CentOs7 repair MBR and GRUB tutorial

Source: Internet
Author: User
I. repair MBR: MBR (master boot record of MasterBootRecord): the hard disk has 0 cylinder, 0 Head, and 1 sector as the main boot sector. Among them, 446Byte is bootloader, 64Byte is Partitiontable, and the remaining 2Byte is m 1. 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 /.

    1. Continue mounts partitions in rw mode.

    2. Read only mounts partitions in ro mode.

    3. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.