Linux common maintenance error, repair MBR boot/repair grub2 menu/kernel file loss

Table of contents

1. Repair MBR

1. Simulate MBR damage

2. Restart the viewing system

3. Use the CD of the current system to repair

4. Enter repair mode to repair

5. Back to normal

Second, repair the grub2 menu

1. The situation

2. Enter repair mode

3. Repair the grub2 menu

4. Exit and restart

Third, the kernel file is missing

1. Enter safe mode

2. Mount the disc

3. Install the kernel package in the CD

4. Repair the grub.cfg file

5. Restart

1. Repair MBR

1. Simulate MBR damage

Destroy the bootloader:

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

Note: The block size here only needs to be less than or equal to 446.

2. Restart the viewing system

3. Use the CD of the current system to repair

Mount the CD, enter the CD boot, and enter the maintenance mode

  • Install centos7 system

  • Check the system and install the system

  • enter safe mode

continue into rescue mode

  • Install the graphical system

  • enter rescue mode

  • enter test mode

  • run localdisk

  • back to menu

continue to enter

4. Enter repair mode to repair

chroot /mnt/sysimage    #提升权限

#centos7以上执行
grub2-install /dev/sda
#以下执行
grub-install /dev/sda

Exit and restart

reboot

5. Back to normal

Second, repair the grub2 menu

grub2 menu file storage location

[root@localhost boot]# cd /boot/grub2/
[root@localhost grub2]# ls
device.map  fonts  grub.cfg  grubenv  i386-pc  locale  themes

1. The situation

2. Enter repair mode

进入光盘引导:3--》2--》1--》回车

3. Repair the grub2 menu

输入:chroot /mnt/sysimage/加载系统镜像此时会进入bash环境
输入:grub2-install /dev/sda,重新构建sda磁盘
输入:grub2-mkconfig -o /boot/grub2/grub.cfg,重新构建grub菜单配置文件

4. Exit and restart

Third, the kernel file is missing

Kernel file storage location

[root@localhost ~]# ls /boot/
config-3.10.0-514.el7.x86_64
grub
grub2
initramfs-0-rescue-a72540d4c3624c1e9c24a0e20cefad5a.img
initramfs-3.10.0-514.el7.x86_64.img
initramfs-3.10.0-514.el7.x86_64kdump.img
initrd-plymouth.img
symvers-3.10.0-514.el7.x86_64.gz
System.map-3.10.0-514.el7.x86_64
vmlinuz-0-rescue-a72540d4c3624c1e9c24a0e20cefad5a
vmlinuz-3.10.0-514.el7.x86_64
[root@localhost ~]# rpm -qf /boot/vmlinuz-3.10.0-514.el7.x86_64 
kernel-3.10.0-514.el7.x86_64

1. Enter safe mode

进入光盘引导:3--》2--》1--》回车

2. Mount the disc

[root@localhost ~]# mount  -t  auto  /dev/cdrom /mnt/cdrom

3. Install the kernel package in the CD

[root@localhost ~]# cd /mnt/cdrom/Packages
[root@localhost ~]# ls | grep kernel
#显示如下:
.....
kernel-3.10.0-123.el7.x86_64.rpm
......
#修复内核
[root@localhost ~]# rpm -ivh kernel-3.10.0-123.el7.x86_64.rpm --force

4. Repair the grub.cfg file

[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

5. Restart

Guess you like

Origin blog.csdn.net/weixin_53678904/article/details/131649719
Recommended