Monday 21 January 2008

Restoring GRUB through rescue CD

Entering Rescue Mode

Rescue Mode environment exists in the system RAM. This is mainly used to perform some system maintenance or repair tasks. To enter this mode you can use any of the “Live CDs” or use your distribution’s installation media if they provide such an option.

As you are going to boot from the CD, boot sequence will have to be adjusted in your motherboard’s BIOS. Having done this, insert the proper CD into the drive and reboot. An interactive menu will appear, type "linux rescue" & enter. Answer questions related to your language, your keyboard, network interfaces etc.

Re-installing GRUB

You need to know what the proper partitions and filesystem types are. I will use sda8 as the root partition and ext3 as the filesystem in this example; change those for your personal setup.

~# cd /
~# mount -t ext3 /dev/sda8 /mnt # Where 8 is the partition containing linux
~# mount -t proc proc /mnt/proc
~# mount -t sysfs sys /mnt/sys
~# mount -o bind /dev /mnt/dev

To install the bootloader, it is necessary to "chroot" into your existing linux system.

~# chroot /mnt /bin/bash

Finally the program grub-install installs GRUB on your drive using the grub shell. You must specify the device name on which you want to install GRUB, like this:

~# grub-install /dev/sda

grub should now be installed on /dev/sda.

Errors

If you get errors that says the file /boot/grub/stage1 not read correctly, it probably means that your fstab/mtab is incorrect for some reason and needs to be fixed. These files are /etc/mtab and /etc/fstab. Edit them and make sure they point to the correct partitions, then try to rerun grub-install.

If you get an error that says can't read /boot/grub/device.map: No such file or directory, it means that you need to use the --recheck option with grub-install.

~# grub-install --recheck /dev/sda



Alternative method (After chroot command)
(In some distributions the above method wont work. In such cases follow the method given below.)

open a terminal and enter.:


~# sudo grub

This will get you a grub> prompt. Execute the following command at the prompt location.

~# find /boot/grub/stage1

This will return a location which you have to use in the next command.

~# root (hd?,?)

Next enter the command to install grub to the mbr

~# setup (hd0)

Exit the grub shell

~# quit
Hope this guide was helpful!

good luck!