Under some rare conditions, you may get a GRUB loader corruption. This post illustrates how to re-install the GRUB loader on CentOS/RHEL 5 or 6.
How do you know GRUB has corrupted
Below are some of the symptoms you would see when there is a GRUB loader corruption.
1. The GRUB menu is not shown when booting the server
2. Boot the server into rescue mode using installation DVD, and check the header of the booting diskIf the GRUB loader is corrupted:
# file -s /dev/sda /dev/sda: x86 boot sector; partition 1: ID=0x83, active, starthead 1, startsector 63, 64998927 sectors; partition 2: ID=0x82, starthead 254, startsector 64998990, 2104515 sectors
While a good one looks like:
# file -s /dev/sda /dev/sda: x86 boot sector; partition 1: ID=0x83, active, starthead 1, startsector 63, 64998927 sectors; partition 2: ID=0x82, starthead 254, startsector 64998990, 2104515 sectors, code offset 0x48
The output may vary from different releases, but the key point is that the first output is missing ‘code offset 0x48‘, which is a indicator of GRUB Stage 1 code.
Reinstalling GRUB loader
Let’s assume that the booting disk is sda, the / partition is sda2, and /boot partition is sda1.
1. Boot the server into rescue mode, and mount the filesystem automatically. Please refer to the below post for booting the server in rescue mode.
2. The / partition would be mounted under /mnt/sysimage automatically. If not, mount it manually:
# mount /dev/sda2 /mnt/sysimage
3. Mount the /boot partition and /dev manually, to prepare the chroot environment:
# mount /dev/sda1 /mnt/sysimage/boot # mount -o bind /dev /mnt/sysimage/dev # chroot /mnt/sysimage
4. Re-install the GRUB loader
# grub-install /dev/sda
Reboot the server and you should able to see the GRUB menu back.
Re-install grub on a multipath device
Follow the steps below when a server configured to boot from a Storage Area Network (SAN) using multipathed devices requires to have grub re-installed. Grub requires re-installation whenever the Master Boot Record (MBR) on the boot device is damaged or overwritten by other boot loaders. It is also required in situations where the boot device changes post-installation like when the boot from SAN configuration is enabled after the server has been installed or when a single-pathed SAN boot device is reconfigured to become multipathed.
1. Boot the server in rescue mode with multipathing enabled using the “linux rescue mpath” boot option. To view the current multipath configuration, you may run the following command from in a rescue environment:
# multipath -ll
2. Edit /etc/fstab to use multipath device names (/dev/mapper/mpathX) instead of plain names (/dev/sdY) to Mount /boot. We recommend using the UUID of /boot to make the device identification more reliable.
3. Add the multipath device containing /boot to grub and install the boot loader using:
# grub grub> device (hd0) /dev/mapper/mpatha grub> root (hd0,0) grub> setup (hd0) grub> quit
Note: The grub-install command does not work for multipath devices.
4. Re-generate the initial ramdisk refering below post.
CentOS / RHEL 5 : How to rebuild Initial Ramdisk Image