Saturday, February 19, 2011

How To Restore Grub2 In Debian Based Systems

Sometimes we get curious or need curtain features and install other systems on our computers. The problem that we run into is that it will trash the way we boot them. It is ever easy to get Grub2 to back to the state it was.

You will need a LIVE cd if you are going to recover Grub2. I will be using an Ubuntu disk for this step by step tutorial. Open up terminal and continue by entering :

$sudo fdisk -l

This will show your partition table.Here is my table to understand it better :

/dev/sda1 29 8369 66999082+ 83 Linux
/dev/sda2 * 8370 13995 45190845 7 HPFS/NTFS
/dev/sda3 13996 14593 4803435 5 Extended
/dev/sda5 13996 14593 4803403+ 82 Linux swap / Solaris

Now i will mount Linux (sda1 here), Yours could be different it depends on where your boot partition for Linux was.)

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

Now chroot into the enviroment we made :

sudo chroot /mnt

After chrooting, you will not have to use sudo anymore as you will be root(you can tell by #).

You may want to edit /etc/default/grub file to fit your system (timeout options etc) just upadte grub if you do.

#nano -w /etc/default/grub

Now install/recover Grub2 via :

#grub-install /dev/sda

You can use reconfirm by using:

#grub-install --recheck /dev/sda

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

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

That is it and you are back in business.
Read more

Shaun Mallette's Blog Design by Insight © 2009