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% /bootor 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_64Make 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_64Next, install
yum-utils
package which contains package-cleanup
binary to be later used to uninstall old unused Linux kernel images: # yum install yum-utilsAt 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=1The 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