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.