25.8. Upgrading from GRUB Legacy to GRUB 2
GRUB 2does 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
GRUB 2has more features and is more reliable.
GRUB 2supports more hardware configurations, file systems, and drive layouts.
Prerequisites for upgrading
GRUB Legacy. Note that
GRUB Legacyis available through the grub package.
Procedure 25.2. Creating a manual backup of
- Download the grub package:
yum reinstall -y --downloadonly grub
- Locate the downloaded package:
find /var/cache/yum/ | grep "grub"
- Copy the package to a safe location, for example to the
cp /var/cache/yum/x86_64/6Server/rhel/packages/grub-0.97-99.el6.x86_64.rpm /root/
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 from
GRUB 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 the
GRUB Legacyconfiguration file
/boot/grub/grub.confand search for the
# 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.imgFor each menu entry, the
rootline 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.
grub-install --recheck /dev/sdaThe old configuration is backed up automatically in
- If the previous step broke your device mapping configuration, restore the backup:
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
# this device map was generated by anaconda (hd0) /dev/sda (hd1) /dev/sdbIn this example, the listing shows that for device
hd0the 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
GRUB 2configuration without removing the original
GRUB Legacyconfiguration. We will keep
GRUB Legacyconfiguration in case
GRUB 2does not work correctly.
- Install the
GRUB 2files to the
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 old
GRUB Legacyconfiguration is not deleted.
WarningNote the difference in the configuration file extensions:
Do not overwrite the old
GRUBconfiguration file by mistake in the next step.
- Generate the
grub2-mkconfig -o /boot/grub2/grub.cfg
NoteFor customizing the generated
GRUB 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
GRUB 2without removing the
GRUB Legacyconfiguration. The
GRUB Legacyconfiguration needs to stay until
GRUB 2configuration is verified; otherwise the system might become unbootable. To safely test
GRUB 2configuration, we will start
- Add a new section into
title GRUB 2 Test root (hd0,0) kernel /grub2/i386-pc/core.img bootSubstitute (hd0,0) with the
GRUB Legacybootable device designation.
- Reboot the system.
- When presented with a
GRUB Legacymenu, select the
GRUB 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
GRUB 2worked successfully, replace
GRUB Legacyand remove it from the system:
- Overwrite the
GRUB Legacyboot sector with the
- Uninstall the grub packages:
yum remove grub
GRUB 2is now finished.