How to remove old Kernel form RHEL or CentOS 6-8 in proper manner.
Updated: Oct 3, 2021
The kernel is the core of a computer's operating system with complete control over everything in the system. If anything wrong with kernel then it may very difficult for you to recover the operating system. Hence i will discuss here the proper way to remove the old kernel.
Remove old kernel from RHEL or CentOS 6-7
Check current version of your kernel
# uname -r
3.10.0-1127.18.2.el7.x86_64
Check how many kernel are installed into your OS
# rpm -qa|grep kernel-[0-9]
kernel-3.10.0-1127.18.2.el7.x86_64
kernel-3.10.0-1062.12.1.el7.x86_64
Remove old kernel from RHEl/CentOS 6-7
package-cleanup --oldkernels --count=1
Loaded plugins: fastestmirror
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-1062.12.1.el7 will be erased
---> Package kernel-devel.x86_64 0:3.10.0-1062.12.1.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================
Package Arch Version Repository Size
======================================================================
Removing:
kernel x86_64 3.10.0-1062.12.1.el7 @updates 64 M
kernel-devel x86_64 3.10.0-1062.12.1.el7 @updates 38 M
Transaction Summary
======================================================================
Remove 2 Packages
Installed size: 102 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : kernel-devel-3.10.0-1062.12.1.el7.x86_64 1/2
Erasing : kernel-3.10.0-1062.12.1.el7.x86_64 2/2
Verifying : kernel-3.10.0-1062.12.1.el7.x86_64 1/2
Verifying : kernel-devel-3.10.0-1062.12.1.el7.x86_64 2/2
Removed:
kernel.x86_64 0:3.10.0-1062.12.1.el7 kernel-devel.x86_64 0:3.10.0-1062.12.1.el7
Complete!
Check the final active kernel version
# rpm -qa|grep kernel-[0-9]
kernel-3.10.0-1127.18.2.el7.x86_64
Remove old kernel from RHEL or CentOS 8
Check current version of kernel
# uname -r
4.18.0-193.6.3.el8_2.x86_64
Check how many kernel are installed into your OS
# rpm -qa|grep kernel-[0-9]
kernel-4.18.0-80.11.2.el8_0.x86_64
kernel-4.18.0-193.6.3.el8_2.x86_64
kernel-4.18.0-147.5.1.el8_1.x86_64
Remove old kernel from RHEl or CentOS 8
# dnf remove --oldinstallonly --setopt installonly_limit=2
Updating Subscription Management repositories.
Dependencies resolved.
================================================================================================
Package Architecture Version Repository Size
================================================================================================
Removing:
kernel x86_64 4.18.0-80.11.2.el8_0 @RHEL8-Base-OS-RHN 0
kernel x86_64 4.18.0-147.5.1.el8_1 @ITCL_RHEL-8_RHEL-8-Baseos 0
kernel-core x86_64 4.18.0-80.11.2.el8_0 @RHEL8-Base-OS-RHN 57 M
kernel-core x86_64 4.18.0-147.5.1.el8_1 @ITCL_RHEL-8_RHEL-8-Baseos 58 M
kernel-modules x86_64 4.18.0-80.11.2.el8_0 @RHEL8-Base-OS-RHN 19 M
kernel-modules x86_64 4.18.0-147.5.1.el8_1 @ITCL_RHEL-8_RHEL-8-Baseos 20 M
Transaction Summary
================================================================================================
Remove 6 Packages
Freed space: 154 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Erasing : kernel-4.18.0-147.5.1.el8_1.x86_64 1/6
Running scriptlet: kernel-4.18.0-147.5.1.el8_1.x86_64 1/6
Erasing : kernel-4.18.0-80.11.2.el8_0.x86_64 2/6
Running scriptlet: kernel-4.18.0-80.11.2.el8_0.x86_64 2/6
Erasing : kernel-modules-4.18.0-80.11.2.el8_0.x86_64 3/6
Running scriptlet: kernel-modules-4.18.0-80.11.2.el8_0.x86_64 3/6
Erasing : kernel-modules-4.18.0-147.5.1.el8_1.x86_64 4/6
Running scriptlet: kernel-modules-4.18.0-147.5.1.el8_1.x86_64 4/6
Running scriptlet: kernel-core-4.18.0-147.5.1.el8_1.x86_64 5/6
Erasing : kernel-core-4.18.0-147.5.1.el8_1.x86_64 5/6
Running scriptlet: kernel-core-4.18.0-147.5.1.el8_1.x86_64 5/6
Running scriptlet: kernel-core-4.18.0-80.11.2.el8_0.x86_64 6/6
Erasing : kernel-core-4.18.0-80.11.2.el8_0.x86_64 6/6
Running scriptlet: kernel-core-4.18.0-80.11.2.el8_0.x86_64 6/6
Verifying : kernel-4.18.0-80.11.2.el8_0.x86_64 1/6
Verifying : kernel-4.18.0-147.5.1.el8_1.x86_64 2/6
Verifying : kernel-core-4.18.0-80.11.2.el8_0.x86_64 3/6
Verifying : kernel-core-4.18.0-147.5.1.el8_1.x86_64 4/6
Verifying : kernel-modules-4.18.0-80.11.2.el8_0.x86_64 5/6
Verifying : kernel-modules-4.18.0-147.5.1.el8_1.x86_64 6/6
Installed products updated.
Last metadata expiration check: 0:00:03 ago on Wed 19 Aug 2020 11:08:24 AM +06.
Uploading Tracer Profile
Removed:
kernel-4.18.0-80.11.2.el8_0.x86_64 kernel-4.18.0-147.5.1.el8_1.x86_64 kernel-core-4.18.0-80.11.2.el8_0.x86_64
kernel-core-4.18.0-147.5.1.el8_1.x86_64 kernel-modules-4.18.0-80.11.2.el8_0.x86_64 kernel-modules-4.18.0-147.5.1.el8_1.x86_64
Complete!
Check the final active kernel version
# rpm -qa|grep kernel-[0-9]
kernel-4.18.0-193.6.3.el8_2.x86_64
That's it.
Hope this will help.
Comments