1. Introduction

While regular Linux kernels might get a lot of upgrades, long-term support (LTS) kernel upgrades are predictable or relatively infrequent, thanks to their stability. The stability of LTS kernels is largely due to their extensive pre-release maintenance periods, which allow for thorough testing, security patching, debugging, and more.

Due to their high stability, LTS kernels are more dependable. That’s why they are preferred for critical systems. So, given an infrastructure with a regular kernel, we may have to switch to an LTS kernel to ensure reliability. In this tutorial, we’ll explore how to switch a Linux installation to the LTS kernel.

2. Switching to LTS Kernel on Debian-Based Systems

Before we switch to an LTS kernel, we may have to install an LTS kernel package. We can do this with apt if the kernel we want is available in our apt repositories.

To get the names of some of the LTS kernel packages available in our apt repositories, we can do an apt search:

$ sudo apt search linux-image | grep lts
linux-image-aws-lts-22.04/jammy-updates amd64
linux-image-azure-fde-lts-22.04/jammy-updates amd64
linux-image-azure-lts-22.04/jammy-updates amd64
linux-image-gcp-lts-22.04/jammy-updates amd64
linux-image-oracle-lts-22.04/jammy-updates,jammy-security amd64

Once we see our desired LTS kernel amongst those available in our apt repositories, we can proceed with the installation. To do so, we’ll start by updating our apt repositories:

$ sudo apt update

Next, we’ll install our LTS kernel package:

$ sudo apt install linux-image-aws-lts-22.04

By running the command above, we’ll install a long-term support Linux kernel for our AWS compute instance. The kernel in this case is based on Linux kernel 5.15 – one of seven current long-term release kernels.

After installing the package, we must use update-grub to add the LTS kernel to the system’s GRUB boot configuration:

$ sudo update-grub
Sourcing file `/etc/default/grub'
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.

With GRUB updated, we reboot the system to load the LTS kernel. Once the system is rebooted, we can confirm the installed kernel by running the uname command with the -r and -s options:

$ uname -rs
Linux 5.15.0-1050-aws

If we want a different LTS kernel, we replace linux-image-aws-lts-22.04 with the package name of our preferred version:

$ sudo apt install <package name of preferred LTS version>

Then, we update GRUB and reboot the system again.

2.1. When the Kernel Version Isn’t in Our apt Repositories

In some cases, our desired LTS kernel may not be available in apt by default. In such cases, we can download the .deb file for the preferred LTS kernel, and install it using dpkg -i.

Alternatively, we can add a PPA with our desired kernel to apt, and install the kernel from that PPA through apt.

2.2. When Switching From a Newer Kernel to an Older Kernel

By default, GRUB loads the newest kernel on a Linux system. So, if we’re switching from our default kernel to an older LTS kernel, running update-grub alone won’t change the default.

To switch from the default kernel to an older LTS kernel, we edit GRUB’s default configuration file. But first, let’s print its content out with cat:

$ cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'


In the configuration file, we change the value of GRUB_DEFAULT from 0 to saved:

$ cat /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'


Editing the value of the GRUB_DEFAULT to saved allows us to change the GRUB default from the command line using grub-set-default. However, we can also change the default in /etc/default/grub by modifying the value of GRUB_DEFAULT to the id of the replacement kernel.

Now that GRUB_DEFAULT has the value saved, we can switch from our default kernel to the older kernel:

$ sudo grub-set-default "1>2"

Here, 1 represents the submenu id/index of the Advanced options submenu in the GRUB main menu. Then, 2 represents the entry id of the kernel we’re switching to.

Non-default kernel entries are typically in the Advanced options submenu. So, if we’re switching to a kernel within the Advanced options submenu, we must specify the id of the kernel along with its submenu id.

For the grub-set-default command earlier, we can get a list of kernel entry IDs using grub-mkconfiggrep, and awk:

$ sudo grub-mkconfig 2> /dev/null | grep -i "menuentry '" | awk '{print i++ " : "$1, $2,
 $3, $4, $5, $6, $7}'
0 : menuentry 'Ubuntu, with Linux 6.2.0-1012-aws' --class ubuntu
1 : menuentry 'Ubuntu, with Linux 6.2.0-1012-aws (recovery mode)'
2 : menuentry 'Ubuntu, with Linux 5.15.0-1050-aws' --class ubuntu
3 : menuentry 'Ubuntu, with Linux 5.15.0-1050-aws (recovery mode)'

Given the output above, we can switch to Linux 6.2.0 in the Advanced options submenu:

$ sudo grub-set-default "1>0"

Following a similar syntax, we can also switch to Linux 5.15 in the Advanced options submenu:

$ sudo grub-set-default "1>2"

Finally, we update GRUB:

$ sudo update-grub

3. Switching to LTS Kernel on Red Hat-Based Systems

Switching to a long-term release kernel on Red Hat-Based Linux systems isn’t too different from switching on Debian-based systems. We just have to install the LTS kernel and update GRUB config.

On our CentOS installation, the default repositories didn’t come with LTS kernel packages. So, we have to install a repository that has an LTS kernel package using rpm:

$ sudo rpm -i https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

Next, we enable the installed repository using dnf:

$ sudo dnf config-manager --enable elrepo-kernel

Then, we install the LTS kernel package:

$ sudo dnf install kernel-lt

Before switching our default boot kernel to the LTS kernel, let’s confirm its entry ID from /etc/grub2.cfg using awk and grep:

$ sudo grep -i "menuentry '" /etc/grub2.cfg | awk '{print i++ " : "$1, $2, $3, $4, $5, $6, $7}'
0 : menuentry 'CentOS Linux (5.4.261-1.el7.elrepo.x86_64) 7 (Core)' --class
1 : menuentry 'CentOS Linux (3.10.0-1160.102.1.el7.x86_64) 7 (Core)' --class
2 : menuentry 'CentOS Linux (3.10.0-1160.83.1.el7.x86_64) 7 (Core)' --class
3 : menuentry 'CentOS Linux (3.10.0-1160.81.1.el7.x86_64) 7 (Core)' --class

After that, let’s set a new default kernel using grub2-set-default and the entry ID from the output of the previous command:

$ sudo grub2-set-default 0

In our CentOS’s GRUB config file, GRUB_DISABLE_SUBMENU is set to true, so there are no submenus. This is why we could specify the kernel’s menu entry ID without indicating its submenu ID.

After changing GRUB’s default boot kernel to the LTS kernel we installed, we recreate the GRUB config file:

$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Next, let’s reboot and confirm the new kernel version:

$ uname -rs
Linux 5.4.261-1.el7.elrepo.x86_64

4. Conclusion

In this article, we learned how to install an LTS kernel using the primary package managers on Debian-based and Red Hat-based Linux systems.

We also saw how to switch from one kernel version to another and how to change GRUB’s default kernel.