• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL 5,6 : How to reinstall GRUB loader from rescue mode

by admin

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.

CentOS / RHEL 6 : How to boot into 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.

# reboot
CentOS / RHEL 7 : How to reinstall GRUB2 from rescue mode

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 6 : How to rebuild Initial Ramdisk Image
CentOS / RHEL 5 : How to rebuild Initial Ramdisk Image

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. ansible-galaxy – Create and manage Ansible roles (Command Examples)
  2. bison Command Examples (GNU parser generator)
  3. “git reset” Command Examples
  4. blkid Command Examples in Linux
  5. dircolors: Output commands to set the LS_COLOR environment variable and style ls, dir, etc
  6. Understanding SELinux Policies in Linux
  7. CentOS / RHEL 7 : Understanding Kexec and Kdump
  8. fallocate: command not found
  9. gh issue create: Create GitHub issues on a repository from the command-line
  10. Linux OS Service ‘iptables’

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright