https://linux.cn/article-8310-1.html
While some people use Linux to mean an entire operating system, it's important to note that, strictly speaking, Linux is just a kernel. A distribution, on the other hand, is a fully functional system built on top of the kernel with a wide variety of application tools and libraries.
During normal operation, the kernel is responsible for performing two important tasks:
- Acts as the interface between the hardware and the software running on the system.
- Manage system resources as efficiently as possible.
To do this, the kernel communicates with the hardware through built-in drivers or drivers that can later be installed as modules.
For example, when a program running on your computer wants to connect to a wireless network, it submits that request to the kernel, which in turn uses the correct driver to connect to the network.
- Suggested Read: How to Upgrade the Kernel in Ubuntu
As new devices and technologies come out regularly, it is important to keep the kernel up to date if we want to take full advantage of them. Additionally, updating the kernel will help us take advantage of new kernel functions and protect ourselves from vulnerabilities found in previous versions.
Ready to update the kernel on CentOS 7 or its derivatives like RHEL 7 and Fedora? If so, keep reading!
Step 1: Check the installed kernel version
Let's install a distribution that includes a specific version of the kernel. To show the version currently installed on the system, we can:
# uname -sr
The image below shows the output on a CentOS 7 server:
Check Kernel Version on CentOS 7
If we now go to https://www.kernel.org/ , at the time of writing, we see that the latest kernel version is 4.10.1 (other versions are available from the same site).
An important thing to also consider is the lifetime of the kernel version - if the version you're currently using is nearing the end of its lifetime, no more bug fixes will be available after that date. See the Kernel Releases page for more information.
Step 2: Upgrade Kernel in CentOS 7
Most modern distributions provide a way to upgrade the kernel using package management systems such as yum and officially supported repositories.
However, this will only upgrade the kernel to the latest version available in the repositories - not the latest version available at https://www.kernel.org/ . Unfortunately, Red Hat only allows kernel upgrades using the former.
Unlike Red Hat, CentOS allows the use of ELRepo, a third-party repository that can upgrade the kernel to the latest version.
To enable the ELRepo repository on CentOS 7, run:
# 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
Enable ELRepo on CentOS 7
Once the repository is enabled, you can list the available kernel-related packages with the following command:
# yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
yum - find out available kernel versions
Next, install the latest mainline stable kernel:
# yum --enablerepo=elrepo-kernel install kernel-ml
Install Latest Kernel Version in CentOS 7
Finally, reboot the machine and apply the latest kernel, then run the following command to check the latest kernel version:
uname -sr
Verify kernel version
Step 3: Set GRUB default kernel version
To make the newly installed kernel the default boot option, you need to modify the GRUB configuration as follows:
Open and edit /etc/default/grub
and set GRUB_DEFAULT=0
. This means that the first kernel on which GRUB initializes a page will be the default kernel.
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
Setting up the kernel in GRUB
Reboot and verify that the latest kernel is the default kernel.
Boot Default Kernel Version in CentOS 7
congratulations! You have upgraded the kernel in CentOS 7!
Summarize
In this article, we explained how to easily upgrade the Linux kernel on your system. We haven't covered another method, since it involves compiling the kernel from source, which could be written in a book, and is not recommended on production systems.
While it's one of the best learning experiences and allows for fine-grained configuration of the kernel, you may leave your system unusable and may have to reinstall it from scratch.
If you're still interested in building a kernel as a learning experience, you can get guidance on the Kernel Newbies page.
As always, if you have any questions or comments about this article, please feel free to use the comment box below.