Tuesday, August 10, 2010

How to boot a Red Hat Linux System if either MBR is corrupt or Rescue mode is unavailable:

Sometimes we face a problem when our system fails to boot because of Corrupt MBR and sometimes our luck is so bad that there is no rescue environment available.

In such a case how should we move things such that we are in a position to either repair MBR or recover our Data?

Well, faced with such a situation you should log on to another machine and find a file named stage2_eltorito.

This file is a special stage-2 for grub designed to run CD-ROM instead of a Hard-Drive.

#find / -name stage2_eltorito

You can also locate the "stage2_eltorito" file using the rpm command:

#rpm -ql grub | grep eltorito

Now create a directory and copy the "stage2_eltorito" file into that directory.

#mkdir -p /tmp/iso/boot/grub

Copy the "stage2_eltorito" file into the newly created directory (/tmp/iso/boot/grub):

#cp /usr/share/grub/i386-redhat/stage2_eltorito /tmp/iso/boot/grub

Now create the ISO Image of the "stage2_eltorito" file:

#cd /tmp/iso
#mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -o /tmp/grub.iso


You can now burn the /tmp/grub.iso file onto a CD and boot it. From there you can use the full GRUB command-line and restore the MBR if it is curroupted, oe you can just load the config file on the system to get to the normal boot menu and boot your machine.

When you boot your system now using the GRUB iso CD, you will get the grub> prompt as shown below. Set the GRUB Root:

grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83

Find the "grub.conf" file:

grub> find /grub/grub.conf
(hd0,0)

grub> configfile (hd0,0)/grub/grub.conf

This will load the normal grub menu which you can use to boot your machine or do further GRUB maintenance.

Catch: What if the configuration file "grub.conf" is missing?
If the configuration file does not exist, you will need to locate the partitions that contain the kernel and initial RAM-Disk (initrd). Now first set the GRUB Root:

grub> root (hd0,0)
Filesystem type is ext2fs, partition type 0x83

And then use the tab completion to get the list of all the files in this directory.

grub> cat /TAB

This will cause the GRUB to display a list of all the files contained in that directory. You should see the full names of both the kernel and the initial RAN-Disk. With this information, it should now be possible to construct the kernel and initrd lines, thus booting the system without configuration file:

grub> kernel /vmlinuz-2.6.18-53.el5 ro root=LABEL=/ rhgb quiet
grub> initrd /initrd-2.6.18-53.el5.img
grub> boot


This will boot the system.

No comments:

Post a Comment