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

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • 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. CentOS / RHEL 7 : GRUB2 configuration file /boot/grub2/grub.cfg explained
  2. How to Check Btrfs FileSystem Usage and Perform Balancing
  3. CentOS / RHE 7 : How to Prevent Users from Using the Last 10 Passwords
  4. watch command examples to run a command repeatedly or monitor dynamically changeable files (like /proc/*)
  5. How To Send Mails To an External User With Mailx on Linux
  6. How to find which rpm package provides a specific file or library in RHEL / CentOS
  7. Audit Rule Configuration not Reflected – How to troubleshoot
  8. How to monitor the status of dm-multipathing and multipath devices (path groups) in Linux
  9. How to make alias command work in bash script or bashrc file
  10. Configuring Network Redundancy for PaceMaker Cluster Communication

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ICMP redirects on CentOS/RHEL
  • What are Oracle Key Vault Roles
  • What Is Oracle Key Vault
  • Auditing with Oracle Database Vault Reports
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary