How to remove old unused kernel from CentOS/RHEL systems with yum-utils utility

To remove unused  old kernels from CentOS/RHEL systems , you can use   package-cleanup command which is the part of yum-utils package.

Firstly you install yum-utils with yum command.

root@localhost ~]# yum install yum-utils -y
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
google-chrome | 951 B 00:00:00
updates | 3.4 kB 00:00:00
Loading mirror speeds from cached hostfile
* base: centos.mirror.net.in
* extras: centos.mirror.net.in
* updates: centos.excellmedia.net
Resolving Dependencies
–> Running transaction check
—> Package yum-utils.noarch 0:1.1.31-42.el7 will be updated
—> Package yum-utils.noarch 0:1.1.31-45.el7 will be an update
–> Finished Dependency Resolution

Dependencies Resolved

============================================================================
Package                                Arch                     Version                  Repository             Size
============================================================================
Updating:
yum-utils                             noarch                  1.1.31-45.el7           base                        119 k

Transaction Summary
============================================================================
Upgrade 1 Package

Total download size: 119 k
Downloading packages:
No Presto metadata available for base
yum-utils-1.1.31-45.el7.noarch.rpm | 119 kB 00:00:05
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : yum-utils-1.1.31-45.el7.noarch 1/2
Cleanup : yum-utils-1.1.31-42.el7.noarch 2/2
Verifying : yum-utils-1.1.31-45.el7.noarch 1/2
Verifying : yum-utils-1.1.31-42.el7.noarch 2/2

Updated:
yum-utils.noarch 0:1.1.31-45.el7

Complete!
[root@localhost ~]#

Now remove all kernels except the latest currently running .

[root@localhost ~]# package-cleanup –oldkernels –count=2

Loaded plugins: fastestmirror, langpacks
–> Running transaction check
—> Package kernel.x86_64 0:3.10.0-514.10.2.el7 will be erased
—> Package kernel.x86_64 0:3.10.0-693.11.1.el7 will be erased
—> Package kernel-devel.x86_64 0:3.10.0-514.16.1.el7 will be erased
—> Package kernel-devel.x86_64 0:3.10.0-693.5.2.el7 will be erased
—> Package kernel-devel.x86_64 0:3.10.0-693.11.1.el7 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

============================================================================
Package               Arch                         Version                     Repository                Size
============================================================================
Removing:
kernel                  x86_64                3.10.0-514.10.2.el7         @updates                148 M
kernel                  x86_64                3.10.0-693.11.1.el7          @updates                  59 M
kernel-devel      x86_64                3.10.0-514.16.1.el7          @updates                  34 M
kernel-devel      x86_64                3.10.0-693.5.2.el7             @updates                  36 M
kernel-devel      x86_64                3.10.0-693.11.1.el7           @updates                  36 M

Transaction Summary
============================================================================
Remove 5 Packages

Installed size: 312 M
Is this ok [y/N]: y

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s