unused kernels

Remove all old installed but unused kernels

| |

I just noticed I had 8 kernels installed on a machine. dont need but one…. so I rebooted to make sure I was using the newest, and removed all the old ones via these simple commands :

 

Ubuntu / Debian / dpkg / Apt:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Thats a one liner, so just copy paste the whole thing.

Centos / RHEL / Yum / RPM:

uname -r

See which kernel is being used.

rpm -q kernel

get a list of installed kernels

yum install yum-utils

make sure yum-utils is installed

package-cleanup --oldkernels --count=1

Cleanup old packages, the count can be any number and it will keep that number of the latest packages. count 2 will keep the current newest and one more, 3 will keep the current newest and 2 more and so on.

nano yum.conf

edit /etc/yum.conf and look for installonly_limit and change it to any number, this was the kernels will be cleaned up automatically. I have mine set to 3.

installonly_limit=3

 

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *