2

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.

bmaupin
  • 5,371

1 Answers1

0

My best guess at this point is that the logic in apt for automatically removing old kernels must not take into account when an HWE version of linux-image-generic is installed alongside the normal linux-image-generic package. Maybe this is intended behaviour.

Indeed, I would prefer to keep the 5.15 kernel around just in case, but unfortunately I was hit by the Ubuntu bug where my /boot partition isn't big enough (my disk is encrypted) so I don't have enough space for four kernels, even though I have a 1 TB hard drive

As a workaround, I'm uninstalling linux-image-5.15.0-82-generic manually:

$ sudo apt purge linux-image-5.15.0-82-generic linux-modules-5.15.0-82-generic
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  linux-image-5.15.0-82-generic* linux-modules-5.15.0-82-generic*
  linux-modules-extra-5.15.0-82-generic*

And I'll keep an eye on my system to see if it ends up in this situation again later.

bmaupin
  • 5,371