Restoring the Grub after reinstalling Windows


After reinstalling windows or fixing MBR(Master Boot Record) you always loose your grub and you cannot boot to your linux. So this post is about the methods of restoring the grub. There are three methods I use. I will explain all three.

All three methods need a live cd of a linux. You need to boot from the live cd and take the terminal and do the following:

  1. First method is using grub command. We initially go into the grub mode interface using the command
    sudo grub

    This will get you a “grub>” prompt (i.e. the grub shell). At grub>. enter these commands

    find /boot/grub/stage1

    If the find returned (hd0,1) then you would enter

    root (hd0,1)

    Now the root drive where the boot folder is mounted.Now we needed to setup the drive to boot to show the grub. We do this by

    setup (hd0)

    Finally exit the grub shell

    quit

    And then Reboot to and try if you are getting the grub.
    If not try the next method.

  2. If couldn’t get grub to find the stage1 file or even recognize the drive. Use this method.
    sudo mkdir /mnt/root 

    sudo mount -t ext3 /dev/sda6 /mnt/root

    Then you have to mount the proc subsystem and udev inside /mnt/root also:

    sudo mount -t proc none /mnt/root/proc 

    sudo mount -o bind /dev /mnt/root/dev

    Doing this allows grub to discover your drives. Next you have to chroot:

    sudo chroot /mnt/root /bin/bash

    Now that you’re chrooted into your drive as root everything should work.

    sudo grub

    And then follow the 1st method to install the grub.

  3. In lastest Linux you can use the command grub-install.The usage of this command is as
    sudo grub-install –root-directory=/media/<root-drive-mount> /dev/sda

    It might be hda if the hard disk is IDE and sda if disk is SATA.

So try it out the next time you loose your grub and tell me how it went.


, , , , , , , , ,

  1. #1 by Denny on December 19, 2009 - 12:23 pm

    With ubuntu 9.10 grub2, doing #2 above then #3 above worked perfectly!

  2. #2 by icko on July 8, 2010 - 11:45 pm

    Thanks man this help.

  3. #3 by ert on January 4, 2011 - 6:50 pm

    Nothing works for me…

    #1 says

    ubuntu@ubuntu:~$ sudo grub
    sudo: grub: command not found

    #2 says

    ubuntu@ubuntu:~$ sudo mount -t ext3 /dev/sda6 /mnt/root
    mount: mount point /mnt/root does not exist

    and #3 says

    ubuntu@ubuntu:~$ sudo grub-install /dev/sda
    /usr/sbin/grub-probe: error: cannot find a device for /boot/grub (is /dev mounted?).

  4. #4 by Dreian on February 21, 2011 - 8:07 pm

    I can truly say that this (Live CD Instrutions) worked for me. The other on I tried with the chroot didn’t work because I didn’t have the root password. This, for some reason circumvented that issue and delivered as promised. (Once I stopped being lazy and followed the instructions it was a one-shot, no-hassle, 5-minute deal. Just the way I like it …..K.I.S.S.

    Thanks much, best wishes to you
    Dreian

  5. #5 by stef on March 4, 2011 - 5:37 am

    Great!
    Worked for me too – method no 2
    Thanks a lot!

  6. #6 by Jeaye on March 23, 2011 - 2:34 am

    Yeah, I chrooted with #2, and then installed grub with #3. It wouldn’t work unless I did #2 first. Thanks a ton for this.

  7. #7 by Srijith R on April 4, 2011 - 3:30 pm

    @ert try the updated post on grub-install

  8. #8 by Joao on May 24, 2011 - 1:57 am

    Hi,

    I repaired successfully my HDD MBR using method 3:

    1. I mounted the root partition with nautilus, as usual.
    2. I issued the command
    sudo grub-install –root-directory=/media/ /dev/sda

    (I got the easily issuing the “ls /media” command).

    3. I rebooted the PC.

    4. The GRUB2 menu reappeared again.

    :)

    Thank you very much, Srijith.

    In fact it was very easy to repair it (I took 2 weeks googling for a solution).

    Best regards,

    Joao

  9. #9 by Sam on December 28, 2011 - 8:27 pm

    The third method works really g8t for me..
    I have latest version of Debian and Linux mint and installing Grub for mint is really a cake walk…cheers..

(will not be published)


  1. Restoring the Grub after reinstalling Windows | Srijith Unplugged WP Air