익명 17:49

Increase the number of old kernels to keep on autoremove in Ubuntu 22.04

Increase the number of old kernels to keep on autoremove in Ubuntu 22.04

I'd like to do the same thing like that:

Increase number of old kernels to keep on autoremove

but in Ubuntu 22.04 I can't find the apt-auto-removal file.

Update:

These are the contents of this directory.

00aptitude        15update-stamp      20packagekit          60icons
00trustcdrm       20apt-esm-hook.conf 20snapd.conf          60icons-hidpi
01autoremove      20archive           50appstream           70debconf
01-vendor-ubuntu  20auto-upgrades     50command-not-found   99update-notifier
10periodic        20dbus              50unattended-upgrades

and I have an "01autoremove" file, and this is what I have inside:

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

APT
{
  NeverAutoRemove
  {
    "^firmware-linux.*";
    "^linux-firmware$";
    "^linux-image-[a-z0-9]*$";
    "^linux-image-[a-z0-9]*-[a-z0-9]*$";
  };

  VersionedKernelPackages
  {
    # kernels
    "linux-.*";
    "kfreebsd-.*";
    "gnumach-.*";
    # (out-of-tree) modules
    ".*-modules";
    ".*-kernel";
  };

  Never-MarkAuto-Sections
  {
    "metapackages";
    "contrib/metapackages";
    "non-free/metapackages";
    "restricted/metapackages";
    "universe/metapackages";
    "multiverse/metapackages";
  };

  Move-Autobit-Sections
  {
    "oldlibs";
    "contrib/oldlibs";
    "non-free/oldlibs";
    "restricted/oldlibs";
    "universe/oldlibs";
    "multiverse/oldlibs";
  };
};

Do you know what I need to change?



Top Answer/Comment:

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 <[email protected]>  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

상단 광고의 [X] 버튼을 누르면 내용이 보입니다