Repairing a Damaged GRUB with CentOS 5
Server Training - Ubuntu Server Administration

Repairing a Damaged GRUB with CentOS 5

GRUB, the Grand Unified Bootloader, is usually quite dependable. But, like everything else in life, it isn't perfect. Once in a blue moon, it may give you some problems.

Lesson 6 | Lesson 8

Recently, , we used YUM Extender to update one of our CentOS 5 machines to CentOS 5.1. The update included a new kernel, which meant that the GRUB configuration had to be re-written. Usually, that goes without a hitch. This time, though, was different.

When the update completed, we rebooted the machine so that we could use the new kernel. But, when it got to the point where we should have seen the GRUB splash screen, all we got was a completely black screen with the single word "GRUB". At that point, the boot-up process stopped dead in its tracks. Apparently, the update didn't update GRUB correctly.

To see what the problem was, we booted the machine from the CentOS 5 installation DVD. At the opening menu, we pressed the F2 key to get to the options menu. There, we typed in "linux rescue". After answering the setup screens, and choosing "No" when asked if we wanted to set up networking, we arrived at the command prompt.

If you ever get the chance to do this, pay close attention to the screens leading up to the command prompt. The last one tells you what you need to do next. (That is, in case you don't remember from this article.)

At the command prompt, enter:

chroot /mnt/sysimage


Now, we've mounted the hard drive's filesystem, and we can do whatever we need to with it.

Next, let's cd to the GRUB directory, and take a look at the menu.lst file.

cd /boot/grub

less menu.lst


You should see something like:

# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
title CentOS (2.6.18-53.1.4.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-53.1.4.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.18-53.1.4.el5.img
title CentOS (2.6.18-8.1.15.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-8.1.15.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.18-8.1.15.el5.img


Entries for both the new kernel and the old one are there, so this apparently isn't the problem. We also cd'ed back to the /boot directory, and verified that all of the proper kernel files were there.


The only possibility left is that the new GRUB configuration just didn't get written to the hard drive's Master Boot Record. To test our theory, we tried running the "grub-install' utility. For this, we entered the "grub-install" command, followed by the device on which we wanted to install it. In this case, we needed to install it on the first hard drive:

grub-install hd0


When it completed,  enter "exit" twice to reboot the machine, and removed the installation DVD. It worked like a champ, problem resolved.


For more information, enter "info grub" and "info grub-install" at the command-line of your Linux machine.