How to reinstall grub bootloader on Ubuntu 10.04 after Windows effs up your MBR

Windows decided to overwrite my MBR and clobber grub. I was successful at restoring grub by taking the following actions. While this may be a self-serving reminder for the next time it happens, others may find it useful.

It’s worth noting that grub2, which ships with Ubuntu 10.04, has made some changes — mostly notably, /boot/grub/menu.lst has been replaced with /boot/grub/grub.cfg. Following restoration instructions for previous versions of grub will likely fail.

1. Boot from Ubuntu Live CD (Install disc)

2. Open terminal

3. Look at partitions to get device name

sudo fdisk -l

4. If your Linux partition is not marked as bootable, go to System->Administration->Disk Utility and mark the partition as bootable.

5. Create a mount point

sudo mkdir /mnt/linux

6. Mount the partition by device name found in step 3 (for example, /dev/sda1)

sudo mount /dev/sdXY /mnt/linux

7. Run grub-install, which will rewrite the MBR. Note that here you want to specify the device (ie, hard disk) but not the partition. So for /dev/sda1, you’d use /dev/sda.

sudo grub-install --root-directory=/mnt/linux/ /dev/sdX

8. Reboot and grub should load. You may wish to run sudo update-grub after rebooting to update /boot/grub/grub.cfg with any partition or OS changes.

References: from LiveCD