Skip to content

Instantly share code, notes, and snippets.

@hsleewis
Created December 24, 2012 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hsleewis/1901557fd4790013f586 to your computer and use it in GitHub Desktop.
Save hsleewis/1901557fd4790013f586 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo 'You are currently running: '`uname -r`
echo 'The following kernel images exist in /boot:'
ls /boot|grep vmlinuz|cut -d'-' -f2,3
nKerns=`ls /boot|grep vmlinuz|wc -l`
if [ $nKerns -gt 1 ]
then
# Ok to remove the oldest ONE
oKern=`ls /boot|grep vmlinuz|cut -d'-' -f2,3|head -1`
echo "The oldest kernel: $oKern will be removed."
echo "Do you want to continue?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Proceed";break;;
No ) exit;;
esac
done
rempkgs=`dpkg -l|grep ^ii|grep $oKern|awk -F' ' '{print $2}'`
echo 'You will now require the SUDO (root) password to complete:'
sudo aptitude remove $rempkgs
echo 'Kernel cleanup completed.'
else
# Prevent the user from self-nuking!
echo '*** WARNING ***'
echo 'This is the ONLY kernel and you must keep it!'
echo 'Without a kernel you have no Linux system!'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment