Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geoffroymontel/f334185d09ecd3ed376ceb7dc57268f4 to your computer and use it in GitHub Desktop.
Save geoffroymontel/f334185d09ecd3ed376ceb7dc57268f4 to your computer and use it in GitHub Desktop.
Remove all old Ubuntu kernels from a VPS
dpkg --list linux-{headers,image,modules,tools}-\* | awk '{ if ($1=="ii") print $2}' | grep -v -e "$(uname -r | cut -d"-" -f1,2)" | xargs sudo dpkg --remove # use dpkg to remove all but the currently running kernel version
sudo apt-get install -f # It's common for apt to be in a broken state after running out of space on /boot
sudo apt-get autoremove # It's really common for apt to be broken on a package that should have been removed
sudo apt-get install -y linux-generic linux-headers-generic linux-image-generic linux-tools-generic # just in case latest kernel was mysteriously removed (e.g. when you are not running the latest kernel)
sudo update-grub # just in case it was not done automatically by dpkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment