Skip to content

Instantly share code, notes, and snippets.

@vzaliva
Created April 1, 2017 07:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vzaliva/bee68ed709ddd2724791a56714eca5f6 to your computer and use it in GitHub Desktop.
Save vzaliva/bee68ed709ddd2724791a56714eca5f6 to your computer and use it in GitHub Desktop.
Script to free space on /boot partition by removing old kernels
#!/bin/bash
kernelver=$(uname -r | sed -r 's/-[a-z]+//')
unused=`dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver`
echo "Your current kernel is version is $kernelver"
if [ -z "$unused" ]; then
echo "No old kernels to remove."
exit 0
fi
echo "The following packages could be removed:"
echo
for p in $unused
do
echo " $p"
done
echo
read -p "Proceed [y/N]? " -n 1 -r REPLY
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Removing"
sudo apt-get purge $unused
exit 0
fi
echo "Not removing"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment