July 17, 2009

Reinstall GRUB Bootloader on md0

After a power outage, an RHEL 4 server was stuck with nothing on the screen but "GRUB" at the top left. Rebooting had the same result. My bootloader was toast.

I put in the RHEL 4 install disc, and at the boot prompt selected the rescue option.
boot: linux rescue
Once the rescue image booted, scanned the system and mounted read/write, I attempted to reinstall grub:
# chroot /mnt/sysimage/
# grub-install /dev/sda
/dev/md0 does not have any corresponding BIOS drive
# grub-install --recheck /dev/sda
/dev/md0 does not have any corresponding BIOS drive
#
An error. The md0 mirror, which is composed of sda and sdb, was complicating things. I though maybe I could fudge the device map by adding an entry to /boot/grub/device.map:
(fd0)   /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
(hd2) /dev/md0
# grub-install /dev/sda
The file /boot/grub/stage1 not read correctly.
That was no good either. Finally, I had to run grub manually.
# grub
grub> root (hd0,0)
root (hd0,0)
Filesystem type is ext2fs, partition type 0xfd
grub> setup (hd0)
setup (hd0)
Checking if "/boot/grub/stage1" exists... no
Checking if "/grub/stage1" exists... yes
Checking if "/grub/stage2" exists... yes
Checking if "/grub/e2fs_stage1_5" exists... yes
Running "embed /grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded.
succeeded
Running "install /grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/grub/stage2 /grub/grub.conf"... succeeded
Done.
grub> quit
# reboot
Fixed. I then also installed the bootloader on sdb (hd1), just in case.

6 comments:

Figjam said...

Hi,

I have a linux installation (debian) on a USB key and I regularly recover grub installations on software raid with the following three steps. It's never actually failed.

1. Boot on the key.
2. Mount sda's root partition on /mnt, mkdir /mnt/boot and mount sda's boot partition on /mnt/boot.
3. Run: grub-install --no-floppy --recheck --root-directory=/mnt /dev/sda

Gavin said...

Hi Figjam,

A bootable CD or a USB key are interchangeable in most cases. They are both external boot media to the actual system you are trying to repair. For older servers, like the one I had here, there are no bios options to boot from USB.

Your grub-install step would not have helped in this case. As you can see, I did try the recheck option and it refused to work. It is the main point of the post.

Additionally, I was trying to repair CentOS, not Debian. I strongly advise against mixing two different distributions in an emergency.

Moshe Linzer said...

Hi Gavin,

Just found your blog, nice going. I had to perform the same steps recently to recover a Dell machine that lost its boot record. only manual install for grub would work!

Moshe

Gavin said...

Glad I could help, Moshe.

Anonymous said...

Hi Gavin
I recently shutdown my RHEL V5 (HP DL585 G5) to upgrade the memory.
On restarting the server, the OS would stop at the "booting kernel" stage. The underlying disk structure was based on hardware based RAID 5 array, on a single logical disk.
After searching the web I found your article and followed it. Which successfully resulted in the server being able to boot again. A life saver of note!!!

Thanks a ton for the info.

Gordon MacKilligan

Gavin W. Burris said...

Glad I could help!