Comment 140 for bug 798414

Revision history for this message
Jarno Suni (jarnos) wrote : Re: update-initramfs should produce a more helpful error when there isn't enough free space

"a more helpful error" that the title of this bug report calls for would not free you from the need to remove kernels manually.

I made a script called linux-purge to make it easy to remove extra kernels even in tricky conditions: https://www.bountysource.com/issues/38300038-feature-request-the-command-should-work-like-this (It is designed to handle dependency problems and even problem running out of inodes - that may occur when installing a kernel - when using --fix option.)

As for preventing system from getting full of kernels automatically, unattended-upgrades provides an adequate solution for most cases. You can configure it in Ubuntu 16.04 like this:
Add line

Unattended-Upgrade::Remove-Unused-Dependencies "true";

in /etc/apt/apt.conf.d/50unattended-upgrades

(since unattended-upgrades is enabled by default in 16.04; the configuration acts as if running "apt-get autoremove" periodically.)

The default setting in 16.04 is

Unattended-Upgrade::Remove-New-Unused-Dependencies "true";

but that does not work in some cases (Bug #1624644); the former setting overrides it.

Alternatively, putting "linux-purge --yes --keep 1" as a cron job or alike could do automatic kernel purging, (if no other process has locked dpkg at the time of calling it).
It has some differences to the unattended-upgrades way:
- It works in 12.04 and 14.04, too. (unattended-upgrades cannot remove manually installed kernels that will be around, if user installs kernel using e.g. update-manager; Bug #1439769.)
- The number of kernels to keep is configurable. It keeps the given number of nearest older kernels of each installed kernel update series, e.g. linux-generic and linux-generic-lts-xenial, not necessarily the installed kernels with greatest versions. (You could use --auto-only to keep
manually installed kernels, too, but you probably would not want to use it in 12.04 and 14.04.)
- Current kernel will never be removed. (Bug #1615381)
- It removes configuration files, too. (i.e. it purges)
- It only removes versioned kernel packages whose name start by linux-.