Unable to keep more than 2 kernels

Ubuntu Version: 25.04

Desktop Environment GNOME

Problem Description: Unable to keep more than 2 kernels
In old releases to keep more kernel limiting autoremove it was possible to change
the file /etc/kernel/postinst.d/apt-auto-removal
now this file no longer exist and i’m unable to keep more than 2 kernels.
please help

Does this method no longer work in 25.04? -

I remember that post like it was yesterday…lol
It still works, but it is huge pain in the rear. :slight_smile:
Good Luck @corradoventu

I have just read that thread, and IMO the workaround there is unnecessarily tying itself in a thousand knots to be “nice” and follow the Ubuntu Way.

What I do on my system (Pop-OS, derived from jammy): I have a “backup-kernel” script that just copies all “kernel-related” files from a particular version to names that are outside of the convention followed by the apt installed kernels. Example:

/boot/vmlinuz-6.9.3-76060903-generic

is copied to

/boot/vmlinuz-6.9.3-00000000-itz20240928-76060903-generic

(the new part encodes the date when the backup was made).

You only need to do this with precisely 5 paths:

  • vmlinuz as above
  • config
  • System.map
  • initrd.img-*
  • lib/modules/*

And then be sure the bootloader sees the backed up versions. I think this is trivial for grub, just running update-grub should work; for EFI, it took me some further scripting, but not longer than a half-page of perl code.

1 Like

Can somebidy enlighten me of the reason why they need more than two kernels, the most current version and the previously installed version that worked.

I’ve never had more than two and have never seen any reason to do so but perhaps I’m missing something potentially important here.

If i try dracut or rust i prefer to have a more kernel

When ubuntu makes its polite suggestion that I might consider an autoremove
I just politely ignore it.
So I just keep as many kernels as I want at the time.

If something else comes up that ought to be autoremoved,
i just remove it manually, never running autoremove.

While many other things in life have caused me problems, this hasn’t.

Manually installed kernels are not proposed for autoremove, so i can keep more than 2.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.