Remove Old Kernels on CentOS

I know how to remove old Kernels on Ubuntu. But, I don’t know how to do it on CentOS. After googling, I found answer.

Go through and see how many kernels here.

[root@juntixiao ~]# rpm -q kernel
kernel-2.6.32-573.3.1.el6.x86_64
kernel-2.6.32-573.7.1.el6.x86_64
kernel-2.6.32-573.8.1.el6.x86_64

Three kernels in machine.

Delete, remove old kernels.

This command is to used to remove old kernels and keep 2 kernels only.

[root@juntixiao ~]# package-cleanup --oldkernels --count=2
Loaded plugins: fastestmirror
--> Running transaction check
---> Package kernel.x86_64 0:2.6.32-573.3.1.el6 will be erased
---> Package kernel-devel.x86_64 0:2.6.32-573.3.1.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package            Arch         Version                   Repository      Size
================================================================================
Removing:
kernel             x86_64       2.6.32-573.3.1.el6        @updates       126 M
kernel-devel       x86_64       2.6.32-573.3.1.el6        @updates        25 M

Transaction Summary
================================================================================
Remove        2 Package(s)

Installed size: 151 M
Is this ok [y/N]: ^CExiting on user Command
Complete!
[root@juntixiao ~]# package-cleanup --oldkernels --count=2
Loaded plugins: fastestmirror
--> Running transaction check
---> Package kernel.x86_64 0:2.6.32-573.3.1.el6 will be erased
---> Package kernel-devel.x86_64 0:2.6.32-573.3.1.el6 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================================================================
Package                                            Arch                                         Version                                                  Repository                                      Size
===============================================================================================================================================================================================================
Removing:
kernel                                             x86_64                                       2.6.32-573.3.1.el6                                       @updates                                       126 M
kernel-devel                                       x86_64                                       2.6.32-573.3.1.el6                                       @updates                                        25 M

Transaction Summary
===============================================================================================================================================================================================================
Remove        2 Package(s)

Installed size: 151 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing    : kernel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                            1/2
Erasing    : kernel-devel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                      2/2
Verifying  : kernel-devel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                      1/2
Verifying  : kernel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                            2/2

Removed:
kernel.x86_64 0:2.6.32-573.3.1.el6                                                                  kernel-devel.x86_64 0:2.6.32-573.3.1.el6

Complete!{/shell]

If you can not run this command, run following to install it.
yum install yum-utils