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<br />
kernel-2.6.32-573.3.1.el6.x86_64<br />
kernel-2.6.32-573.7.1.el6.x86_64<br />
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<br />
Loaded plugins: fastestmirror<br />
--&gt; Running transaction check<br />
---&gt; Package kernel.x86_64 0:2.6.32-573.3.1.el6 will be erased<br />
---&gt; Package kernel-devel.x86_64 0:2.6.32-573.3.1.el6 will be erased<br />
--&gt; Finished Dependency Resolution</p>
<p>Dependencies Resolved</p>
<p>================================================================================<br />
Package            Arch         Version                   Repository      Size<br />
================================================================================<br />
Removing:<br />
kernel             x86_64       2.6.32-573.3.1.el6        @updates       126 M<br />
kernel-devel       x86_64       2.6.32-573.3.1.el6        @updates        25 M</p>
<p>Transaction Summary<br />
================================================================================<br />
Remove        2 Package(s)</p>
<p>Installed size: 151 M<br />
Is this ok [y/N]: ^CExiting on user Command<br />
Complete!<br />
[root@juntixiao ~]# package-cleanup --oldkernels --count=2<br />
Loaded plugins: fastestmirror<br />
--&gt; Running transaction check<br />
---&gt; Package kernel.x86_64 0:2.6.32-573.3.1.el6 will be erased<br />
---&gt; Package kernel-devel.x86_64 0:2.6.32-573.3.1.el6 will be erased<br />
--&gt; Finished Dependency Resolution</p>
<p>Dependencies Resolved</p>
<p>===============================================================================================================================================================================================================<br />
Package                                            Arch                                         Version                                                  Repository                                      Size<br />
===============================================================================================================================================================================================================<br />
Removing:<br />
kernel                                             x86_64                                       2.6.32-573.3.1.el6                                       @updates                                       126 M<br />
kernel-devel                                       x86_64                                       2.6.32-573.3.1.el6                                       @updates                                        25 M</p>
<p>Transaction Summary<br />
===============================================================================================================================================================================================================<br />
Remove        2 Package(s)</p>
<p>Installed size: 151 M<br />
Is this ok [y/N]: y<br />
Downloading Packages:<br />
Running rpm_check_debug<br />
Running Transaction Test<br />
Transaction Test Succeeded<br />
Running Transaction<br />
Erasing    : kernel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                            1/2<br />
Erasing    : kernel-devel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                      2/2<br />
Verifying  : kernel-devel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                      1/2<br />
Verifying  : kernel-2.6.32-573.3.1.el6.x86_64                                                                                                                                                            2/2</p>
<p>Removed:<br />
kernel.x86_64 0:2.6.32-573.3.1.el6                                                                  kernel-devel.x86_64 0:2.6.32-573.3.1.el6</p>
<p>Complete!{/shell]</p>
<p>If you can not run this command, run following to install it.<br />
yum install yum-utils