Skip to content

Instantly share code, notes, and snippets.

@wangyingang
Last active August 29, 2015 14:23
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 wangyingang/0fe9f9c46d2f3eaf5bbf to your computer and use it in GitHub Desktop.
Save wangyingang/0fe9f9c46d2f3eaf5bbf to your computer and use it in GitHub Desktop.
Clean up useless kernels on partition /boot

do-release-upgrade fail?

May be you got a warinning message when you execute do-release-upgrade:

Not enough free disk space

The upgrade has aborted. The upgrade needs a total of xxx M free space on disk '/boot'. Please free at least an additional xxx M of disk space on '/boot'. Empty your trash and remove temporary packages of former installations using 'sudo apt-get clean'.

Because your /boot partition is filled with old kernels. You can easily remove the old kernels if you know which packages they came in.

First check your current version:

uname -a

Then run the following command:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'

This command will list all packages that you no longer need. I don't like removing them automatically, I like to be in control when it comes to removing kernels. So for every package listed do the following:

sudo apt-get -y purge some-kernel-package

Where some-kernel-package can be replaced with one of the packages listed. Just beware that you don't remove the kernel packages that are in current use (as listed by the uname -a) eg. sudo apt-get purge -y linux-headers-3.8.0-39 etc.

It can be automated further using the xargs command, here's the command to do so:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

It's done!

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