Linux boot repair

CentOS Logo

System boot is the beginning of an operating system to run, if the boot problems arise, the system will not work properly, then there is no way to fix it? The answer is yes.


CentOS7 boot process

1. Post BIOS
2. MBRboot
3. GRUBmenu
4. Load kernel kerneland file system memory initramfs
5. Load the initialization process and the hardware drivers

MBR sector failure repair

MBRFirst sector (512B) located on a physical hard disk boot record, also known as the master boot sector, in addition to the portion of the data comprising a system boot program, further comprising recording the entire hard disk partition table.

Backup MBR sector data

1. Prepare the other disk for MBRthe sector data backup

[root@localhost ~]# fdisk /dev/sdb
[root@localhost ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=1310656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5242624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

2. Mount the /dev/sdb1partition

[root@localhost ~]# mkdir /bak
[root@localhost ~]# mount /dev/sdb1 /bak/
[root@localhost ~]# df -hT
文件系统       类型      容量  已用  可用 已用% 挂载点
/dev/sda2      xfs        20G  3.4G   17G   17% /
devtmpfs       devtmpfs  1.9G     0  1.9G    0% /dev
tmpfs          tmpfs     1.9G     0  1.9G    0% /dev/shm
tmpfs          tmpfs     1.9G  9.1M  1.9G    1% /run
tmpfs          tmpfs     1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/sda5      xfs        10G   37M   10G    1% /home
/dev/sda1      xfs       2.0G  174M  1.9G    9% /boot
tmpfs          tmpfs     378M  8.0K  378M    1% /run/user/42
tmpfs          tmpfs     378M     0  378M    0% /run/user/0
/dev/sdb1      xfs        20G   33M   20G    1% /bak

3. backup MBRsector data

[root@localhost ~]# ls /bak/
[root@localhost ~]# dd if=/dev/sda of=/bak/sda.mbr.bak bs=512 count=1
记录了1+0 的读入
记录了1+0 的写出
512字节(512 B)已复制,0.000289995 秒,1.8 MB/秒
[root@localhost ~]# ls /bak/
sda.mbr.bak

Analog MBR sector failure

1. Human coverage MBRsector recording

[root@localhost ~]# dd if=/dev/zero of=/dev/sda bs=512 count=1
记录了1+0 的读入
记录了1+0 的写出
512字节(512 B)已复制,0.000157851 秒,3.2 MB/秒

2. Restart

[root@localhost ~]# init 6

3. not start

Unable to start

Restore MBR sector data

1. U disk boot disk or optical disk operating system boot

Start Menu

2. Enter Troubleshootingtroubleshooting mode

Troubleshooting

3. Enter the Rescue a CentOS systemsystem emergency mode

Emergency Mode

4. Enter the shellenvironment, recover

shell

mkdir /bak
mount /dev/sdb1 /bak
ls /bak
dd if=/bak/sda.mbr.bak of=/dev/sda
reboot

5. recovery success

Recovery success


GRUB boot failure recovery

GRUBMost Linuxdefault boot program, you can choose to enter different operating systems through the Startup menu. If the configuration file is missing, or the key to a configuration error, you can not complete the boot process.

GRUB fault simulation

1. Delete Profiles

[root@localhost ~]# cp -p /boot/grub2/grub.cfg /boot/grub2/grub.cfg.bak
[root@localhost ~]# rm -f /boot/grub2/grub.cfg
[root@localhost ~]# init 6

2. fails to start

Unable to start

Fault repair GRUB

The front section and above, enter the same system rescue mode to fix it.

shell

1. Load system image to be repaired switching Linuxsystem root environment

chroot /mnt/sysimage/

2. sdaThe MBRsector reinstall grubbootloader

grub2-install /dev/sda

3. To re-build grubthe menu configuration file

grub2-mkconfig -o /boot/grub2/grub.cfg

4. Exit and restart, wait for the system to start

exit
reboot

ROOT password forgotten

When the forgotten rootpassword, will not be able Linuxto perform administrative and maintenance tasks on the system. When they can not change the password by other users, you can also use the rescue mode to modify rootthe password.

shell

Very simple, as follows:

chroot /mnt/sysimage/
echo "000000" | passwd --stdin root 或 passwd root
exit
reboot

Guess you like

Origin www.cnblogs.com/llife/p/11419071.html