How to fix MBR and GRUB in CentOs7
I. Repair MBR:
MBR (Master Boot Record ):
The hard disk has 0 cylinders, 0 heads, and 1-sector names as the primary Boot Sector. Among them, 446Byte is bootloader, 64Byte is Partition table, and the remaining 2Byte is magic number.
Backup MBR:
# Dd if =/dev/sda of =/root/mbr. bak count = 1 bs = 512
Destroy bootloader:
# Dd if =/dev/zero of =/dev/sda count = 1 bs = 200
The block size must be less than or equal to 446.
Solution:
1. Use other systems to mount disks for restoration.
The repair method is similar to the CD fix, and the grub2-install command is also used.
2. Use the installation disc for restoration.
1. Mount the disc and select troubleshooting on the boot page:
2. Select to enter the rescue mode:
3. Press enter to continue:
4. Select the disk Mounting Mode:
The disk will be mounted to/mnt/sysimage /.
-
Continue mounts partitions in rw mode.
Read only mounts partitions in ro mode.
Skip the skip and manually attach the disk.
5. Select continue. Wait a moment and the system prompts that the mounting is complete.
6. Enter the command line in rescue mode:
7. Use the grub2-install command to recreate bootloader:
# Grub2-install root-directory =/mnt/sysimage/dev/sda
No error is displayed. Use sync to write data to the hard disk and reboot to restart the system.
8. There is no error after restart, and grub runs properly:
So far, MBR repair is complete.
Ii. Repair grub
Grub configuration file loss:
After the instance is started, the grub page is displayed as grub>:
The repair procedure is as follows:
Grub> insmod xfs
Grub> set root = (hd0, 1)
Grub> linux16/vmlinuz-xxxxx root =/dev/mapper/centos-root
Grub> initrd16/initramfs-. xxxxx. img
After the repair is completed, you can enter the system and recreate the configuration file.
Note: Because CentOS7 uses grub2, the configuration file has many changes with grub. Be sure to back up grub. cfg for recovery.
This article is from the "small private blog" blog, please be sure to keep this source http://ggvylf.blog.51cto.com/784661/1618345