For those of you who follow my blog, you may remember that I’ve been using CentOS for a long time, but with the Linux Kernal version and CentOS version updates, my local kernel is getting a bit old, and some of the new features and software don’t work properly, so I decided to upgrade Kernal.

The main reason is that a lot of the software in the system depends on the kernel version, especially the software that you compile and install by yourself, even if it doesn’t depend on the kernel version, it has tools and other dependencies that are related to the kernel. installation. But that’s not the point. This article is to document how I upgraded my kernel, which was originally version 3.10 and older, and then prepared a one-time upgrade to the latest version 5.0, skipping the 4.x version.

Step 1: Upgrade the system software

As a routine operation, the first step is definitely to upgrade the system’s original software, because some of the subsequent steps may depend on some of the software already installed, to reduce the subsequent trouble, so you need to perform the following upgrade operation.

[]# yum -y update

Step 2: Add an elrepo source

To upgrade the kernel, you must have a source, and here I am using the elrepo source, added by following these steps.

Step 3: Install the new kernel

Now you can start installing the new kernel, for the sake of the other sources, you need to specify the source when you use it.

[]# yum --enablerepo=elrepo-kernel install kernel-ml

Once installed, you’re done.

Step 4: Set up grub2

I have installed the new kernel in step 3 and can now look at all the kernels in the system:.

[]# sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg.
0 : CentOS Linux (5.0.7-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-957.10.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-957.1.3.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-a3a5fb49fbb1460284f9555176a03f2e) 7 (Core)

I’ve set the new kernel as the default startup here, which you should not have if you follow this step to install it, so it needs to be set up with this step.

[]# sudo grub2-set-default 0
[]# sudo grub2-mkconfig -o /boot/grub2/grub.cfg
[]# sudo reboot

This first sentence followed by a number 0 is to set which kernel is the default kernel, the second sentence is to persist the configuration to the system configuration, and then the third sentence reboots the system and you’ll notice that the system will default to booting from a new kernel if you don’t intervene manually.

After booting, you can check the current kernel version.

[]# uname-msr
Linux 5.0.7-1.el7.elrepo.x86_64 x86_64

[Optional] Step 5: Remove the old kernel version

If you feel that older versions of the kernel are taking up your space, then it’s a good idea to delete them, and in a simple way.

[]# yum install yum-utils
[]# package-cleanup --oldkernels

It’s a wrap, but when I’m done upgrading and ready to compile and install the rest of the software, the problem arises that no matter what I do, the version of kernal-devel I’m compiling depends on is old.

Step 6: Upgrade kernal-devel

After upgrading the kernel, I check the version of kernal-devel.

[]# cd /usr/src/kernels/
[]# ls -l

Obviously, it doesn’t match my current system kernel version, so I have no choice but to find a way to upgrade it. First of all, I must say that yum install kernel-devel is definitely not going to work, because the default system source is still an old version, and you may need to modify several repo’s to fix this version, and you don’t know if you can fix it completely, so my way of dealing with this is rather extreme, and I just shut down all the previous repo’s first. Then added the repo from step 2.

Then you started installing the new kernel-devel.

[]# yum --enablerepo=elrepo-kernel install kernel-ml
[]# yum --enablerepo=elrepo-kernel -y swap kernel-headers -- kernel-ml-headers
[]# yum --enablerepo=elrepo-kernel -y swap kernel-tools-libs -- kernel-ml-tools-libs
[]# yum --enablerepo=elrepo-kernel -y install kernel-ml-tools
[]# yum -y remove kernel

And that’s OK, all is well, let’s play.