Linux boot process and service control

1. Booting process Insert picture description here
2. CentOS7 startup process

POST (power on self test)→BootSequence→Bootloader→kernel+initranfs(initd)→rootfs→/sbin/init
Note: BIOS (Basic Input Output System)

3. Different system boot process

* 

windowsbootloader:ntloader
*
Linuxbootloader:LILO/GRUB/grub2

4. linux kernel: modular

* 

Kernel file: /boot/vmlinuxz-VERSION-realease
*
Module file: /lib/modules/VERSION-realease/
*
Note: kernel: kernel initranfs: initialize memory file system initrd (ramdisk): memory hard disk

5. The parent boot process

CentOS7 parent boot process: /usr/lib/systemd/systemd-switche
CentOS6 parent boot process: /sbin/init

6. Causes of MBR sector (512 bytes) failure

* 

Viruses, Trojan horses cause damage (such as hard disk bombs)
*
Incorrect partition operation, misoperation of hard disk read and write

7. Failure phenomenon

* 

Can't find the boot program, start interrupted
*
Unable to load the system, boot black screen

8. Solution ideas

* 

Back up in advance
*
Boot from the boot CD into emergency mode
*
Restore from the backup file

9. Simulate sda ​​damage and repair (first 512 bytes)

fdisk /dev/sdb #Create the primary partition
mkfs.xfs /dev/sdb1 #Format
mkdir /backup #Create a backup directory
mount /dev/sdb1 /backup #Mount the hard disk to the directory
dd if=/dev/sda of=/backup /sda.mbr.bak bs=512 count=1 #copy the first 512 bytes of sda to the backup directory
dd if=/dev/zero of=/dev/sda bs=512 count=1 #simulate damage to the first 512 bytes of sda
reboot #Restart
Enter emergency mode
mkdir /aaa #Create directory
mount /dev/sdb1 /aaa
#Mount hard disk dd if=/aaa/sda.mbr.bak of=/dev/sda bs=512 count=1 #Copy the content before Copy to sda
reboot # restart
Insert picture description here
Insert picture description here
10. GRUB boot failure

* 

cause of issue:

                    1.MBR中的GRUB引导程序遭到破坏
                    2.grub.conf文件丢失,引导配置有误
* 

Symptom: The system boot stalls and the "grub>" prompt is displayed
*
Solution:

                    1.手动输入
                    2.进入急救模式,重建grub程序
                    3.若无MBR备份,进入急救模式,重新安装grub程序

Insert picture description here
Insert picture description here
11. GRUB boot failure

* 

The first 446 bytes are damaged: rewrite the command to install (chroot/mnt/sysimage, grub2install /dev/sda) or use the dd command to copy the first 446 bytes into the first 446 bytes of sda
*
No grub menu:

                         1.手动输入命令(less /boot/grub2/grub.conf中的配置信息,)
      grub>insmod xfs
    grub>set root=(hd0,msdos1)
    grub>linux16 /vmlinuz-xxxxx root=/dev/mapper/centos-root
    grub>initrd16 /initramfs-.xxxxx.imggrub>boot
                         2.修改开机启动顺序,从备份文件中写入。

Insert picture description here
Insert picture description here
Insert picture description here
12. Various password settings in Linux

1. Root password:
*
Enter single user mode in CentOS6, formula: e2e, space 1, press enter and press B. passwd, reboot
*
Enter single-user mode in CentOS7, add init=/bin/sh at the end of the line e, linux16. Press control+X,

      mount -o remount,rw/ 以读写方式重新挂载根目录,passwd,exec /sbin/init 开启这个功能

Insert picture description here
2. grub password:
*
CentOS6 delete grub password: enter single user mode, delete passwd in /boot/grub/grub.conf.
*
CentOS6 set grub password: vi /boot/grub/gurb.conf, write passwordXXXXXXX on the title.
*
CentOS7 set grub password: cd/boot/grub2, grub2-setpassword. cat /boot/grub2/ user.cfg
*
CentOS7 delete grub password: delete the password configuration file

Insert picture description here
13. The default run level at boot

CentOS6

Cat /etc/redhat-release
CentOS release 6.5 (Finanl) #is the 6.5 version
Vim /etc/inittab
Insert picture description here
Insert picture description here
CentOS7
Insert picture description here
14. Service control and optimized startup Insert picture description here
Insert picture description here
Insert picture description here
15. systemctl example
shows all unit status
systemctl or systemctl list-units
only shows the status of service units systemctl --type=service
displays the sshd service unit systemctl -l status sshd.service
verifies whether the sshd service is currently active
systemctl is-active sshd
starts, stops and restarts the sshd service
systemctl start sshd.service systemctl stop sshd.service systemctl restart sshd.service
reload Configure
systemctl reload sshd.service to
list all service units in active status
systemctl list-units --type=service
list all service units
systemctl list-units --type=service --all
view the enabled and disabled status of service units
systemctl list -unit-files --type=service
List failed services
systemctl --failed --type=service
list dependent units
systemctl list-dependencies sshd
verify whether the sshd service is started
systemctl is-enabled sshd
disables the network so that it cannot be started automatically, but you can manually
systemctl disable network
Enable
network systemctl enable network
Disable network so that it cannot be started manually or automatically
systemctl mask network
Enable network systemctl
unmask network

Guess you like

Origin blog.csdn.net/qq_39109226/article/details/109398355