Easy steps to change default kernel version RHEL/CentOS 8


CentOS 8

In this tutorial we will learn the steps to change default kernel version i.e. switch between different installed kernel versions in RHEL/CentOS 8. The steps involved with RHEL/CentOS 8 are completely different compared to older releases as GRUB2 has been further upgraded to what we had with RHEL/CentOS 7. Hence now we have a special designated tool called grubby to change default kernel versions

 

Overview on grubby

  • grubby is a command line tool used to configure bootloader menu entries across multiple architectures.
  • It is used 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.
  • If no bootloader configuration file is found, grubby will use the default value for that architecture for example grub2 for x86_64 machines, elilo for ia64 etc

 

List installed kernel versions

For the sake of this tutorial I have installed multiple kernels on my Red Hat 8 server. So we will switch between these kernel versions in our example.

# rpm -qa | grep kernel | sort
kernel-4.18.0-193.1.2.el8_2.x86_64
kernel-4.18.0-193.14.3.el8_2.x86_64
kernel-4.18.0-193.el8.x86_64
kernel-core-4.18.0-193.1.2.el8_2.x86_64
kernel-core-4.18.0-193.14.3.el8_2.x86_64
kernel-core-4.18.0-193.el8.x86_64
kernel-modules-4.18.0-193.1.2.el8_2.x86_64
kernel-modules-4.18.0-193.14.3.el8_2.x86_64
kernel-modules-4.18.0-193.el8.x86_64
kernel-tools-4.18.0-193.el8.x86_64
kernel-tools-libs-4.18.0-193.el8.x86_64

With RHEL/CentOS 8 now the kernel rpm is distributed across kernel-core and kernel-modules. You can read more about these kernel rpms in What are kernel-core and kernel-module rpms and how to upgrade these rpms

Here we got a long list of kernel and it's dependent packages. You can use grubby to get a cleaner output for list of installed kernels

# grubby --info=ALL | grep ^kernel
kernel="/boot/vmlinuz-4.18.0-193.14.3.el8_2.x86_64"
kernel="/boot/vmlinuz-4.18.0-193.1.2.el8_2.x86_64"
kernel="/boot/vmlinuz-4.18.0-193.el8.x86_64"
kernel="/boot/vmlinuz-0-rescue-d88fa2c7ff574ae782ec8c4288de4e85"

This will print the initramfs version of all the installed kernels.

 

Currently active (loaded) kernel

To check the currently active kernel version we will use uname with -r which will give us kernel release information:

# uname -r
4.18.0-193.el8.x86_64

 

Get more information of boot entries

Now with grubby we have listed the available boot entries, to get more information on individual boot entries we can use:

# grubby --info="/boot/vmlinuz-4.18.0-193.14.3.el8_2.x86_64"
index=0
kernel="/boot/vmlinuz-4.18.0-193.14.3.el8_2.x86_64"
args="ro resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet biosdevname=0 net.ifnames=0 enforcing=0 $tuned_params"
root="/dev/mapper/rhel-root"
initrd="/boot/initramfs-4.18.0-193.14.3.el8_2.x86_64.img $tuned_initrd"
title="Red Hat Enterprise Linux (4.18.0-193.14.3.el8_2.x86_64) 8.2 (Ootpa)"
id="d88fa2c7ff574ae782ec8c4288de4e85-4.18.0-193.14.3.el8_2.x86_64"

 

Check the kernel version which is going to be activated post reboot

Now to determine the kernel version which will be activated post reboot we use:

# grubby --grub2 --default-title
Red Hat Enterprise Linux (4.18.0-193.14.3.el8_2.x86_64) 8.2 (Ootpa)

So our currently active kernel was 4.18.0-193.el8.x86_64, but after reboot 4.18.0-193.14.3.el8_2.x86_64 will be active.

To list the boot entry of the default kernel i.e. the kernel which will be active post reboot

# grubby --default-kernel
/boot/vmlinuz-4.18.0-193.14.3.el8_2.x86_64

Similarly to get the index value of default kernel

# grubby --default-index
0

So the boot entry with index value 0 will be activated post reboot of my Linux server.

 

Change the default kernel (switch kernel version)

Now assuming we wish to change the default kernel which will be active post reboot from 4.18.0-193.14.3.el8_2.x86_64 to 4.18.0-193.1.2.el8_2.x86_64

We can either use

  • kernel title
  • kernel boot entry
  • kernel index value

to change the default kernel version and to switch the kernel for activation post reboot. In this example I am using kernel boot entry to change default kernel version

# grubby --set-default "/boot/vmlinuz-4.18.0-193.1.2.el8_2.x86_64"
The default is /boot/loader/entries/d88fa2c7ff574ae782ec8c4288de4e85-4.18.0-193.1.2.el8_2.x86_64.conf with index 1 and kernel /boot/vmlinuz-4.18.0-193.1.2.el8_2.x86_64

So the default kernel version is successfully updated.

 

Verify the new default kernel

Next use the same command as used earlier with grubby to verify the new default kernel:

# grubby --default-kernel
/boot/vmlinuz-4.18.0-193.1.2.el8_2.x86_64

To get more information of this boot entry:

# grubby --info /boot/vmlinuz-4.18.0-193.1.2.el8_2.x86_64
index=1
kernel="/boot/vmlinuz-4.18.0-193.1.2.el8_2.x86_64"
args="ro resume=/dev/mapper/rhel-swap rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet biosdevname=0 net.ifnames=0 enforcing=0 $tuned_params"
root="/dev/mapper/rhel-root"
initrd="/boot/initramfs-4.18.0-193.1.2.el8_2.x86_64.img $tuned_initrd"
title="Red Hat Enterprise Linux (4.18.0-193.1.2.el8_2.x86_64) 8.2 (Ootpa)"
id="d88fa2c7ff574ae782ec8c4288de4e85-4.18.0-193.1.2.el8_2.x86_64"

So we can also verify the default index, it should be "1" based on the above information:

# grubby --default-index
1

Now reboot the server and verify the active kernel using uname:

# uname -r
4.18.0-193.1.2.el8_2.x86_64

So our active kernel is same as we had set for default kernel. Using this method you can easily switch between different kernel versions in RHEL/CentOS 8 Linux.

 

What's Next

Now since you know about this wonderful grubby tool, it is time to explore this command and learn more about it's capabilities:

 

Conclusion

In this tutorial we learned about grubby tool in brief and how it can be used to change default kernel version in RHEL/CentOS 8 Linux. grubby is a very versatile tool and can do much more than switching kernel versions such as updating kernel entries, grub configuration etc.

Lastly I hope the steps from the article to switch between different kernel versions in Red Hat and CentOS 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!!

5 thoughts on “Easy steps to change default kernel version RHEL/CentOS 8”

Leave a Comment