Tuesday, February 02, 2010

Restore grub 2 after windows installation

Here is the step by step guide to recover Grub 2 (with ubuntu 9.10) after windows install. The steps are different than for recovering Grub 1 (as explained in this post:

You will need a LIVE cd if you are going to recover an Ubuntu Box. Boot the system with Live CD (I assume you are using Ubuntu Live CD). Press Alt+F2 and enter gnome-terminal command. And continue typing :

$sudo fdisk -l

This will show your partition table:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 12748 102398278+ 7 HPFS/NTFS
/dev/sda2 12749 60800 385977690 f W95 Ext'd (LBA)
/dev/sda5 12749 13003 2048256 82 Linux swap / Solaris
/dev/sda6 13004 16827 30716248+ 83 Linux
/dev/sda7 16828 25272 67834431 83 Linux
/dev/sda8 25273 32125 55046302+ 7 HPFS/NTFS
/dev/sda9 32126 60800 230331906 7 HPFS/NTFS

Now we need to mount Linux (sda6 and sda7 here). sda6 is the / partition and sda7 is the /home partition. So mount them accordingly. If you have any other partitions (specially boot partition) dont forget to mount them.

$sudo mount /dev/sda6 /mnt
$sudo mount /dev/sda7 /mnt/home
$sudo mount --bind /dev /mnt/dev
$sudo mount --bind /proc /mnt/proc
$sudo mount --bind /sys /mnt/sys

Now chroot into the enviroment we made :

$sudo chroot /mnt

You may want to edit /etc/default/grub file to fit your system (timeout options etc)

$vi /etc/default/grub

Once you are thru install grub2 by using

$grub-install /dev/sda

If you get errors with that code use:

$grub-install --recheck /dev/sda

Now you can exit the chroot, umount the system and reboot your box :

$sudo umount /mnt/home
$sudo umount /mnt/sys
$sudo umount /mnt/dev
$sudo umount /mnt/proc
$sudo umount /mnt
$sudo reboot

No comments: