CentOS is known for not using the latest versions of the Linux kernel. If you need up-to-date versions, you need to configure the OS to use different repositories.
The turtle and the hare
Among the different linux distributions, I’ve always liked and used CentOS. It’s a great solution, it helps also to learn RedHat in case one would have to work with it, and has tons of resources available online to learn and get help. But one of the limits in CentOS has always been the lack of up-to-date kernels. This article has been written in November 2015, and while the latest stable kernel of Linux is 4.2.6:
on a completely up-to-date CentOS 7 machine, the used kernel is quite older:
[root@linux-repo ~]# uname -r 3.10.0-229.20.1.el7.x86_64
Note, I’ve not said “outdated”, if you look at the list 3.10 is there as “longterm”. It’s good for production environments to use really stable and tested versions of the kernel, but I use a lot technologies like Ceph and BTRFS, and for those to work properly it’s recommended to use the latest possible kernels, as enhancements to those software is made available as kernel is updated. For example, I was facing an issue with the rebalancing of a BTRFS partition spread among different disks, and I found a fix was made available in kernel 3.14. So, I had to find a way to have newer kernels in my CentOS machines.
Install newer kernel on CentOS
As the main repository of CentOS has no newer version of the kernel, we need first of all to use a 3rd party repository. New kernels for CentOS are available via “ELRepo”.
First, we download the GPG key of ELRepo and install the elrepo-release package.
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
Now, we enable the repository (vi /etc/yum.repos.d/elrepo.repo and set enabled to 1 for [elrepo-kernels] ); then, we need to remove the old kernel headers to avoid conflicts:
yum remove kernel-headers kernel-tools kernel-tools-libs
and finally ask yum to install the new kernel packages:
yum install kernel-ml kernel-ml-headers kernel-ml-tools kernel-ml-tools-libs kernel-ml-tools-libs-devel
Yum offers us to install the 4.3 version (as of November 2015). Now, we check how the different kernels are listed in the GRUB configuration file:
[root@linux-repo ~]# grep vmlinuz /boot/grub2/grub.cfg linux16 /vmlinuz-4.3.0-1.el7.elrepo.x86_64 root=/dev/mapper/centos_linux--demo-root ro crashkernel=auto rd.lvm.lv=centos_linux-demo/swap rd.lvm.lv=centos_linux-demo/root rhgb quiet LANG=en_US.UTF-8 systemd.debug linux16 /vmlinuz-4.3.0-1.el7.elrepo.x86_64 root=/dev/mapper/centos_linux--demo-root ro crashkernel=auto rd.lvm.lv=centos_linux-demo/swap rd.lvm.lv=centos_linux-demo/root rhgb quiet LANG=en_US.UTF-8 systemd.debug linux16 /vmlinuz-3.10.0-229.20.1.el7.x86_64 root=/dev/mapper/centos_linux--demo-root ro crashkernel=auto rd.lvm.lv=centos_linux-demo/swap rd.lvm.lv=centos_linux-demo/root rhgb quiet LANG=en_US.UTF-8 systemd.debug linux16 /vmlinuz-3.10.0-229.20.1.el7.x86_64 root=/dev/mapper/centos_linux--demo-root ro crashkernel=auto rd.lvm.lv=centos_linux-demo/swap rd.lvm.lv=centos_linux-demo/root rhgb quiet LANG=en_US.UTF-8 systemd.debug linux16 /vmlinuz-3.10.0-229.el7.x86_64 root=/dev/mapper/centos_linux--demo-root ro crashkernel=auto rd.lvm.lv=centos_linux-demo/swap rd.lvm.lv=centos_linux-demo/root rhgb quiet LANG=en_US.UTF-8 linux16 /vmlinuz-0-rescue-2612c655a4034118a6cbc12ae78334ba root=/dev/mapper/centos_linux--demo-root ro crashkernel=auto rd.lvm.lv=centos_linux-demo/swap rd.lvm.lv=centos_linux-demo/root rhgb quiet
As we want the newer 4.3 kernel to be used by default, we tell grub to do so (0 is the first entry of the list)
grub2-set-default 0 grub2-mkconfig -o /boot/grub2/grub.cfg
After a reboot, we will have our CentOS machine using the latest kernel:
[root@linux-repo ~]# uname -r 4.3.0-1.el7.elrepo.x86_64