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. MBR
boot
3. GRUB
menu
4. Load kernel kernel
and file system memory initramfs
5. Load the initialization process and the hardware drivers
MBR sector failure repair
MBR
First 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 MBR
the 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/sdb1
partition
[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 MBR
sector 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 MBR
sector 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
Restore MBR sector data
1. U disk boot disk or optical disk operating system boot
2. Enter Troubleshooting
troubleshooting mode
3. Enter the Rescue a CentOS system
system emergency mode
4. Enter the shell
environment, recover
mkdir /bak
mount /dev/sdb1 /bak
ls /bak
dd if=/bak/sda.mbr.bak of=/dev/sda
reboot
5. recovery success
GRUB boot failure recovery
GRUB
Most Linux
default 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
Fault repair GRUB
The front section and above, enter the same system rescue mode to fix it.
1. Load system image to be repaired switching Linux
system root environment
chroot /mnt/sysimage/
2. sda
The MBR
sector reinstall grub
bootloader
grub2-install /dev/sda
3. To re-build grub
the 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 root
password, will not be able Linux
to 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 root
the password.
Very simple, as follows:
chroot /mnt/sysimage/
echo "000000" | passwd --stdin root 或 passwd root
exit
reboot