Teach you three steps to install or upgrade the latest kernel in CentOS 7

While some people use  Linux  to refer to the entire operating system, it's important to note that Linux is, strictly speaking, 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:

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

To do this, the kernel communicates with the hardware through built-in drivers or drivers that can be installed later 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.

With new devices and technologies coming out on a regular basis, it's important to keep the kernel up to date if we want to take full advantage of them. Also, 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, read on!

Step 1: Check the installed kernel version

Let's install a distribution that includes a specific version of the kernel. To display the installed versions on the current 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 website).

An important thing to also consider is the lifecycle of kernel versions - if the version you're currently using is nearing its end of life, no more bug fixes will be delivered 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 a package management system such as yum and officially supported repositories.

However, this will only upgrade the kernel to the latest version available in the repository - not the latest version available in 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 upgrades the kernel to the latest version.

To enable 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 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

In order 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 from the GRUB initialization page will be used as 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 command below to recreate the kernel configuration.

# grub2-mkconfig -o /boot/grub2/grub.cfg

Set up the kernel in GRUB

Reboot and verify that the latest kernel is available as the default.

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. There's another method we haven't covered yet because it involves compiling the kernel from source, which could fill a book and is not recommended for production systems.

While it's one of the best learning experiences, and allows for fine-grained configuration of the kernel, you may render 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, feel free to use the comment box below if you have any questions or comments about this article.


About the Author:

I'm a computer addict and fan of open source and Linux system software, with about 4 years of experience with Linux distribution desktops, servers and bash  scripting .

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/131360505