Upgrading to CentOS 7.7

CentOS

CentOS 7.7 has just been released a few days ago and with any luck CentOS 8 will be released next week. I decided to quickly upgrade one of my dedicated servers from CentOS 7.6 to CentOS 7.7.

Confirm CentOS Version

Just a couple of steps to check what CentOS release we’re running:

root@s2:~ # cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

There should also be a package reflecting CentOS release already installed on your system. This package will be upgraded along with the rest of the OS when we’re stepping up to CentOS 7.7:

root@s2:~ # rpm -qa | grep centos-release
 centos-release-7-6.1810.2.el7.centos.x86_64

Check Available CentOS Upgrades

yum command has the check-update option for verifying if any packages are available for updating:

root@s2:~ # yum check-update

This will return a rather long list. To be super-sure we’ll actually get the CentOS 7.7 upgrade, look for the same centos-release package:

root@s2:~ # yum check-update | grep centos-release
 centos-release.x86_64                    7-7.1908.0.el7.centos           base

Upgrade CentOS 7.6 to CentOS 7.7

We need the yum update command here. After you run it it will resolve dependencies and report something like this, prompting for your confirmation:

Transaction Summary
===============================================================
Install    3 Packages (+25 Dependent packages)
Upgrade  406 Packages
Total download size: 577 M
Is this ok [y/d/N]:

Sounds about right! We’ll press Y and let the server download and apply all the updates…

On my hosting it took about 1min to download all the packages!

Transaction Summary
===============================================================
Install    3 Packages (+25 Dependent packages)
Upgrade  406 Packages
Total download size: 577 M
Is this ok [y/d/N]:
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Updating   : libgcc-4.8.5-39.el7.x86_64                                                                                                       1/841
 Installing : urw-base35-fonts-common-20170801-10.el7.noarch                                                                                   2/841
 Updating   : 1:grub2-common-2.02-0.80.el7.centos.noarch                                                                                       3/841
 Updating   : centos-release-7-7.1908.0.el7.centos.x86_64                                                                                      4/841
 Updating   : langtable-0.0.31-4.el7.noarch                                                                                                    5/841
 Updating   : libreport-filesystem-2.1.11-43.el7.centos.x86_64                                                                                 6/841
...
yum-plugin-fastestmirror.noarch 0:1.1.31-52.el7                           yum-utils.noarch 0:1.1.31-52.el7
 Replaced:
   urw-fonts.noarch 0:2.4-16.el7
 Complete!

It took less than 10 min to apply all the package updates, so the only things left are to capture current kernel version before and after the reboot:

root@s2:/ # uname -a
Linux s2 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Now let’s reboot:

root@s2:/ # shutdown -r now

… and confirm that we’re running newer Linux Kernel and sporting the CentOS 7.7 release now:

greys@s2:~ $ uname -a
Linux s2 3.10.0-1062.1.1.el7.x86_64 #1 SMP Fri Sep 13 22:55:44 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Hmmm. This does look a bit conservative! It’s 3.10 branch of Linux kernel whereby desktop releases are sporting Linux Kernel 5.x already.

Anyway, that’s server s2 upgraded to CentOS 7.7 successfully!

We’re certainly running the CentOS 7.7 release now:

greys@s2:~ $ cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

See Also




How To: Install Kernel Source Code in CentOS/RedHat

CentOS-linux-logo

From time to time it’s required to compile some Linux kernel specific software on your CentOS/RedHat Linux system. Most often it’s some kind of kernel module specific to a software that requires deep integration with your operating system.

Install Kernel Sources and Headers in RedHat/CentOS

You need to install two packages: kernel sources from kernel-develop and header files from kernel-headers:

root@centos:~ # yum install kernel-devel kernel-headers
Loaded plugins: fastestmirror, langpacks 
Determining fastest mirrors
epel/x86_64/metalink | 28 kB 00:00:00 
* base: centos.quelquesmots.fr
* epel: mirror.in2p3.fr 
* extras: centos.crazyfrogs.org
* updates: centos.quelquesmots.fr 
base | 3.6 kB 00:00:00 
epel | 4.7 kB 00:00:00 
extras | 3.4 kB 00:00:00 
updates | 3.4 kB 00:00:00 
(1/4): epel/x86_64/updateinfo | 998 kB 00:00:00 
(2/4): extras/7/x86_64/primary_db | 201 kB 00:00:00 
(3/4): updates/7/x86_64/primary_db | 5.0 MB 00:00:00 
(4/4): epel/x86_64/primary_db | 6.7 MB 00:00:00 
Resolving Dependencies 
--> Running transaction check 
---> Package kernel-devel.x86_64 0:3.10.0-957.12.2.el7 will be installed 
---> Package kernel-headers.x86_64 0:3.10.0-957.12.2.el7 will be installed 
--> Finished Dependency Resolution 
Dependencies Resolved 
============================================================================
Package Arch Version Repository Size 
============================================================================
Installing: 
kernel-devel x86_64 3.10.0-957.12.2.el7 updates 17 M 
kernel-headers x86_64 3.10.0-957.12.2.el7 updates 8.0 M 

Transaction Summary
============================================================================
Install 2 Packages

Total download size: 25 M
Installed size: 41 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): kernel-headers-3.10.0-957.12.2.el7.x86_64.rpm | 8.0 MB 00:00:00 
(2/2): kernel-devel-3.10.0-957.12.2.el7.x86_64.rpm | 17 MB 00:00:00 
------------------------------------------------------------------------------------------------------------------------
Total 55 MB/s | 25 MB 00:00:00 
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : kernel-devel-3.10.0-957.12.2.el7.x86_64 1/2
Installing : kernel-headers-3.10.0-957.12.2.el7.x86_64 2/2 
Verifying : kernel-headers-3.10.0-957.12.2.el7.x86_64 1/2 
Verifying : kernel-devel-3.10.0-957.12.2.el7.x86_64 2/2

Installed:
kernel-devel.x86_64 0:3.10.0-957.12.2.el7 kernel-headers.x86_64 0:3.10.0-957.12.2.el7

Complete!

I just realised that the same packages will most obviously be needed if you ever decide to compile your Linux kernel.

Why Kernel Source is Old Version in Your OS

Most Linux distros lag quite a big behing the latest Linux kernel version: this is expected, because their maintainers need time to download and complile the latest kernel and to also complete the full suite of integratory tests. This is done so that most of key software running in a particular distro will still function. Quite possibly, lots of kernel modules specific to a distro are re-compiled at that stage.

What this means is that your Linux distro will not have the latest branch of Kernel sources (5.1 as of May 2019). In this example today, my CentOS 7.6 system is using and downloading Linux Kernel 3.10.0.

Verify If You Have Kernel Sources Installed

Simply look in the /usr/src/kernels directory: you will at least have the just-installed packages but quite possibly older versions as well:

root@s2:~ # ls /usr/src/kernels/
3.10.0-957.12.2.el7.x86_64
root@s2:~ # ls /usr/src/kernels/3.10.0-957.12.2.el7.x86_64/
arch drivers include Kconfig Makefile Module.symvers scripts System.map virt
block firmware init kernel Makefile.qlock net security tools vmlinux.id
crypto fs ipc lib mm samples sound usr

That’s quite a bit of source codes:

root@s2:~ # du -sh /usr/src/kernels/3.10.0-957.12.2.el7.x86_64
74M /usr/src/kernels/3.10.0-957.12.2.el7.x86_64

See Also

 




How To: Remove Old Kernels in CentOS

CentOS-linux-logo.pngFor dedicated servers and virtual machines that you keep upgrading in-place, you will eventually reach the situation where there’s a number of old kernel packages installed. That’s because when you’re updating OS packages and get new kernel installed, the old ones are not auto-removed – allowing you to fall back if there are issues with the latest kernel.

How To List Old Kernels in CentOS/Red Hat Linux

rpm -q command comes to the resque! just run it for the kernel packages:

root@centos:~ # rpm -q kernel
kernel-3.10.0-327.28.3.el7.x86_64
kernel-3.10.0-327.36.3.el7.x86_64
kernel-3.10.0-693.21.1.el7.x86_64
kernel-3.10.0-957.5.1.el7.x86_64

You can use the uname command to verify the current kernel you’re running:

root@centos:~ # uname -a
Linux centos.ts.fm 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

How To Remove Old Linux Kernels in CentOS

There’s actually a special command for doing this, but it’s probably not installed by default. It’s part of the yum-utils package that you may have to install like this first:

root@centos:~ # yum install yum-utils

Now that it’s installed, we’ll use the package-cleanup command. It takes the number of most recent kernels that you want to keep. So if you want to keep just the currently used kernel, the number should be 1. I recommend you keep 2 kernels – current and the one before it, so the count should be 2.

Just to be super sure, the package-cleanup -oldkernels command will ask you if you’re positive about removing the listed kernel packages before progressing:

root@centos:~ # package-cleanup --oldkernels --count=2
Loaded plugins: fastestmirror, langpacks
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-327.28.3.el7 will be erased
---> Package kernel.x86_64 0:3.10.0-327.36.3.el7 will be erased
--> Finished Dependency Resolution
epel/x86_64/metalink | 22 kB 00:00:00

Dependencies Resolved

===============================================================
Package Arch Version Repository Size
=============================================================== 
Removing:
kernel x86_64 3.10.0-327.28.3.el7 @centos-updates 136 M
kernel x86_64 3.10.0-327.36.3.el7 @updates 136 M

Transaction Summary
=============================================================== 
Remove 2 Packages

Installed size: 272 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : kernel.x86_64 1/2
Erasing : kernel.x86_64 2/2
Verifying : kernel-3.10.0-327.36.3.el7.x86_64 1/2
Verifying : kernel-3.10.0-327.28.3.el7.x86_64 2/2

Removed:
kernel.x86_64 0:3.10.0-327.28.3.el7 kernel.x86_64 0:3.10.0-327.36.3.el7

Complete!

… and yes, don’t worry to be left without any Linux kernels! I checked, and specifying count=0 will not result in the package-cleanup killing your operating system:

root@centos:~ # package-cleanup --oldkernels --count=0
Loaded plugins: fastestmirror, langpacks
Error should keep at least 1 kernel!

That’s it for today. Hope you enjoyed the article!

See Also




Unix Tutorial Digest – February 4th, 2019