Skip to content

Instantly share code, notes, and snippets.

@bse666
Last active May 9, 2016 07:13
Show Gist options
  • Save bse666/63fa045866fa12ab9fb5cc6ab24f7deb to your computer and use it in GitHub Desktop.
Save bse666/63fa045866fa12ab9fb5cc6ab24f7deb to your computer and use it in GitHub Desktop.
Purge old kernel's on reboot
#!/bin/bash
dpkg --get-selections | `#show all installed packages` \
grep 'linux-image-*' | `#select all installed images` \
awk '{print $1}' | `#select only package name)` \
egrep -v "linux-image-$(uname -r)|linux-image-generic" | `#remove current and base kernel from list` \
head -n -2 | `#remove two recent kernels from list` \
sed 's/^linux-image-\(.*\)$/\1/' | \
while read n
do
echo 'Purging unneeded kernel images and headers for: '$n
sudo apt-get --yes purge linux-image-$n #purge images
sudo apt-get --yes purge linux-headers-$n #purge headers
done
@bse666
Copy link
Author

bse666 commented May 9, 2016

crontab: @reboot purge-old-kernels.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment