Feed on Posts or Comments

english & linux Franchu on 05 Nov 2006 07:13 pm

Recovering GRUB in Ubuntu

I have already found myself twice in the situation that after having to re-install Windows in a machine that had dual-boot with Ubuntu, the windows installer messes up with the MBR and it is not possible to access Ubuntu anymore.
As I always spend quite a lot of time remembering where I saw the easy solution, I decided to write it down myself in a place I would have always at hand.
The instructions should work in other linux flavors and specially in any Debian based distro.

We boot up with a linux live-cd and as soon as we are allowed we open a root terminal in which we will be working.

First we create a folder where we will mount our main partition:

mkdir /ubuntu

Now that we have a mounting point we mount the main partition of our hard drive:

mount -t ext3 /dev/hda1 /ubuntu

Now we mount the /proc and /dev in our /ubuntu partition in order to be sure that our hard drive is able to see the hardware to reinstall grub:

mount -t proc none /ubuntu/proc
mount -o bind /dev /ubuntu/dev

Now we get into our hard drive partition and forget about the rest of the world:

chroot /ubuntu /bin/bash

Now we can execute grub as if we had booted with our real hard drive and get everything properly configured:

grub

And now inside of grub we reset the booting partition and the MBR:

root (hd0,0)
setup (hd0)

That’s it… we now have the MBR properly configured and we just have to boot up our machine. First we quit grub:

quit

And then we can reboot the machine and we will get the grub dialog that will allow us to choose which OS we want to use.

Related posts:

  1. Upgrade problems from Ubuntu 6.10 (Edgy) to Ubuntu 9.10 (Intrepid) These days I had to perform an upgrade of a...

Related posts brought to you by Yet Another Related Posts Plugin.

Trackback This Post | Subscribe to the comments through RSS Feed

Leave a Reply