Every time you update your CentOS Linux and the update includes a new kernel image update the system will not remove your old kernel but it will cumulatively add new kernel to the top of your Linux kernel installed list. Normally, this does not present any issue to your running system and you are not required to take any action to remove any old and unused kernel images.

The reason why you may wish to remove/uninstall unused kernel images is that you need to reduce disk usage space of your system, especially if your /boot mount point is mounted separately and has a limited disk space
$ df -h /boot/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       331M  198M  112M  64% /boot
or you just simply like to reduce the number of titles on your GRUB boot list. The bellow commands will help you to remove any unused Linux kernel images from your CentOS Linux system.

Let's start by listing all installed Linux kernel images:
# rpm -q kernel
kernel-3.10.0-229.4.2.el7.x86_64
kernel-3.10.0-229.el7.x86_64
kernel-3.10.0-229.20.1.el7.x86_64
kernel-3.10.0-229.11.1.el7.x86_64
kernel-3.10.0-327.3.1.el7.x86_64
Make sure you boot into the latest installed Kernel image. In this case it is kernel-3.10.0-327.3.1.el7 kernel image. Run uname command to confirm:
$ uname -r
3.10.0-327.3.1.el7.x86_64
Next, install yum-utils package which contains package-cleanup binary to be later used to uninstall old unused Linux kernel images:
# yum install yum-utils
At this stage we are ready to remove old Linux kernels using package-cleanup command. The --oldkernels option means that we wish to remove old Kernel images, whereas the --count=1 option instructs the package-cleanup command to leave one old kernel untouched. Thus, after the execution of the below command the system will be left with one current up to date kernel and one unused kernel old kernel as a backup. Feel free to amend the count number to suit your needs:
# package-cleanup --oldkernels --count=1
The rest of old Linux kernel images should now be removed. Use rpm command to confirm:
# rpm -q kernel
kernel-3.10.0-229.20.1.el7.x86_64
kernel-3.10.0-327.3.1.el7.x86_64


Go to top