From what I understand, apt is internally configured to only keep the current kernel plus two more (based on this answer).
However, I can see on my system that four kernels are installed:
$ dpkg -l | grep linux-image-.*-generic | grep ^ii
ii linux-image-5.15.0-82-generic 5.15.0-82.91 amd64 Signed kernel image generic
ii linux-image-5.19.0-50-generic 5.19.0-50.50 amd64 Signed kernel image generic
ii linux-image-6.2.0-26-generic 6.2.0-26.26~22.04.1 amd64 Signed kernel image generic
ii linux-image-6.2.0-31-generic 6.2.0-31.31~22.04.1 amd64 Signed kernel image generic
I think the only reason this should happen is if I've recently upgraded my kernel and haven't rebooted yet, but that doesn't seem to be the case:
$ uname -a
Linux hostname 6.2.0-31-generic #31~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Aug 16 13:45:26 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Running sudo apt autoremove
doesn't uninstall any additional kernels:
$ sudo apt autoremove --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
...
If I list all the linux-image packages, this is what I get:
$ dpkg -l | grep linux-image | grep ^ii
ii linux-image-5.15.0-82-generic 5.15.0-82.91 amd64 Signed kernel image generic
ii linux-image-5.19.0-50-generic 5.19.0-50.50 amd64 Signed kernel image generic
ii linux-image-6.2.0-26-generic 6.2.0-26.26~22.04.1 amd64 Signed kernel image generic
ii linux-image-6.2.0-31-generic 6.2.0-31.31~22.04.1 amd64 Signed kernel image generic
ii linux-image-generic 5.15.0.82.78 amd64 Generic Linux kernel image
ii linux-image-generic-hwe-22.04 6.2.0.31.31~22.04.8 amd64 Generic Linux kernel image
linux-image-generic-hwe-22.04
requires the 6.2.0-31 kernel, so I'm guessing apt is preserving that kernel as well as the two previous kernels.
And linux-image-generic
seems to require the 5.15.0-82 kernel as well, so I guess that explains why a fourth kernel is being kept?
But after removing linux-image-generic
, sudo apt autoremove
still doesn't remove the fourth kernel.