-1

i like to do the same thing like that:

Increase number of old kernels to keep on autoremove

but in ubuntu 22.04 i cant find "apt-auto-removal" file.

thanks nir

update: this is the content of this dir

dir content

and i have "01autoremove" file and this is what i have inside

/etc/apt/apt.conf.d$ cat 01autoremove

01autoremove file content

do you know what do i need to change?

  • Welcome to AskUbuntu. Can you edit your question with an added screenshot of the files in the directory /etc/apt/apt.conf.d? ( I use Kubuntu 20.04 and my file is called 01autoremove. ) – Joepie Es Jun 21 '22 at 13:35
  • i just add a screenshot to the question, i hope you can help me . thanks. – user1820183 Jun 22 '22 at 04:21
  • In 20.04 there is no "apt-auto-removal" file either. I personally use 'Ubuntu Mainline Kernel Installer' to uninstall old kernels. This program does not make a difference between manually and automaticly installed kernels. It works with a GUI, so it is very easy to use. After a new kernel is installed ( and after reboot works properly ) I just run the program to unistall an old kernel. You can find more info about the program and how to install it here: https://ubuntuhandbook.org/index.php/2020/08/mainline-install-latest-kernel-ubuntu-linux-mint/ . imo easier than changing a bunch of scripts. – Joepie Es Jun 22 '22 at 14:00

1 Answers1

3

To keep additional kernels I think you would have to essentially duplicate the apt-auto-removal script concept. Have a script that runs and generates an apt configuration specifying what to keep in an APT::NeverAutoRemove block. You might even be able to simply download the old apt-auto-removal script into /etc/kernel/postinst.d/ and patch it to keep the number of kernels you want, but I have not tested that.

The apt-auto-removal script was removed from the apt package recently, and the logic for protecting kernels from autoremove was added into apt itself. There were some edge cases that the script did not handle properly because it was only run when a kernel was installed. From the apt changelog.

apt (2.1.16) unstable; urgency=medium
...
  * Rewrite of the kernel autoremoval code:
    - Determine autoremovable kernels at run-time (LP: #1615381), this fixes the
      issue where apt could consider a running kernel autoremovable
    - Automatically remove unused kernels on apt {full,dist}-upgrade.
      This helps ensuring that we don't run out of /boot space.
    - Only keep up to 3 (not 4) kernels.
      Ubuntu boot partitions were sized for 3 kernels, not 4.
...
 -- Julian Andres Klode <jak@debian.org>  Fri, 08 Jan 2021 21:49:15 +0100

Based on the apt source code it looks like using the "run-time" logic apt will not autoremove

  • the booted kernel
  • the latest kernel
  • the previous kernel

I do not see any obvious way to configure the behavior to be different. These are some apt configuration options that might be useful.

APT
{
...
  NeverAutoRemove "<LIST>";  // list of package name regexes
  LastInstalledKernel "<STRING>"; // last installed kernel version
  VersionedKernelPackages "<LIST>"; // regular expressions to be protected from autoremoval (kernel uname will be appended)
  Protect-Kernels "<BOOL>"; // whether to protect installed kernels against autoremoval (default: true)

links