Skip to content

Instantly share code, notes, and snippets.

@kurtis318
Last active November 26, 2018 15:56
Show Gist options
  • Save kurtis318/c4c7b3c3a5983111d23fae6c17b2ff19 to your computer and use it in GitHub Desktop.
Save kurtis318/c4c7b3c3a5983111d23fae6c17b2ff19 to your computer and use it in GitHub Desktop.
Cleanup old kernels on Debian and/or Ubuntu
I watched one of my virtual machines perfor an apt-get dist-upgrade and I noticed abot 10 kernels being built.
This took a quite a while to complete. Here is the solution I found that I don't want to forget.
REF: https://www.tecmint.com/remove-old-kernel-in-debian-and-ubuntu/
Show kernels installed:
dpkg -l | grep linux-image | awk '{print$2}'
Install this package to do this easier:
sudo apt install byobu
Here is the magic command:
sudo purge-old-kernels --keep 3
Here is another way:
REF: https://askubuntu.com/questions/2793/how-do-i-remove-old-kernel-versions-to-clean-up-the-boot-menu
dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p'
sudo apt-get -y purge <old-kernel-image-from-above>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment