Restoring GRUB loader after Windows 7 install

I have installed Windows 7 237 days ago at my laptop and then had no time to restore Ubuntu 9.04 loader all this time, but when I have started using Ubuntu every day at work I decided to get Ubuntu working on my home computer too! 🙂

It is really very simple to restore GRUB loader, all you need is to have live cd with Ubuntu, follow instructions bellow if you need to repair GRUB loader which was broken by Windows installation:
1. Insert Ubuntu Live CD and boot into the virtual Ubuntu;
2. Open terminal (CTRL+ALT+T or hit ALT+F2 and type: gnome-terminal);
3. type in terminal:

$sudo fdisk -l

3.1. you will see partitions table, something like this:

/dev/sda1 1 2635 21165606 7 HPFS/NTFS
/dev/sda2 2636 12043 75569760 f W95 ext. (LBA)
/dev/sda3 * 12044 14593 20482875 7 HPFS/NTFS
/dev/sda5 2636 10706 64830276 7 HPFS/NTFS
/dev/sda6 10707 11861 9277506 83 Linux
/dev/sda7 11862 12043 1461883+ 82 Linux своп / Solaris

4. Now you have to mount Linux partition, here it is sda6, I have no separate /boot partition, but don’t forget to mount it too if you have one!
4.1. Mounting partitions:

$sudo mount /dev/sda6 /mnt
$sudo mount --bind /dev /mnt/dev
$sudo mount --bind /proc /mnt/proc


5. To continue repairing your GRUB you need to switch into chroot environment:

sudo chroot /mnt

5.1. Note: after switch is completed you do not need to use sudo.

6. To recover GRUB, just type following command:

#grub-install /dev/sda

6.1. If you get an error message, just type another command:

#grub-install --recheck /dev/sda

7. Now you can safely exit from chroot, unmount partitions and reboot your PC:

#exit
$sudo umount /mnt/dev
$sudo umount /mnt/proc
$sudo umount /mnt
$sudo reboot

8. Happy codding in Ubuntu! (:

Original article, I have used to restore my GRUB: http://www.ubuntu-inside.me/2009/06/howto-recover-grub2-after-windows.html

Best regards,
Yahor