Recovering GRUB after accidentally writing to MBR

The other day I decided to partition out a tiny bit of my hard drive (10 GB) to install Windows XP. I figured it was good to have around to play games in my spare time. No big deal, the install went fine. Then I realized Windows likes to take over the MBR. Grub was no longer my default boot loader. So in order to boot back into Ubuntu I needed a live CD. Honestly, any live CD should work fine for this (try Ubuntu's if you don't have a preference).

Once in you're in your live environment, you need to go into grub's console with the following command:

$ grub

You should then have a prompt as such:

grub>

If you're unsure of which partition you have your boot information you can use a quick find command like this:

grub> find /boot/grub/stage1

This should return something similar to (hd0,2). Use that for the following two commands.

grub> root (hd0,2)
grub> setup (hd0)

You should be good to go at this point. If you want to boot back into Windows you will stil need to add that to your /boot/grub/menu.lst and add the following all the way at the end.

title Windows
root (hd0,1)
makeactive
chainloader +1

This time replace (hd0,1) with the location of your Windows partition.

For further information you can take a look at the Ubuntu Wiki for Recovering Ubuntu After Installing Windows.

Tags: