Removing old kernels with yum is a good way to keep Linux systems clean because during the update process old kernels are not automatically deleted.
After a while the system runs out of space due to old versions left in the system. Because the boot partition is normally small in size, about 200 MB, out of space issue related to the partition can heavily affects the system functionality.
To free some disk space old kernels can be safely removed from the system. To check installed kernels type the following command:
# rpm -q kernel
To remove versions no longer in use using the yum command in a “different way”, we need to install the yum-utils package.
# yum install yum-utils
Of course to delete old kernels it’s always possible to use the classic yum remove command.
yum remove kernel-xxxxxxxxxxx
# yum remove kernel-2.6.32-358.6.2.el6.x86_64
What if you are not aware of old kernels number installed in the system and you want to remove them leaving only the last two or three versions? A cool solution found in the blog If Not True Then False uses the command inside yum-utils package to achieve this goal. From the console type the following instruction:
# package-cleanup –oldkernels –count=2
Where “2” is the number of kernels to leave installed.
Typing y to confirm, all installed kernels are removed with the exception of the last two versions.
Checking once again the installed kernels, we found exactly the two packages previously specified.
This solution allows the administrators to quickly remove old kernels leaving the system clean and keeping performances and disk usage under control.