Saturday, 13 January 2018

Automatically remove old kernels versions

Centos

sudo yum install yum-utils -y
sudo package-cleanup --oldkernels --count=2

Ubuntu

Free up space if you don't have any on your /boot partition

Find out which kernel you are running uname -r
Delete files that are not related to that kernel (e.g. rm *-79-*)
Now you have space you can run apt-get autoremove --purge
if you have any errors coming up add -f to force the command to complete 
finally, stop it happening again by editing /etc/apt/apt.conf.d/50unattended-upgrades and changing:
//Unattended-Upgrade::Remove-Unused-Dependencies "false";
to 
Unattended-Upgrade::Remove-Unused-Dependencies "true";