Grub and MBR Repair

Source: Internet
Author: User

1. grub.conf configuration file is missing

first of all: at the grub command prompt, all types of disks (whether SATA or SAS) are identified as devices that start with HD (such as hd0), no SDA, and so on.

When the/boot/grub/grub.conf profile is lost, the system restarts without the Linux boot menu and goes directly to the GRUB prompt interface as follows:

650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "Spacer.gif"/>650 "this.width=650;" src= "http ://s2.51cto.com/wyfs02/m01/86/f4/wkiom1fpsodargj9aaac6qahsms632.png "title=" 1.png "alt=" Wkiom1fpsodargj9aaac6qahsms632.png "/>

You can use the help command to see what commands are available.

The complete recovery steps are as follows:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/86/F4/wKioL1fPtviC8lvcAAAXml8lmRA425.png "title=" 3.png " alt= "Wkiol1fptvic8lvcaaaxml8lmra425.png"/>

If you know which partition in the/boot directory you can omit the first step, use the root command to specify the disk partition, if you do not know, you can use the Find command to locate.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/F4/wKiom1fPs5ewm8SnAAAFrQ71O1s602.png "title=" 2.png " alt= "Wkiom1fps5ewm8snaaafrq71o1s602.png"/>

Input Find (hd0,0) represents the first partition from the first disk, input the Find (hd0,0)/vmlinuz, followed by the TAB key to complete, if it can complete, it means that the partition can find the kernel file.

Then use root to specify the disk partition;


Then specify the kernel and pass parameters to the kernel file, RO is read-only, the/dev/sda2 in Root=/dev/sda2 is the partition where the root filesystem resides, (so be aware of the name of the partition on which the root file system resides if the system is installed, and if the root file system is on a logical volume, Write the name of the logical volume partition )


Finally specify the initrd file, INITRD is a memory to emulate the disk file, is a small root file system, which contains the current system of the real root file system driver, with these drives the Linux kernel to mount the real root filesystem.


The kernel file name after kernel and the file specified after INITRD can be automatically complete using the TAB key

Start with the boot command after the previous steps are set up.


After startup, enter the/boot/grub directory to rewrite the grub.conf file, the file content is roughly the above steps, the contents are as follows:

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/F6/wKiom1fPv1KhLqHiAAAMJqBT4sc052.png "title=" 6.png " alt= "Wkiom1fpv1khlqhiaaamjqbt4sc052.png"/>

Where default=0 represents the title if there are multiple words, the default is to select the first title of the start, timeout=3 for the start of the Grub selection interface for 3 seconds, after the title can be arbitrarily defined by themselves. After the edits are saved, the next boot will not have a problem.


In the above steps, if the kernel parameter root= the name of the partition where the root file system is specified here is incorrect, the error interface is as follows

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/F4/wKioL1fPvT_yOaXkAAAWXBph0yc669.png "title=" 5.png " alt= "Wkiol1fpvt_yoaxkaaawxbph0yc669.png"/>

2, the first 446 bytes of MBR is lost (if the middle 64 bytes are lost, this method does not apply, the middle 64 bytes is missing is the partition table is destroyed)

MBR Total 512 bytes, the first 446 bytes to hold the bootloader program, the next 64 bytes to hold the partition table information, the last 2 bytes to hold the special flag. Here are the main instructions on how to fix bootloader after being destroyed.

When the bootloader is compromised, the following interface is restarted:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/F6/wKiom1fPwiHxmPYOAAASQzLnwZs583.png "title=" 7.png " alt= "Wkiom1fpwihxmpyoaaasqzlnwzs583.png"/>

This will activate the use of disc emergency rescue mode.

After mounting the disc, set the startup item to boot from the CD-ROM and enter the installation interface.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/86/F5/wKioL1fPzt_xR1EeAAORxhvL0M4716.png "title=" 8.png " alt= "Wkiol1fpzt_xr1eeaaorxhvl0m4716.png"/>

Select Rescue Installed System

Enter after the prompt to choose the language Lanaguage, keyboard type keyboard type, the general default is the line. Then go to the following interface.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/86/F7/wKiom1fP0DTBFqtBAAAJ2i_bT8Y221.png "title=" 9.png " alt= "Wkiom1fp0dtbfqtbaaaj2i_bt8y221.png"/>

This step is whether to enable the network, if necessary to enable, you can choose Yes, access to the interface for IP and other configuration, not enabled here.

There is no need to enable it, select No. Go to the following interface

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/F7/wKiom1fP0hmSUPkmAAAn_DsXtj4949.png "title=" 10.png "alt=" Wkiom1fp0hmsupkmaaan_dsxtj4949.png "/>

The default continue can be, the next few steps by default, until the following step.

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/F7/wKiom1fP0xvB-YeyAAAPuJU0YN0325.png "title=" 11.png "alt=" Wkiom1fp0xvb-yeyaaapuju0yn0325.png "/>

This step is after selecting OK, the bottom of the command prompt appears, the next thing you need to do

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/F6/wKioL1fP1ETwowlkAAA0xNBzHqU683.png "title=" 12.png "alt=" Wkiol1fp1etwowlkaaa0xnbzhqu683.png "/>

The first step is to use chroot/mnt/sysimage to switch to the root filesystem where the/mnt/sysimage directory is located, the root file system will be mounted to this directory, then use GRUB to enter the command prompt, and also use root (hd0,0) to specify the disk partition. Then use Setup (hd0) to start the recovery directly mbr,mbr is not in any partition, after all setup directly with (hd0), directly specify the disk.

After successful recovery, use quit to exit the Grub command prompt interface, and then exit the root filesystem of the/mnt/sysimage directory with exit, back to the root file system loaded from the CD, and then enter the system normally after rebooting the system.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/F8/wKiom1fP2R2hvhgaAAAEyvVSCOY267.png "title=" 13.png "alt=" Wkiom1fp2r2hvhgaaaaeyvvscoy267.png "/>


3. The Grub directory is missing


When the/boot/grub directory is lost, the system can not enter the system, restart the system after the error is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/86/F6/wKioL1fP2mqT37HJAAACMhNXHLc690.png "title=" 14.png "alt=" Wkiol1fp2mqt37hjaaacmhnxhlc690.png "/>

At this point is still entering the emergency rescue mode, the specific steps see above the MBR is missing.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/F7/wKioL1fP43fw_36wAAAnSi9dees467.png "title=" 15.png "alt=" Wkiol1fp43fw_36waaansi9dees467.png "/>

After entering rescue mode, use chroot to switch to/mnt/sysimage root file system, use Grub-install command to reinstall Grub Directory, Grub-install--root-directory=//dev/sda2 In this command,--root-directory= should format the root of the boot directory-that is, the root/back of the disk device where the root filesystem resides, even if the partition where the root file system resides is a logical volume and cannot use the logical volume name, but instead uses the original device name as above. Dev/sda2 or/dev/sda1 or/DEV/SDA, the following (FD0)/dev/fd0 and (hd0)/DEV/SDA can appear after the Grub-install command is executed to calculate the installation success.

After installation, you can see the Grub directory already in the/boot directory.

The final step is to manually create the grub.conf file in the Grub directory with the following file contents:

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/86/F9/wKiom1fP-f7zGYxRAAANoNCIVCI335.png "title=" 4.png " alt= "Wkiom1fp-f7zgyxraaanoncivci335.png"/>

Where kernel that line if the root filesystem is on a logical volume, you should use the name of the logical volume instead of using/dev/sda2 as in the Grub-install command above. If it is a logical volume, it should look like this

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/86/F7/wKioL1fP-3yC_G9wAAAa6SVhNIU755.png "title=" 5.png " alt= "Wkiol1fp-3yc_g9waaaa6svhniu755.png"/>

The parameter also uses the quiet selinux=0 representative to use silent mode, to turn off SELinux.

If you do not close SELinux, the startup error will be as follows

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/F9/wKiom1fP-lbxkMc9AAAO5_xxo-U885.png "title=" 2.png " alt= "Wkiom1fp-lbxkmc9aaao5_xxo-u885.png"/>


This article is from the "Gan mu" blog, please be sure to keep this source http://ganmu.blog.51cto.com/9305511/1850556

Grub and MBR Repair

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.