Changing the default kernel in Red Hat Enterprise Linux 8 , 9 & 10
Environment
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 10
Issue
- How to change the default boot entry for
kernelin Red Hat Enterprise Linux ? - Changing the default kernel of a Red Hat Enterprise Linux system when multiple kernel versions installed.
Resolution
Simple way common to RHEL8, RHEL9 and RHEL 10
1. Confirmation before the change
# grubby --default-kernel
/boot/vmlinuz-5.14.0-70.30.1.el9_0.x86_64
# uname -r
5.14.0-70.30.1.el9_0.x86_64
2. Show installed kernel list ( You can count 0,1,.. from the top of the title line)
# grubby --info=ALL | grep title
title="Red Hat Enterprise Linux (5.14.0-70.30.1.el9_0.x86_64) 9.0 (Plow)" <---0
title="Red Hat Enterprise Linux (5.14.0-70.13.1.el9_0.x86_64) 9.0 (Plow)" <---1
3. Set the default kernel
# grubby --set-default-index 1
4. Confirmation after the change
# grubby --default-kernel
/boot/vmlinuz-5.14.0-70.13.1.el9_0.x86_64
5. reboot the system
# reboot
6. Confirmation after system reboot
# uname -r
5.14.0-70.13.1.el9_0.x86_64
# grubby --default-kernel
/boot/vmlinuz-5.14.0-70.13.1.el9_0.x86_64
More Information
There are two ways to change the default kernel.
Using grub2-set-default
Listing BLS entry files of Installed Kernels:
Each kernel information exists in a separated BLS file in /boot/loader/entries directory:
# cd /boot/loader/entries/
# ls -l
total 16
-rw-r--r--. 1 root root 540 Jan 31 10:55 d5e7db3976314d06a6e09451488125db-0-rescue.conf
-rw-r--r--. 1 root root 502 Jan 31 10:55 d5e7db3976314d06a6e09451488125db-5.14.0-362.13.1.el9_3.x86_64.conf
-rw-r--r--. 1 root root 502 Jan 31 10:55 d5e7db3976314d06a6e09451488125db-5.14.0-362.18.1.el9_3.x86_64.conf
-rw-r--r--. 1 root root 498 Jan 31 10:55 d5e7db3976314d06a6e09451488125db-5.14.0-70.22.1.el9_0.x86_64.conf
Changing Default Kernel Boot Entry:
To change the default kernel boot entry using the
# grub2-set-default <XXX> //note, delete the ".conf" suffix
like:
# grub2-set-default d5e7db3976314d06a6e09451488125db-5.14.0-70.22.1.el9_0.x86_64
Check grubenv File:
To confirm if the specified default kernel is reflected, check the saved_entry value in the output of the following command:
# grub2-editenv /boot/grub2/grubenv list
Otherwise, in case of UEFI enabled:
# grub2-editenv /boot/efi/EFI/redhat/grubenv list
Confirm GRUB_DEFAULT=saved in /etc/sysconfig/grub
Above steps to change the default kernel can work with GRUB_DEFAULT=saved in /etc/sysconfig/grub, which is the default configuration.
Confirm DEFAULTKERNEL value in /etc/sysconfig/kernel
To configure a kernel variant such as kernel, kernel-rt, kernel-rt-debug as the default boot kernel, ensure the DEFAULTKERNEL value is updated failing which system will boot with a wrong undesired kernel version.
To change from kernel-core i.e default kernel to kernel-rt user must edit /etc/sysconfig/kernel to reflect the correct variant:
# cat /etc/sysconfig/kernel | grep -i DEFAULTKERNEL
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel-core
# sed -i 's/DEFAULTKERNEL=.*/DEFAULTKERNEL=kernel-rt-core/g' /etc/sysconfig/kernel
# cat /etc/sysconfig/kernel | grep -i DEFAULTKERNEL
# DEFAULTKERNEL specifies the default kernel package type
DEFAULTKERNEL=kernel-rt-core
Using grubby
Listing the Default Kernel:
To get the 'kernel filename' of the current default kernel:
# grubby --default-kernel
Eg:
# grubby --default-kernel
/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64
To get the index number of the current default kernel:
# grubby --default-index
Eg:
# grubby --default-index
0
Listing Available Kernels:
To get the list of file names of available kernels:
# ls -l /boot/vmlinuz-*
Eg:
# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 7872864 Jul 12 05:27 /boot/vmlinuz-0-rescue-31c619b4ae7b4a29b0cdd151ca2a7ca6
-rwxr-xr-x. 1 root root 7876960 Jun 24 06:52 /boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64
-rwxr-xr-x. 1 root root 7872864 Mar 13 08:34 /boot/vmlinuz-4.18.0-80.el8.x86_64
Changing Default Kernel Boot Entry:
To change the default kernel boot entry using 'kernel filename':
# grubby --set-default <kernel-filename>
Eg:
# grubby --set-default /boot/vmlinuz-4.18.0-80.el8.x86_64
OR
# grubby --set-default vmlinuz-4.18.0-80.el8.x86_64
To change the default kernel boot entry using kernel entry-index:
# grubby --set-default-index=<kernel-entry-index>
Eg:
# grubby --set-default-index=1
The detailed information of a certain kernel version can be collected by using --info, it will show the index as well:
# grubby --info <kernel-filename>
Eg:
# grubby --info /boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64
index=0
kernel="/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64"
args="ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet $tuned_params"
root="/dev/mapper/rhel-root"
initrd="/boot/initramfs-4.18.0-80.7.1.el8_0.x86_64.img $tuned_initrd"
title="Red Hat Enterprise Linux (4.18.0-80.7.1.el8_0.x86_64) 8.0 (Ootpa)"
id="31c619b4ae7b4a29b0cdd151ca2a7ca6-4.18.0-80.7.1.el8_0.x86_64"
Diagnostic Steps
- To determine the order of the
kernelentry-index, the latest kernel installed will have the entry-index of0and the older kernel version will get1. In the mentioned example older kernelkernel-4.18.0-80.el8.x86_64will have entry-index1and the latest kernelkernel-4.18.0-80.7.1.el8_0.x86_64will have entry-index0
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.