Show Table of Contents
Upgrading from
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 Legacyis no longer maintained and does not receive updates. GRUB Legacyis unable to boot on systems without the/boot/directory.GRUB 2has more features and is more reliable.GRUB 2supports 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
- Download the grub package:
~]#
yum reinstall -y --downloadonly grub - Locate the downloaded package:
~]#
find /var/cache/yum/ | grep "grub"Note
If you did not change the default cache location ofyum, then its cache is located in the/var/cache/yum/directory. If you changed the default cache location ofyum, consult its configuration to find it. For further information, see Working with Yum Cache and Configuring Yum and Yum Repositories . - 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
- Install the grub package from its backup:
~]#
rpm --install --force --nodeps grub-0.97-99.el6.x86_64.rpmThis step ensures that you have a recovery option in case that the upgrade fromGRUB LegacytoGRUB 2fails 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. - 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
- Find out the
GRUB Legacydesignation for the bootable device. For that, view theGRUB Legacyconfiguration file/boot/grub/grub.confand search for therootline:# 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, therootline specifies the bootable device. In this example,hd0,0is the bootable device. - Only perform this step if your
/boot/grub/device.mapis not correct. This might happen, for example, after changing hardware configuration.- Recreate
/boot/grub/device.map:~]#
grub-install --recheck /dev/sdaThe old configuration is backed up automatically in/boot/grub/device.map.backup. - 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
- Determine the mapping of the
GRUB Legacydevice designation to the device file. For that, take the device found in step 1, and find the corresponding entry in the/boot/grub/device.mapfile:# this device map was generated by anaconda (hd0) /dev/sda (hd1) /dev/sdb
In this example, the listing shows that for devicehd0the 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.
- Install the
GRUB 2files to the/boot/grub/directory of/dev/sdXdisk:~]#
grub2-install --grub-setup=/bin/true /dev/sdXSubstitute /dev/sdX with the bootable device file determined in the section called “Determining bootable device file”.The--grub-setup=/bin/trueoption ensures that the oldGRUB Legacyconfiguration is not deleted.Warning
Note the difference in the configuration file extensions:.confis forGRUB.cfgis forGRUB 2
Do not overwrite the oldGRUBconfiguration file by mistake in the next step. - Generate the
/boot/grub2/grub.cfg:~]#
grub2-mkconfig -o /boot/grub2/grub.cfgNote
For customizing the generatedGRUB 2configuration 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.cfgare 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.
- 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 theGRUB Legacybootable device designation. - Reboot the system.
- When presented with a
GRUB Legacymenu, select theGRUB 2 Testentry. - When presented with a
GRUB 2menu, select a kernel to boot. - If the above did not work, restart, and do not choose the
GRUB 2 Testentry on next boot.
Replacing and removing GRUB Legacy
If
GRUB 2 worked successfully, replace GRUB Legacy and remove it from the system:
- Overwrite the
GRUB Legacyboot sector with theGRUB 2bootloader:~]#
grub2-install /dev/sda - Uninstall the grub packages:
~]#
yum remove grub
The upgrade to
GRUB 2 is now finished.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.