2 ways to boot with old kernel version in RHEL 8 using grubby


GRUB2, Linux, Tips and Tricks

How to set default boot kernel in RHEL 8 Linux using Grubby? How to change the default boot entry for kernel in RHEL 8? How to boot with old kernel version in RHEL 8? How to revert to previous kernel version ?

boot with old kernel version and set default boot kernel in RHEL 8 using grubby

 

Earlier I had shared the steps to set default kernel in RHEL/CentOS 7 Linux node. Now with RHEL 8 the GRUB2 configuration parameter has changed again and now we use grubby to set default kernel or to change the default boot entry for kernel in the system.

At the time of writing this article CentOS 8 was not available hence the steps could not be validated on CentOS 8 but I will assume that the same steps should work also on CentOS 8. If you face any problems while executing these steps on CentOS 8 then please drop in the details in the comment box at the end of this article.

 

What is Grubby?

grubby is a command line tool for updating and displaying information about the configuration files for various architecture specific bootloaders. It is primarily designed to be used from scripts which install new kernels and need to find information about the current boot environment.

 

GRUB configuration file

The default bootloader target is primarily determined by the architecture for which grubby has been built. Each architecture has a preferred bootloader, and each bootloader has its own configuration file. If no bootloader is selected on the command line, grubby will use these default settings to search for an existing configuration. If no bootloader configuration file is found, grubby will use the default value for that architecture. These defaults are listed in the table below.

Arch Bootloader Configuration File
x86_64 [BIOS] grub2 /boot/grub2/grub.cfg
x86_64 [UEFI] grub2 /boot/efi/EFI/redhat/grub.cfg
i386 grub2 /boot/grub2/grub.cfg
ia64 grub2 /boot/efi/EFI/redhat/elilo.conf
ppc [>=Power8] grub2 /boot/grub2/grub.cfg
ppc [<=Power7] yaboot /etc/yaboot.conf
s390 zipl /etc/zipl.conf
s390x zipl /etc/zipl.conf

 

Grubby Arguments

Below are some of the arguments which we will use in this article. These snippets are taken from man page of grubby

--set-default=kernel-path
       The first entry which boots the specified kernel is made the default boot entry. This may not be invoked with --set-default-index.

--set-default-index=entry-index
       Makes the given entry number the default boot entry. This may not be invoked with --set-default.  The given value represents the index in the post-modification boot entry list.

--default-kernel
       Display the full path to the current default kernel and exit.

--default-index
       Display the numeric index of the current default boot entry and exit.
			  
--info=kernel-path
       Display  information  on  all  boot entries which match kernel-path. If kernel-path is DEFAULT, then information on the default kernel is displayed. If kernel-path is ALL, then information on all boot entries are dis‐played.

 

Check default boot kernel

Before we configure our system to boot with old kernel version or set different boot kernel for our RHEL 8 system, let us check the current default kernel.

[root@rhel-8 ~]# grubby --default-kernel
/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64

Here this means that post reboot the node will continue to boot from /boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64 and mapped entries

To check the mapped index with this kernel use below command

[root@rhel-8 ~]# grubby --default-index
0

You can get the list of initrd image available on your system under /boot as shown below:

[root@rhel-8 ~]# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 7872864 Jul 30 16:00 /boot/vmlinuz-0-rescue-fe04eeb0b80e4239ad8237cfbbef7edf
-rwxr-xr-x. 1 root root 7868768 Jun 14 18:59 /boot/vmlinuz-4.18.0-80.4.2.el8_0.x86_64
-rwxr-xr-x. 1 root root 7876960 Jun 24 16:22 /boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64
-rwxr-xr-x. 1 root root 7872864 Mar 13 18:04 /boot/vmlinuz-4.18.0-80.el8.x86_64

To get more information about the respective initrd image, you can use grubby --info

[root@rhel-8 ~]# 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="fe04eeb0b80e4239ad8237cfbbef7edf-4.18.0-80.7.1.el8_0.x86_64"

 

Get index ID of kernel using grubby

Before we configure our system to boot with old kernel version in RHEL 8, we must be familiar with the index mapping. Get the list of available kernels installed on your system

[root@rhel-8 ~]# rpm -qa | grep kernel | sort -V
kernel-4.18.0-80.4.2.el8_0.x86_64
kernel-4.18.0-80.7.1.el8_0.x86_64
kernel-4.18.0-80.el8.x86_64
kernel-core-4.18.0-80.4.2.el8_0.x86_64
kernel-core-4.18.0-80.7.1.el8_0.x86_64
kernel-core-4.18.0-80.el8.x86_64
kernel-modules-4.18.0-80.4.2.el8_0.x86_64
kernel-modules-4.18.0-80.7.1.el8_0.x86_64
kernel-modules-4.18.0-80.el8.x86_64
kernel-tools-4.18.0-80.el8.x86_64
kernel-tools-libs-4.18.0-80.el8.x86_64

So as you see for the demonstration of this article I have installed 3 versions of kernel. Similarly I have three different initrd images mapped to respective kernel

[root@rhel-8 ~]# ls -l /boot/vmlinuz-*
-rwxr-xr-x. 1 root root 7872864 Jul 30 16:00 /boot/vmlinuz-0-rescue-fe04eeb0b80e4239ad8237cfbbef7edf
-rwxr-xr-x. 1 root root 7868768 Jun 14 18:59 /boot/vmlinuz-4.18.0-80.4.2.el8_0.x86_64
-rwxr-xr-x. 1 root root 7876960 Jun 24 16:22 /boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64
-rwxr-xr-x. 1 root root 7872864 Mar 13 18:04 /boot/vmlinuz-4.18.0-80.el8.x86_64

Here the latest kernel will be considered to have index 0
then the older version will be mapped with index 1
then the next older version will be mapped with index 2
and so on..

Now here since my system is running with the latest available kernel on my system, the index will be shown as "0"

[root@rhel-8 ~]# uname -r
4.18.0-80.7.1.el8_0.x86_64

[root@rhel-8 ~]# grubby --default-index
0

Similarly if I boot my system with older kernel then the index will be shown respectively

[root@rhel-8 ~]# grubby --default-index
1

[root@rhel-8 ~]# uname -r
4.18.0-80.4.2.el8_0.x86_64

For the oldest kernel available on my system

[root@rhel-8 ~]# grubby --default-index
2

[root@rhel-8 ~]# uname -r
4.18.0-80.el8.x86_64

 

Set default boot kernel (Grubby)

Now since we know the default kernel and index, we can proceed with the next steps to set default boot kernel using grubby in RHEL 8 and allow your system to boot with old kernel version. There are two methods to set default kernel using grubby tool

 

Method 1: Boot with old kernel version using index

I hope we are clear on the kernel to index mapping part. So here I will demonstrate the usage of --set-default-index to set default kernel using index ID. Currently my system is running with index 0 i.e. latest kernel, which now I will change to older kernel version with index 1

[root@rhel-8 ~]# grubby --set-default-index=1
The default is /boot/loader/entries/fe04eeb0b80e4239ad8237cfbbef7edf-4.18.0-80.4.2.el8_0.x86_64.conf with index 1 and kernel /boot/vmlinuz-4.18.0-80.4.2.el8_0.x86_64

Next you can check the default kernel using which the system will be booted during next reboot.

[root@rhel-8 ~]# grubby --default-kernel
/boot/vmlinuz-4.18.0-80.4.2.el8_0.x86_64

Similarly check the default index value which will be active post reboot

[root@rhel-8 ~]# grubby --default-index
1

To activate the changes, reboot the node

[root@rhel-8 ~]# reboot

Post reboot validate the changes

[root@rhel-8 ~]# grubby --default-index
1

[root@rhel-8 ~]# grubby --default-kernel
/boot/vmlinuz-4.18.0-80.4.2.el8_0.x86_64

As expected now our system is running with kernel mapped with index 1 i.e. 4.18.0-80.4.2.el8

[root@rhel-8 ~]# uname -r
4.18.0-80.4.2.el8_0.x86_64

Verify the same in the active GRUB2 configuration file

[root@rhel-8 ~]# cat /proc/cmdline
BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-80.4.2.el8_0.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet

 

Method 2: Boot with old kernel version using initrd image

Now here this step is little less confusing as you don't have to remember the index value. Here you can directly give the initrd image location using which you wish to set the default boot kernel.

Now currently my system is running with below kernel version

[root@rhel-8 ~]# uname -r
4.18.0-80.4.2.el8_0.x86_64

To change default kernel to 4.18.0-80.7.1.el8_0.x86_64 which is the latest available kernel on our system we will use the mapped initrd image

[root@rhel-8 ~]# grubby --set-default=/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64
The default is /boot/loader/entries/fe04eeb0b80e4239ad8237cfbbef7edf-4.18.0-80.7.1.el8_0.x86_64.conf with index 0 and kernel /boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64

Next you can verify the status of default kernel and default index which will be active post reboot of the node

[root@rhel-8 ~]# grubby --default-index
0

[root@rhel-8 ~]# grubby --default-kernel
/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64

Next let us reboot our node to activate the changes

[root@rhel-8 ~]# reboot

Post reboot as expected, our new kernel is loaded on the system

[root@rhel-8 ~]# uname -r
4.18.0-80.7.1.el8_0.x86_64

verify the same using GRUB2 configuration file

[root@rhel-8 ~]# cat /proc/cmdline
BOOT_IMAGE=(hd0,msdos1)/vmlinuz-4.18.0-80.7.1.el8_0.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet 

The same details can be checked using below commands again

[root@rhel-8 ~]# grubby --default-kernel
/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64

[root@rhel-8 ~]# grubby --default-index
0

 

What's Next

I hope you know that with RHEL 8 we have new architecture for kernel i.e. kernel is replaced by kernel-core, kernel-module:
Best practices to update kernel-core in RHEL/CentOS 8

Lastly I hope the steps from the article to set default boot kernel using grubby and boot with old kernel version in RHEL 8 Linux was helpful. So, let me know your suggestions and feedback using the comment section.

 

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

1 thought on “2 ways to boot with old kernel version in RHEL 8 using grubby”

  1. ¡GRACIAS! Thank you very much for the work .
    The only place I found with a coherent explanation on how to change the default kernel in Centos 8.
    In principle is so easy with that grubby tool.
    Best regards

    Reply

Leave a Comment