Red Hat Training

A Red Hat training course is available for RHEL 8

Chapter 9. Reinstalling GRUB

Reinstalling GRUB bootloader is a convenient way to fix certain problems usually caused by an incorrect installation of GRUB, missing files, or a broken system. You can resolve this issue by restoring the missing files and updating the boot information.

The following are the reasons to reinstall GRUB:

  • Upgrading GRUB bootloader.
  • Adding the boot information to another drive.
  • The user requires the GRUB bootloader to control installed operating systems. However, some operating systems are installed with their own bootloaders and reinstalling GRUB returns control to the desired operating system.
Note

GRUB restores files only if they are not corrupted.

9.1. Reinstalling GRUB on BIOS-based machines

You can reinstall GRUB using the grub2-install command.

Important

When you run the grub2-install command on an existing boot device, it overrides the existing GRUB to install the new GRUB. Hence, ensure that the system does not cause data corruption or boot crash during the installation before issuing the grub2-install command.

Procedure

  1. Issue the grub2-install command with the device argument. For example, if sda is your device:

    # grub2-install /dev/sda
  2. Reboot your system for the changes to take effect.

    # reboot

Additional resources

  • the grub-install(1) man page

9.2. Reinstalling GRUB on UEFI-based machines

You can reinstall GRUB using the yum reinstall command.

Important

Ensure that the system does not cause data corruption or boot crash during the installation before issuing the yum reinstall command.

Procedure

  1. Enter the yum reinstall command with the grub2-efi and shim bootloader files.

    # yum reinstall grub2-efi shim
  2. Reboot your system for the changes to take effect.

    # reboot

9.3. Resetting GRUB

Resetting GRUB completely removes all GRUB configuration files and system settings and reinstalls the bootloader. You can reset all the configuration settings to their default values, and thus fix failures caused by corrupted files and incorrect configuration.

Important

The following procedure will remove all the customization the user has made.

Procedure

  1. Remove the configuration files.

    # rm /etc/grub.d/*
    # rm /etc/sysconfig/grub
  2. Reinstall packages.

    • On BIOS-based machines, enter:

      # yum reinstall grub2-tools
    • On UEFI-based machines, enter:

      # yum reinstall grub2-efi shim grub2-tools
  3. Rebuild the grub.cfg file for the changes to take effect.

    • On BIOS-based machines, enter:

      # grub2-mkconfig -o /boot/grub2/grub.cfg
    • On UEFI-based machines, enter:

      # grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
  4. Follow Reinstalling GRUB procedure to restore GRUB on the /boot/ partition.