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.

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
  3. Hello, I tried to set grub default 0, and rebuild the grub.conf but the problem when boot it doesn’t choose the version 5 but still default check version 3. Is there any other ways to force it to 5? Thanks

    Reply
  4. The whole update process via YUM works fine, however the new Kernel did not fix the mouse bug. Does anyone else have a fix for this?

    Reply
    • @Sorin,

      I replaced them, but I think its due to caching, I cleared cache at server end, so that new images will appear properly..

      Reply
  5. After run this scripts my system doesn’t boot from the latest one i mean to say “4.20 kernel” it was booted from my last one which is “3.10 kernel”

    Reply
    • @Dima,

      If you’ve installed new Kernel using Elrepo, you can easily revert back to previous Kernel using following command.

      # yum --enablerepo=elrepo-kernel remove kernel-ml
      
      Reply
  6. Its is great that free ebooks are being offered – it certainly is good for people who want to learn more but the one thing that is so so annoying is the hundreds of fields one has to complete and actually forced to complete in order to download a book – why on earth do they need all your contact details? what do they plan on doing with it? surely once is enough? but the same details over and over again how many fields is pathetic!

    Reply
  7. Kind of works, but then “pstore: No deflate compression” halts the boot process. Anyone else had this? What pstore…?

    Reply
  8. It doesnt work, I tried it step by step without any erros, but after system reboot, my Centos 7 kde only boots with 3.10, and in advanced options, only has 3.10 kernel.

    Reply
  9. uname -r returns the correct kernel version. ‘rpm -qa kernel‘ only returns the old versions.

    The tests that I am running from AWS are picking up the old versions. Any suggestions whats going on?

    Reply
  10. I followed these instructions. After rebooting and running ‘uname -sr’ it returns: Linux 4.17.5-1.el7.elrepo.x86_64

    If I run ‘rpm -qa kernel’ it does not show the version above. It only shows the old versions.

    I am running some tests and they do not see the 4.17 kernel only the old 3.10 kernel.

    It does not seem like these instructions actually install a new kernel.

    Any suggestions?

    Reply
  11. Hi,

    I have successfully upgraded my kernel version from 3.10 to 4.14 using your instructions but the problem is now I get these errors every-time I boot my centos 7 server.

    Any idea how to fix this?.

    14:05
    wdat_wdt wdat_wdt: can’t request region for resource [mem 0x8d6c4b98-0x8d6c4b9c] kernel
    14:05
    ACPI Exception: AE_NOT_EXIST, Evaluating _PMC (20170728/power_meter-755) kernel
    14:05
    ACPI Error: Method parse/execution failed \_SB.PMI0._PMC, AE_NOT_EXIST (20170728/psparse-550) kernel
    14:05
    ACPI Error: Method parse/execution failed \_SB.PMI0._GHL, AE_NOT_EXIST (20170728/psparse-550) kernel
    14:05
    ACPI Error: Region IPMI (ID=7) has no handler (20170728/exfldio-299) kernel
    14:05
    ACPI Error: No handler for Region [SYSI] (ffff88016b161048) [IPMI] (20170728/evregion-166) kernel

    Reply
    • @Phil,

      Check in /var/log/messages for these errors, and it’s related to ACPI buffer size. The solution is to blacklist the acpi_power_meter kernel module. The driver doesn’t work due to the incorrect buffer size.

      # echo "blacklist acpi_power_meter" >> /etc/modprobe.d/hwmon.conf
      

      This is also caused by a missing kernel module, which was not supported by kernel package version 3.0.x before. After updating the Kernel, the required modules will not be loaded automatically, so you need to load it manually using the following commands:

      # modprobe ipmi_si
      # modprobe acpi_ipmi
      
      Reply
      • @Ravi

        Thank you very much for your help. the error was gone but now it got replace by this error:

        i2c i2c-0: sendbytes: NAK bailout.

        any idea how to fix that?

        Reply
  12. At first, I must say this is a wonderful tutorial! I followed those steps and then successfully upgraded my CentOS 7.4 kernel to 4.15.12.

    However, I met new issue now:

    After I run “yum update -y” , I noticed that the old kernel 3.3.10 was also updated and now it is moved to the top one position on the list of booting options on the first screen when I rebooting my server, and that option is selected by default.

    That is to say, now my server will reboot with updated kernel 3.3.10 instead of the new one 4.15.12 if I don’t do anything.

    Why the sequence of boot options will change after “yum update” ?

    How can I configure to “always boot with Kernel 4.15.12 no matter which position it is placed on the list”?

    Thank you.

    Reply
    • @Baijanpeng,

      You can change the default boot option and set the new kernel as default, just follow the Step 3: Set Default Kernel Version in GRUB in the article.

      Reply
      • I surely had done that step. My point is: the “yum update” command will CHANGE the sequence of boot options. So you don’t know which option will be selected by default after next “update” command.

        How can we configure the “grub” to ALWAYS boot with specific version of Kernel?

        Thank you.

        Reply
        • @Baijianpeng,

          Yes, once kernel update the boot sequence change automatically, so to boot into default kernel you need to configure grub as explained in the article.

          Reply
          • Did you really understand my question?

            In your article, you said: ” GRUB_DEFAULT=0. This means that the first kernel in the GRUB initial screen will be used as default.” , so, which “value” should I use to let certain kernel version will be selected by default no matter it is the first or not?

          • @Baiianpeng,

            Yeah go it, you want to set certain kernel version permanently. For this first you need to list all available kernel images added to GRUB2 by running the following command.

            $ grep '^menuentry' /boot/grub2/grub.cfg
            

            Now verify the GRUB menu entry for the kernel that you want to use. Every menu entry is allocated by GRUB2 a numeric value starting from 0 in an increasing order. That means, the first menu entry allocated 0, the second entry allocated 1, etc.

            To set different kernel version, open /etc/default/grub file and set GRUB_DEFAULT to the numeric entry value for the kernel that you want to use as default.

    • @Mario,
      If you’re on RHEL, you can always go to Red Hat for support – although it would be a pretty good idea to engage them right from the start. As for CentOS, you’re basically on your own – except for the support you may get from the community.

      Reply
  13. Hello,

    Kindly help me have situations, I have an dedicated server with CentOS 7 x64 bit. Last day I have updated the both OS and kernel ( CentOS 7 to 7.4 x64 bit.

    Situation 1: OS not booting from new kernel 3.10.0-693.5.2.e17.x86_64 (Getting black dead screen) but working fine on old kernel 3.10.0-229.e17.x86_64 .
    situation 2: I have downloaded the latest CentOS 7.4 x64 bit and tried to fresh installation on the server but this also not working (Getting black dead screen).

    Screenshot : http://prntscr.com/ha0qgo

    Reply
  14. Hi, then i have installed new kernel and reboot the server, the command “uname -sr” says me even the old kernel and on the machine i don’t find the file /etc/default/grub.

    How can i do to resolve?

    Thank you

    Reply
  15. Hi, I had upgrade from centos 7.2 to centos 7.3, but its got upgraded to centos 7.4.

    Please suggest me how i have to degrade from centos 7.4 to centos 7.3

    Thanks: satya

    Reply
    • @satya,
      I am not sure if you’re talking about upgrading the kernel or the OS here. Either way, why would you want to downgrade?

      Reply
        • @Vinay – if by RHEL7 in generic you mean any Enterprise Linux 7-like distribution, you have your answer in this post, as it demonstrates how to upgrade the kernel in CentOS 7. Otherwise, please clarify.

          Reply
          • You have mentioned, “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.”.

            How can we make up for this in RHEL7 as we won’t be able to use ELRepo according to you?

      • Also, you have mentioned, “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.”.

        How can we make up for this in RHEL7?

        Reply
  16. if /etc/default/grub = “GRUB_DEFAULT=saved” then you have to update the env file by looking at the possible menu items
    awk -F\’ ‘$1==”menuentry ” {print i++ ” : ” $2}’ /etc/grub2.cfg
    then update the default with
    grub2-set-default “option number”
    validate the update
    grub2-editenv list
    and reboot

    Reply
  17. Hi,

    Great tutorial,

    I have one question before updating my kernel, how should I pick kernel 4.4 if I choose to want that one? (4.4 is an LTS if I’m correct)

    Regards.

    Reply
    • @Ries – to be honest I wrote this article with updating to the latest kernel available in mind. But in theory, you should be perfectly fine with choosing another one. It goes without saying that you may want to test on a non-production machine first to be sure.

      Reply
  18. And now, how to update kernel headers, etc.

    I got this error

    Error: kernel-ml-headers conflicts with kernel-headers-3.10.0-514.16.1.el7.x86_64
    

    what to do?

    Reply
    • @Pajafumo

      The installed kernel-ml-headers already provides all the needed modules for building kernel, but if you really need kernel-headers, you can remove he kernel-ml-headers package forcibly with rpm:

      # rpm --nodeps -e kernel-ml-headers
      

      Then you can able to install the kernel-headers package using yum tool:

      # yum install kernel-headers
      

      You will get some error warning, but you can ignore those warnings: those dependencies will be installed again once the kernel-headers package is installed.

      Reply
  19. This is not one of the best tutorial explaining what the Kernel is and how to upgrade it.
    **THIS IS THE BEST TUTORIAL**

    Is concise.
    To the point.
    Without the boring start story.
    Commands executed without errors.
    Everything you need to GET YOUR KERNEL UPGRADED!

    Thanks a lot!

    Let’s tweet this!

    Reply
    • Chris – thank you for your kind words! We’re glad that you liked this article and were able to follow the steps successfully!

      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.