Boot process and repair of linux system

Disk boot

mbr represents the master boot record, located in track 0 and sector 1, with a size of 446 bytes, as shown in the following figure:

mbr function:
Record the location of grub2 boot files
When mbr data is lost, the system will stop starting because the boot partition cannot be found

Problem simulation mode

[root@localhost Desktop]# fdisk -l check the disk system disk. The corresponding device with * has the mbr main boot area
Disk /dev/vda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x657e7edc

Device     Boot   Start      End  Sectors  Size Id Type   It can be seen that there are mbr The equipment in the main boot area is /dev/vda
/dev/vda1  *       2048  1026047  1024000  500M 83 Linux
/dev/vda2       1026048  2050047  1024000  500M 82 Linux swap / Solaris
/dev/vda3       2050048 16777215 14727168    7G 83 Linux

[root@localhost mnt]# dd if=/dev/zero of=/dev/vda bs=446 count=1 clear the data in the mbr main boot area, and the system will stop starting because the boot partition cannot be found
[root@localhost mnt]# dd if=/dev/vda of=/mnt/mbrfile bs=446 count=1 intercept data
1+0 records in
1+0 records out
446 bytes copied, 0.000127563 s, 3.5 MB/s
[root@localhost mnt]# hexdump -C /mnt/mbrfile view the intercepted data, all of which are 0, indicating that the mbr data has been cleared
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
000001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 0a     |...............|

Restart the system after clearing, and the system will display the following interface

Recovery method:
Add a disc, as shown below

Boot from CD

Enter rescue mode

2. grub2 boot file (boot file)

/boot/grub2/grub.cfg main boot file
/Boot / loader / entries / xxxxxxxx.conf header boot file
Function: specify / boot location
Specifies the file name to load when the system starts

Simulation question 1:

RM - FR / boot / loader / entries / xxxxxxxx.conf is deleted, and problems will occur when the system is restarted

Repair method (you can repair it before restarting):

[root@localhost modules]# cp /usr/lib/modules/4.18.0-193.el8.x86_ 64 / bls.conf / boot / bls.conf copy the template file to boot
[root@localhost entries]# kernel-install add $(unam -r) /boot/vmlinuz-4.18.0-193.el8.x86_64  
                                              Kernel version number              Kernel image

Manual boot (reboot required after system restart)

[root@localhost Desktop]# df must first view / partition the mounted device, which is / dev/vda3 
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          392292       0    392292   0% /dev
tmpfs             419148       0    419148   0% /dev/shm
tmpfs             419148    6812    412336   2% /run
tmpfs             419148       0    419148   0% /sys/fs/cgroup
/dev/vda3        7353344 4459724   2893620  61% /
/dev/vda1         506528  216728    289800  43% /boot
tmpfs              83828    1180     82648   2% /run/user/42
/dev/sr0         8238560 8238560         0 100% /run/media/root/RHEL-8-2-0-BaseOS-x86_64
tmpfs              83828      20     83808   1% /run/user/0

 cd /boot  Switch to/boot See if there is a template file bls.conf
[root@host boot]# ls
[root@host boot]#cp /usr/lib/modules/4.18.0-193.el8.x86_64/bls.conf /boot/ #If not, copy the template file
[root@localhost boot]# kernel-install add $(uname -r) /boot/vmlinuz-4.18.0-193.el8.x86_64 execution

Simulation question 2:

To delete the master boot file:
root@localhost grub2]# rm -fr grub.cfg delete main boot file
root@localhost grub2]# reboot
Repair method:

[root@localhost boot]# cd /boot/grub2/
[root@localhost grub2]# ls  fonts  grubenv  i386-pc
[root@localhost grub2]# grub2-mkconfig > /boot/grub2/grub.cfg
Generating grub configuration file ...
[root@localhost grub2]# ls  fonts  grub.cfg  grubenv  i386-pc

3. Kernel loading


[root@localhost boot]# rm -fr vmlinuz-4.18.0-193.el8.x86_64 delete kernel


Enter rescue mode:
Input 1
 input chroot /mnt/sysimage
 input cp /usr/lib/modules/$(uname -r)/vmlinuz   /boot/vmlinuz-$(uanme -r)  Copy the kernel file stored in the template file
 Re enter the system with a hard disk device and check whether the repair is successful

4. Kernel initialization image

/boot/initramfs-4.18.0-80.el8.x86_64.img function:
Load system clock
Load selinux
Load system host information
Load the disk hanging policy in the / etc/fstab file
Load disk quota
Initialize the system program and start the startup service
Open virtual console
Open graphics

[ root@localhost boot]# rm -fr initramfs-4.18.0-193.el8.x86_ 64.img delete system initialization image

Recovery - if there is no restart, you can use the following methods:

[root@localhost boot]# Mkinitrd -- help view help
usage: mkinitrd [--version] [--help] [-v] [-f] [--preload <module>]
       [--image-version] [--with=<module>]
       <initrd-image> <kernel-version>

       (ex: mkinitrd /boot/initramfs-4.18.0-193.el8.x86_64.img 4.18.0-193.el8.x86_64)
[root@localhost boot]# mkinitrd /boot/initramfs-4.18.0-193.el8.x86_64.img 4.18.0-193.el8.x86_64 directly copy this command to generate
Creating: target|kernel|dracut args|basicmodules 

If you restart, the system will not start (as shown in the figure below). How to recover?

Enter rescue mode

Input: mkinitrd /boot/initramfs-$(uname -r).img $(uanme -r)

5. System startup level

0Shut down
1single user
2No graphics network mode
3No graphics network mode
4No graphics network mode
5With graphical interface mode

Problems arise
[ root@localhost Desktop]# systemctl set default view startup level
oot@localhost Desktop]# systemctl set default if the startup level is set to 6, the system will restart all the time
Removed /etc/systemd/system/
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/

Manually specify the startup level:
Power on press e

After specifying, enter the system and change the command to

[root@localhost Desktop]# systemctl set-default 
Removed /etc/systemd/system/
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/

6. Super user password forgotten, crack the password

Press e in the boot selection interface to enter the boot file editing mode

Change ro to rw and add rd.break to indicate that the system stops initialization after starting the kernel

Keywords: Linux Operation & Maintenance ssh

Added by jimjack145 on Fri, 17 Sep 2021 21:57:47 +0300