Distro-provided mechanism to clean up old kernels

Dustin Kirkland kirkland at ubuntu.com
Tue May 1 00:33:33 UTC 2012


FYI, I have committed a version of a script and a manpage,
purge-old-kernels, to lp:bikeshed:
 * http://bazaar.launchpad.net/~bikeshed/bikeshed/trunk/view/head:/purge-old-kernels
 * http://bazaar.launchpad.net/~bikeshed/bikeshed/trunk/view/head:/purge-old-kernels.1

It's based on the logic that Kees posted here.  However, it will also:
  - always keep your currently running kernel
    + to remove your current current, reboot into a newer one, and
then re-run the script
  - default to saving your 2 newest kernels
    + but that can be easily overridden at run time with --keep N
  - passes through any other parameters to apt-get
    + defaults to interactive prompt by apt-get, override with -y

For example:
 $ sudo purge-old-kernels --keep 3 -qy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-3.2.0-23-generic linux-headers-3.2.0-21
linux-headers-3.2.0-22 linux-headers-3.2.0-23 libcrypto++9
linux-headers-3.2.0-21-generic libnekohtml-java
  linux-headers-3.2.0-22-generic
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  linux-image-2.6.38-10-generic* linux-image-3.0.0-10-generic*
linux-image-3.0.0-11-generic* linux-image-3.0.0-16-generic*
linux-image-3.0.0-7-generic* linux-image-3.0.0-8-generic*
  linux-image-3.0.0-9-generic* linux-image-3.2.0-17-generic*
linux-image-3.2.0-18-generic* linux-image-3.2.0-19-generic*
linux-image-3.2.0-20-generic* linux-image-3.2.0-21-generic*
0 upgraded, 0 newly installed, 12 to remove and 0 not upgraded.
After this operation, 1,801 MB disk space will be freed.
...
 $ sudo apt-get autoremove -y
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  libcrypto++9 libnekohtml-java linux-headers-3.2.0-21
linux-headers-3.2.0-21-generic linux-headers-3.2.0-22
linux-headers-3.2.0-22-generic linux-headers-3.2.0-23
  linux-headers-3.2.0-23-generic
0 upgraded, 0 newly installed, 8 to remove and 0 not upgraded.
After this operation, 207 MB disk space will be freed.

This cleaned out 2GB of old kernels and headers on my system.

If we can decide on an appropriate package where this can land, I'm
happy to clean it up and push it there.  Otherwise, it can ship in
bikeshed or in its own standalone package.  Note, I'd *love* to SRU
this to older supported Ubuntu's, once this lands in Quantal.

Cheers!
:-Dustin



More information about the ubuntu-devel mailing list