Friday, September 29, 2006

GRUB reinstall woes

I recently had to reinstall Windows on my dual boot (Windows/Ubuntu 6.06) system. This of course wiped out the GRUB loader in the MBR. Now, the normal method of restoring GRUB is to do this:
1. Boot from your linux installation CD (In case of Ubuntu just go through the Start or Install Ubuntu routine till you get the desktop)
2. Open up a terminal and mount your boot partition
3. Switch the system root and do a grub-install to restore the grub from the boot partition on your MBR.

Now the normal commands to do this do not work in Ubuntu for some reason. For example, doing
$ sudo mkdir /mnt/ubuntu
$ sudo mount /dev/sda8 /mnt/ubuntu #(/dev/sda8 is my / partition)
$ chroot /mnt/ubuntu
$ grub-install /dev/sda #(install grub to the MBR)

This kept giving me errors like "/dev/sda: Not found or not a block device". After some searching I landed up at this Ubuntu Wiki page that lists a number of approaches to reinstall GRUB. Some of them still didn't work, but the one that did work is this:

1. Pop in the Live CD, boot from it until you reach the desktop.
2. Open a terminal window or switch to a tty (Ctrl + Alt + F1).
3. Type "sudo grub"
4. Type "root (hd0,7)", or whatever your harddisk + boot partition numbers are (my /boot is at /dev/sda8, which translates to hd0,7 for grub).
5. Type "setup (hd0)", or whatever your harddisk number is.
6. Quit grub by typing "quit".
7. Reboot.


Happy GRUBbing :)

Labels: , , ,