Linux kernel not auto removing old packages

October 19, 2022

Linux is keeping a lot of old packages and running out of space causing it to fail to update.

As a temporary workaround my old post linux-kernel-fails-to-update shows how to fix that the hard way.

After continually getting update failures due to the boot partition running out of space I found the reason is that some packages were marked as manually installed and thus not being removed.

Autoremove old kernels

To check if any kernels are marked as manually installed use:

apt-mark showmanual | grep linux-*

You should see only a few entries like linux-crashdump and linux-generic. If you see entries like linux-headers-5.4.... these may be the reason they are not getting removed.

To fix that simply mark them as auto. For example:

apt-mark auto linux-headers-*
apt-mark auto linux-image-*
apt-mark auto linux-modules-*
apt-mark auto linux-cloud-tools-*
apt-mark auto linux-tools-*

Then run sudo apt autoremove and it will remove all of the old packages!