How to Install or Upgrade to Kernel 5.0 in CentOS 7

Although some people use the word Linux to represent the operating system as a whole, it is important to note that, strictly speaking, Linux is only the kernel. On the other hand, a distribution is a fully-functional system built on top of the kernel with a wide variety of application tools and libraries.

During normal operations, the kernel is responsible for performing two important tasks:

  1. Acting as an interface between the hardware and the software running on the system.
  2. Managing system resources as efficiently as possible.

To do this, the kernel communicates with the hardware through the drivers that are built into it or those that can be later installed as a module.

For example, when an application running on your machine wants to connect to a wireless network, it submits that request to the kernel, which in turns uses the right driver to connect to the network.

Suggested Read: How to Upgrade Kernel in Ubuntu

With new devices and technology coming out periodically, it is important to keep our kernel up to date if we want to make the most of out them. Additionally, updating our kernel will help us to leverage new kernel functions and to protect ourselves from vulnerabilities that have been discovered in previous versions.

Ready to update your kernel on CentOS 7 or one of their derivatives such as RHEL 7 and Fedora? If so, keep reading!

Step 1: Checking Installed Kernel Version

When we install a distribution it includes a certain version of the Linux kernel. To show the current version installed on our system we can do:

# uname -sr

The following image shows the output of the above command in a CentOS 7 server:

Check Kernel Version in CentOS 7
Check Kernel Version in CentOS 7

If we now go to https://www.kernel.org/, we will see that the latest kernel version is 5.0 at the time of this writing (other versions are available from the same site).

This new Kernel 5.0 version is a long-term release and will be supported for 6 years, earlier all Linux Kernel versions were supported for 2 years only.

One important thing to consider is the life cycle of a kernel version – if the version you are currently using is approaching its end of life, no more bug fixes will be provided after that date. For more info, refer to the kernel Releases page.

Step 2: Upgrading Kernel in CentOS 7

Most modern distributions provide a way to upgrade the kernel using a package management system such as yum and an officially-supported repository.

Important: If you looking to run custom compiled Kernel, then you should read our article that explains How to Compile Linux Kernel on CentOS 7 from sources.

However, this will only perform the upgrade to the most recent version available from the distribution’s repositories – not the latest one available in the https://www.kernel.org/. Unfortunately, Red Hat only allows to upgrade the kernel using the former option.

As opposed to Red Hat, CentOS allows the use of ELRepo, a third-party repository that makes the upgrade to a recent version a kernel.

To enable the ELRepo repository on CentOS 7, do:

# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm 
Enable ELRepo in CentOS 7
Enable ELRepo in CentOS 7

Once the repository has been enabled, you can use the following command to list the available kernel.related packages:

# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Yum – Find Available Kernel Versions
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * elrepo-kernel: mirror-hk.koddos.net
Available Packages
kernel-lt.x86_64                        4.4.176-1.el7.elrepo        elrepo-kernel
kernel-lt-devel.x86_64                  4.4.176-1.el7.elrepo        elrepo-kernel
kernel-lt-doc.noarch                    4.4.176-1.el7.elrepo        elrepo-kernel
kernel-lt-headers.x86_64                4.4.176-1.el7.elrepo        elrepo-kernel
kernel-lt-tools.x86_64                  4.4.176-1.el7.elrepo        elrepo-kernel
kernel-lt-tools-libs.x86_64             4.4.176-1.el7.elrepo        elrepo-kernel
kernel-lt-tools-libs-devel.x86_64       4.4.176-1.el7.elrepo        elrepo-kernel
kernel-ml.x86_64                        5.0.0-1.el7.elrepo          elrepo-kernel
kernel-ml-devel.x86_64                  5.0.0-1.el7.elrepo          elrepo-kernel
kernel-ml-doc.noarch                    5.0.0-1.el7.elrepo          elrepo-kernel
kernel-ml-headers.x86_64                5.0.0-1.el7.elrepo          elrepo-kernel
kernel-ml-tools.x86_64                  5.0.0-1.el7.elrepo          elrepo-kernel
kernel-ml-tools-libs.x86_64             5.0.0-1.el7.elrepo          elrepo-kernel
kernel-ml-tools-libs-devel.x86_64       5.0.0-1.el7.elrepo          elrepo-kernel
perf.x86_64                             5.0.0-1.el7.elrepo          elrepo-kernel
python-perf.x86_64                      5.0.0-1.el7.elrepo          elrepo-kernel

Next, install the latest mainline stable kernel:

# yum --enablerepo=elrepo-kernel install kernel-ml
Install Kernel 5.0 in CentOS 7
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.mirror.net.in
 * elrepo: mirror-hk.koddos.net
 * elrepo-kernel: mirror-hk.koddos.net
 * epel: repos.del.extreme-ix.org
 * extras: centos.mirror.net.in
 * updates: centos.mirror.net.in
Resolving Dependencies
--> Running transaction check
---> Package kernel-ml.x86_64 0:5.0.0-1.el7.elrepo will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================
 Package                Arch        Version                 Repository        Size
====================================================================================
Installing:
 kernel-ml              x86_64      5.0.0-1.el7.elrepo      elrepo-kernel     47 M

Transaction Summary
====================================================================================
Install  1 Package

Total download size: 47 M
Installed size: 215 M
Is this ok [y/d/N]: y
Downloading packages:
kernel-ml-5.0.0-1.el7.elrepo.x86_64.rpm                           |  47 MB  00:01:21     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : kernel-ml-5.0.0-1.el7.elrepo.x86_64                1/1 
  Verifying  : kernel-ml-5.0.0-1.el7.elrepo.x86_64                1/1 

Installed:
  kernel-ml.x86_64 0:5.0.0-1.el7.elrepo                                                                                                                                                                            

Complete!

Finally, reboot your machine to apply the latest kernel, and then select latest kernel from the menu as shown.

Select Latest Kernel Version
Select Latest Kernel Version

Login as root, and run following command to check the kernel version:

# uname -sr
Verify Kernel Version
Verify Kernel Version

Step 3: Set Default Kernel Version in GRUB

To make the newly-installed version the default boot option, you will have to modify the GRUB configuration as follows:

Open and edit the file /etc/default/grub and set GRUB_DEFAULT=0. This means that the first kernel in the GRUB initial screen will be used as default.

GRUB_TIMEOUT=5
GRUB_DEFAULT=0
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=centos/root rd.lvm.lv=centos/swap crashkernel=auto rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

Next, run the following command to recreate the kernel configuration.

# grub2-mkconfig -o /boot/grub2/grub.cfg
Set Default Kernel Version in Grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.0.0-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-5.0.0-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.20.0-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.20.0-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.19.11-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.19.11-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-4.19.0-1.el7.elrepo.x86_64
Found initrd image: /boot/initramfs-4.19.0-1.el7.elrepo.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.1.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.1.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1e2b46dbc0c04b05b592c837c366bb76
Found initrd image: /boot/initramfs-0-rescue-1e2b46dbc0c04b05b592c837c366bb76.img
done

Reboot and verify that the latest kernel is now being used by default.

Booting Default Kernel Version in CentOS 7
Booting Default Kernel Version in CentOS 7

Congratulations! You have upgraded your kernel in CentOS 7!

Summary

In this article we have explained how to easily upgrade the Linux kernel on your system. There is yet another method which we haven’t covered as it involves compiling the kernel from source, which would deserve an entire book and is not recommended on production systems.

Although it represents one of the best learning experiences and allows for a fine-grained configuration of the kernel, you may render your system unusable and may have to reinstall it from scratch.

If you are still interested in building the kernel as a learning experience, you will find instructions on how to do it at the Kernel Newbies page.

As always, feel free to use the form below if you have any questions or comments about this article.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

66 thoughts on “How to Install or Upgrade to Kernel 5.0 in CentOS 7”

  1. After performing the above steps at the reboot stage got:

    grub issue on centos7 (3 to 5 kernel). Request you to please upload proper content.

    grub>

    Reply
  2. After installing the kernel on CentOS 7, I got below output at the end, so the kernel is installed or not?

    Error! echo
    Your kernel headers for kernel 5.6.4-1.el7.elrepo.x86_64 cannot be found at
    /lib/modules/5.6.4-1.el7.elrepo.x86_64/build or /lib/modules/5.6.4-1.el7.elrepo.x86_64/source.
    Verifying : kernel-ml-5.6.4-1.el7.elrepo.x86_64 1/1

    Installed:
    kernel-ml.x86_64 0:5.6.4-1.el7.elrepo

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.