How to boot with old kernel version in RHEL7 ?
Environment
- Red Hat Enterprise Linux 7 [ALL]
Issue
- System installed with latest kernel version, but need to boot with old one.
- How to change the default boot entry for kernel in RHEL 7 ?
Resolution
-
By default, the key for the
GRUB_DEFAULTdirective in the/etc/default/grubfile is the word saved. This instructs GRUB 2 to load the kernel specified by thesaved_entrydirective in the GRUB 2 environment file, located at/boot/grub2/grubenv. One can set another GRUB record to be the default, using thegrub2-set-defaultcommand, which will update the GRUB 2 environment file. -
By default, the
saved_entryvalue is set to the name of latest installed kernel of package type kernel. This is defined in/etc/sysconfig/kernelby theUPDATEDEFAULTandDEFAULTKERNELdirectives. The file can be viewed by the root user as follows:$ cat /etc/sysconfig/kernel # UPDATEDEFAULT specifies if new-kernel-pkg should make # new kernels the default UPDATEDEFAULT=yes # DEFAULTKERNEL specifies the default kernel package type DEFAULTKERNEL=kernel -
To force a system to always use a particular menu entry, use the menu entry name as the key to the
GRUB_DEFAULTdirective in the/etc/default/grubfile. To list the available menu entries, run the following command as root:~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg Eg: ~]# awk -F\' '$1=="menuentry " {print $2}' /etc/grub2-efi.cfg Red Hat Enterprise Linux Server (3.10.0-693.el7.x86_64) 7.3 (Maipo) <<==== Entry 0 Red Hat Enterprise Linux Server (3.10.0-514.el7.x86_64) 7.3 (Maipo) <<==== Entry 1 Red Hat Enterprise Linux Server (0-rescue-d3c598b9d2204138bd2e1001316a5cc6) 7.3 (Maipo) -
GRUB 2 supports using a numeric value as the key for the
saved_entrydirective to change the default order in which the kernel or operating systems are loaded. To specify which kernel or operating system should be loaded first, pass its number to thegrub2-set-defaultcommand. For example:~]# grub2-set-default 1 -
Check the below file to see the kernel which will be loaded at next boot, crosscheck the numeric value with the menuentry in the
/etc/default/grubfile.~]# cat /boot/grub2/grubenv |grep saved Eg: ~]# cat /boot/grub2/grubenv |grep saved saved_entry=1 -
Changes to
/etc/default/grubrequire rebuilding thegrub.cfgfile as follows: -
Rebuild the
/boot/grub2/grub.cfgfile by running the grub2-mkconfig -o command as follows:- On BIOS-based machines:
~]# grub2-mkconfig -o /boot/grub2/grub.cfg - On UEFI-based machines:
~]# grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
- On BIOS-based machines:
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
