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:

[jensd@cen7 ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[jensd@cen7 ~]$ uname -r
3.10.0-514.26.2.el7.x86_64

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:

[jensd@cen7 ~]$ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Then, install the repository:

jensd@cen7 ~]$ sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Retrieving http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:elrepo-release-7.0-3.el7.elrepo  ################################# [100%]

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:

[jensd@cen7 ~]$ sudo yum install yum-utils -y
...
Complete!

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:

[jensd@cen7 ~]$ repoquery --enablerepo=elrepo-kernel -qi kernel
Name        : kernel
Version     : 3.10.0
Release     : 514.26.2.el7
Architecture: x86_64
Size        : 154831215
Packager    : CentOS BuildSystem <http://bugs.centos.org>
...

The long term support kernel from ELRepo:

[jensd@cen7 ~]$ repoquery --enablerepo=elrepo-kernel -qi kernel-lt
Name        : kernel-lt
Version     : 4.4.79
Release     : 1.el7.elrepo
Architecture: x86_64
Size        : 179917045
Packager    : Alan Bartlett <ajb@elrepo.org>
...

The mainline base kernel from ELRepo:

[jensd@cen7 ~]$ repoquery --enablerepo=elrepo-kernel -qi kernel-ml
Name        : kernel-ml
Version     : 4.12.4
Release     : 1.el7.elrepo
Architecture: x86_64
Size        : 196945427
Packager    : Alan Bartlett <ajb@elrepo.org>
...

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

[jensd@cen7 ~]$ sudo yum --enablerepo=elrepo-kernel install kernel-ml -y
...
Complete!

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:

[jensd@cen7 ~]$ uname -r
4.12.4-1.el7.elrepo.x86_64

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):

[jensd@cen7 ~]$ sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (4.12.4-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-514.26.2.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-b768eaafc5964bff8b60e08032c0202d) 7 (Core)

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:

jensd@cen7 ~]$ sudo grub2-editenv list
saved_entry=CentOS Linux (3.10.0-514.26.2.el7.x86_64) 7 (Core)

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

[jensd@cen7 ~]$ sudo grub2-set-default 0

After the change:

[jensd@cen7 ~]$ sudo grub2-editenv list
saved_entry=0

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:

[jensd@cen7 ~]$ rpm -qa|grep kernel|egrep -v tools
kernel-3.10.0-514.el7.x86_64
kernel-3.10.0-514.26.2.el7.x86_64
kernel-ml-4.12.4-1.el7.elrepo.x86_64

Uninstall the old one:

[jensd@cem7vm ~]$ sudo yum remove kernel-3.10.0-514.el7.x86_64 -y
...
Complete!

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

6 thoughts on “Install a newer kernel in CentOS 7

  1. i installed the latest kernel on my centos machine but i am unable to boot. it is getting stuck, printing virbr0 is disabled. any help?

  2. Thanks for the ” grub2-editenv list” sentence, I used ” grub2-editenv set entry=’CentOS Linux (4.xx.x-x.el7.elrepo.x86_64) 7 (Core)’ justo to select the proper kernel I needed.

  3. Hi, If we already installed some components on existing linux OS, will those be not recognized on new OS after new kernel installation? or same as a kernel upgrade that we don’t have to care about them?

  4. I’m getting self-reboots of Dell PowerEdge R720 servers just in the end of booting process with 5.1 kernel. On 4.x and 3.x the same machines work well. On R430 and R720xd servers 5.1 kernel run well. Does any body know what the problem is? Google has not helped much yet :(

  5. Hi,

    Can we download and install another mainline kernel instead of thos suggested with elrep ?
    Thanks

  6. It seem the RHEL stock kernel is backported with new features, so even though the kernel look old it may have features of newer kernels.
    Does the ELRepo kernels include these backported features?
    In other words, are the ELRepo kernels based on the upstream kernel or based on the RHEL stock kernel?
    If the former is the case, then one could say that the “old” RHEL stock kernel, e.g. 4.18, might actually have features from the updatream 5.6, that you’ll not get if you install ELRepo kernel 5.4?
    By the way I can only recommend kicking grub2 to hell as quickly as you can and take back control of the boot process by using systemd-boot (if that’s supported on RHEL’ish distro….been running Debian myself, but thinking of switching)

Leave a Reply to MrCal Cancel reply

Your email address will not be published.