Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

25.8. Upgrading from GRUB Legacy to GRUB 2

When you do an in-place upgrade of Red Hat Enterprise Linux (RHEL) from version 6 to 7, the upgrade from GRUB Legacy to GRUB 2 does not happen automatically, but it can be done manually. Perform the GRUB upgrade for these reasons:
  • In RHEL 7 and later versions, GRUB Legacy is no longer maintained and does not receive updates.
  • GRUB Legacy is unable to boot on systems without the /boot/ directory.
  • GRUB 2 has more features and is more reliable.
  • GRUB 2 supports more hardware configurations, file systems, and drive layouts.

Prerequisites for upgrading

Prior to upgrading your Red Hat Enterprise Linux 7 system, do a manual backup of GRUB Legacy. Note that GRUB Legacy is available through the grub package.

Procedure 25.2. Creating a manual backup of GRUB Legacy

  1. Download the grub package:
    ~]#  yum reinstall -y --downloadonly grub
  2. Locate the downloaded package:
    ~]# find /var/cache/yum/ | grep "grub"

    Note

    If you did not change the default cache location of yum, then its cache is located in the /var/cache/yum/ directory. If you changed the default cache location of yum, consult its configuration to find it. For further information, see Working with Yum Cache and Configuring Yum and Yum Repositories .
  3. Copy the package to a safe location, for example to the /root/ directory:
    ~]# cp /var/cache/yum/x86_64/6Server/rhel/packages/grub-0.97-99.el6.x86_64.rpm /root/

    Important

    Do not copy the grub package into the /boot/ directory. This may cause the in-place upgrade from RHEL 6 to RHEL 7 to fail if /boot/ does not have enough free space. For more information, see the pre-upgrade and upgrade documentation:

Upgrading from GRUB Legacy to GRUB 2 after the in-place upgrade of the operating system

Procedure 25.3. Upgrading from GRUB Legacy to GRUB 2

  1. Install the grub package from its backup:
    ~]# rpm --install --force --nodeps grub-0.97-99.el6.x86_64.rpm
    This step ensures that you have a recovery option in case that the upgrade from GRUB Legacy to GRUB 2 fails at some point. Note that there can be various versions of the package, so you need to use the precise name of your backed up package.
  2. Make sure that the grub2 package is installed. If grub2 is not on the system after the upgrade to RHEL 7, you can install it manually by running:
    ~]# yum install grub2

Determining bootable device file

  1. Find out the GRUB Legacy designation for the bootable device. For that, view the GRUB Legacy configuration file /boot/grub/grub.conf and search for the root line:
    # grub.conf generated by anaconda
    #
    # Note that you do not have to rerun GRUB 2 after making changes to this file
    # NOTICE:  You have a /boot partition.  This means that
    #          all kernel and initrd paths are relative to /boot/, eg.
    #          root (hd0,0)
    #          kernel /vmlinuz-version ro root=/dev/mapper/vg_rhel68-lv_root
    #          initrd /initrd-[generic-]version.img
    #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/grub/splash.xpm.gz
    hiddenmenu
    title Red Hat Enterprise Linux Server (2.6.32-642.4.2.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-642.4.2.el6.x86_64 ro root=/dev/mapper/vg_rhel68-lv_root rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_rhel68/lv_root rd_LVM_LV=vg_rhel68/lv_swap rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-642.4.2.el6.x86_64.img
    title Red Hat Enterprise Linux 6 (2.6.32-642.el6.x86_64)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-642.el6.x86_64 ro root=/dev/mapper/vg_rhel68-lv_root rd_NO_LUKS  KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=vg_rhel68/lv_root rd_LVM_LV=vg_rhel68/lv_swap rd_NO_DM rhgb quiet
    initrd /initramfs-2.6.32-642.el6.x86_64.img
    For each menu entry, the root line specifies the bootable device. In this example, hd0,0 is the bootable device.
  2. Only perform this step if your /boot/grub/device.map is not correct. This might happen, for example, after changing hardware configuration.
    1. Recreate /boot/grub/device.map:
      ~]# grub-install --recheck /dev/sda
      The old configuration is backed up automatically in /boot/grub/device.map.backup.
    2. If the previous step broke your device mapping configuration, restore the backup:
      ~]# rm /boot/grub/device.map
      ~]# cp /boot/grub/device.map.backup /boot/grub/device.map
  3. Determine the mapping of the GRUB Legacy device designation to the device file. For that, take the device found in step 1, and find the corresponding entry in the /boot/grub/device.map file:
    # this device map was generated by anaconda
    (hd0)     /dev/sda
    (hd1)     /dev/sdb
    In this example, the listing shows that for device hd0 the device file is /dev/sda.
    Make note of the device file, it will be used in the next procedure.

Generating the GRUB 2 configuration files

Now we will add GRUB 2 configuration without removing the original GRUB Legacy configuration. We will keep GRUB Legacy configuration in case GRUB 2 does not work correctly.
  1. Install the GRUB 2 files to the /boot/grub/ directory of /dev/sdX disk:
    ~]# grub2-install --grub-setup=/bin/true /dev/sdX
    Substitute /dev/sdX with the bootable device file determined in the section called “Determining bootable device file”.
    The --grub-setup=/bin/true option ensures that the old GRUB Legacy configuration is not deleted.

    Warning

    Note the difference in the configuration file extensions:
    • .conf is for GRUB
    • .cfg is for GRUB 2
    Do not overwrite the old GRUB configuration file by mistake in the next step.
  2. Generate the /boot/grub2/grub.cfg:
    ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

    Note

    For customizing the generated GRUB 2 configuration file, see Section 25.5, “Customizing the GRUB 2 Configuration File”. You should make changes in /etc/default/grub, not directly in /boot/grub2/grub.cfg. Otherwise, changes in /boot/grub2/grub.cfg are lost every time the file is re-generated.

Testing GRUB 2 with GRUB Legacy still installed

Now we will test GRUB 2 without removing the GRUB Legacy configuration. The GRUB Legacy configuration needs to stay until GRUB 2 configuration is verified; otherwise the system might become unbootable. To safely test GRUB 2 configuration, we will start GRUB 2 from GRUB Legacy.
  1. Add a new section into /boot/grub/grub.conf:
    title GRUB 2 Test
    root (hd0,0)
    kernel /grub2/i386-pc/core.img
    boot
    Substitute (hd0,0) with the GRUB Legacy bootable device designation.
  2. Reboot the system.
  3. When presented with a GRUB Legacy menu, select the GRUB 2 Test entry.
  4. When presented with a GRUB 2 menu, select a kernel to boot.
  5. If the above did not work, restart, and do not choose the GRUB 2 Test entry on next boot.

Replacing and removing GRUB Legacy

If GRUB 2 worked successfully, replace GRUB Legacy and remove it from the system:
  1. Overwrite the GRUB Legacy boot sector with the GRUB 2 bootloader:
    ~]# grub2-install /dev/sda
  2. Uninstall the grub packages:
    ~]# yum remove grub
The upgrade to GRUB 2 is now finished.