Install a newer kernel in CentOS 7

When using the latest version of CentOS 7, even with all updates installed, by default, you can’t get a very recent kernel via the standard repositories in your package manager. While the idea is to remain stable and rather conservative, there are several benefits with installing a newer kernel and in some cases it’s the only option to get the OS to support all your hardware. The risk and impact on stability is small and the process is rather simple.

Some of the benefits are:

  • Support for previously unsupported hardware: every kernel release has a list of added drivers. Especially when you have recent hardware, a newer kernel could be required to fully support your video card for example.
  • Performance improvements and bug fixes: newer kernels often contain a lot of bug fixes, have new functions and performance tweaks. Here again, the most is to gain on newer hardware.
  • New kernel options and security fixes

The most recent (stable) kernel that is available at the moment of writing is version 4.12, released 27/07/2017. You can find a complete overview of changes in every kernel version at https://www.kernel.org/ or http://kernelnewbies.org/LinuxVersions

The latest version of the kernel available, at the time of writing, via the standard repositories for CentOS 7 is/was:

There are basically two options to install a newer kernel in CentOS 7. The first is the easiest and this is what I will explain in this post. The second is not so easy. It is simply to compile a newer kernel yourself. While compiling a kernel nowadays isn’t rocket science anymore, the first way is still preferable and will save you a lot of time because others have been through the second method and present you the result of their work :)

Installing a newer kernel in CentOS

If you’re using CentOS as your desktop-system, you probably already heard of the EPEL (Extra Packages for Enterprise Linux)-repository which contains extra and newer ready-made packages that are by default not in RHEL, CentOS or derivatives. Next to EPEL, there is the ELRepo-repository which also contains extra packages, ready-made for RHEL, CentOS and derivatives but it focuses mainly on hardware: drivers, firmware, network, file systems,… Of course if the focus is on hardware, newer kernel versions can’t be absent here.

For more information about ELRepo: visit http://elrepo.org/tiki/About

ELRepo doesn’t provide all recent kernel versions but it still let’s you a choice between the long term support-kernel (kernel-lt) and the mainline stable kernel (kernel-ml).

To add the ELRepo-repository to your system, perform the following steps:

Start by adding the GPG-key of ELRepo:

Then, install the repository:

Now, we can browse the repository to check which is the last version and install it if we want to. To easily get more information about versions in the repository, it is handy to install yum-utils. This allows us to use the repoquery-tool.

First install yum-utils:

Now, to check which kernels are available in the repository, use repoquery -qi to get more information:

The most recent “normal” kernel from the CentOS-repository:

The long term support kernel from ELRepo:

The mainline base kernel from ELRepo:

To install a new kernel, it is sufficient to install it with yum:

After the installation, reboot your system and select the newly installed kernel from the selection in GRUB. Red Hat or CentOS do not select the new kernel by default.

To verify that the new kernel is used after booting:

When everything works as expected, you can set this newer kernel to be started by default by GRUB. This is a bit different than in CentOS 6 as GRUB2 is used:

To list the entries that exist in the grub menu (as seen in the above screenshot):

In the above list, we can see the kernels that are installed and the order of these for GRUB. We need to adjust the default to 0 if we want to set the 4.12 kernel as the default.

In order to see the currently set default, we need to get the saved_entry variable for GRUB:

To change the default kernel to item 0 from the list:

After the change:

When rebooting your system now, it should boot automatically with the new kernel.

Uninstalling unused kernels in CentOS

When everything works as expected, you can safely uninstall the older kernel in order to clean up your system and to free up some space in /boot

To check which kernels are currently installed:

Uninstall the old one:

That’s it… you can see that installing a recent kernel isn’t hard at all.

Leave a Reply

Your email address will not be published. Required fields are marked *