How to repair Corrupt Boot Loader

[Total: 5    Average: 5/5]

How to repair Corrupt Boot Loader? There are times when you inadvertently overwrite your Master Boot Record. The end result being that you are unable to boot into Linux. This is especially true when you are dual booting between windows and Linux OSes.

This is what you do to restore the GRUB boot loader when faced with the above problem. First you need a Linux distribution CD.

With CD
Boot your computer with the first CD of your CD drive (You have to enable your PC to boot from the cdrom, which you can set in the BIOS settings).

At the installation boot prompt that you get, enter the following command:

boot: linux rescue

… and press Enter. The installer will ask you a few questions like the language you would like to use, the type of keyboard etc. Then, if you have linux previously installed on your machine, the installer will automatically detect it and mount it in the /mnt/sysimage directory. Once the linux partition is mounted, you are dropped into the command shell prompt. The next step is to make your newly mounted directory the root (or parent) directory. This you do by running the chroot command as follows:

# chroot /mnt/sysimage

Now you are in the shell with respect to the parent directory which is the linux partition on your harddisk.

From here, the steps needed depends on which bootloader you are using. You have to have a fair idea what is the device node of your harddisk partition housing your MBR. In most cases, it is /dev/sda.

Restoring GRUB

Execute the following command :

# grub-install /dev/hda

… to install GRUB boot loader on to your MBR. And then type exit to reboot the machine. Now your GRUB boot loader is fixed.

Many have said when they run the grub-install command after following the above steps, they get an error saying that /dev/hda is missing. The most probable reason is that when you chroot to the mount location, it does not have a copy of the device nodes on your machine. Here is a solution for that. If you have installed Linux with /boot, /usr and / in different partitions then the above method may not get the desired results and running the grub-install /dev/hda command after running chroot might give the error that there is no /dev/hda. This is because you have mounted only one of the partitions which houses ‘/’ . And the error tells you that it cannot find the device nodes. In this scenario you can do the following :

Lets say I have Linux installed with / in /dev/hda2, /boot in /dev/hda1 with an ext3 filesystem. I boot using a Live CD as described above and then mount the partitions as follows :

# mount -t ext3 /dev/hda2 /mnt

# mount -t ext3 /dev/hda1 /mnt/boot

Remember that you are mounting the boot partition into the boot directory inside /mnt. Now mount the proc filesystem of your liveCD as follows

Now you can chroot to the /mnt location and run the grub-install command as described above.

# chroot /mnt
# grub-install /dev/hda

Please note: This updated method is applicable only if you have a Linux installation spread across multiple partitions. If you have installed Linux in a single partition, the first and second step works flawlessly. At least it works for me.