This script will remove ALL versions but two, the currently active and the most recent of the remaining installed versions:
#/bin/bash
keep=2
ls /boot/ | grep vmlinuz | sed 's@vmlinuz-@linux-image-@g' | grep -v $(uname -r) | sort -Vr | tail -n +$keep | while read I
do
aptitude purge -y $I
done
update-grub
you can specify how many kernels to keep by adjusting the keep variable, if you set it to 1, only the active kernel will be left installed.
Or you can do it in one line:
Or you can do it in one line:
ls /boot/ | grep vmlinuz | sed 's@vmlinuz-@linux-image-@g' | grep -v $(uname -r) | sort -Vr | tail -n +2 | xargs -r sudo aptitude purge -ythat you can use in crontab.
Thank you, This was very helpfull!
ReplyDeleteI discovered your page by accident, but now this is bookmarked :)
Greetings, William - System Engineer