为什么 apt autoremove 不立即删除所有旧的内核软件包?

Old*_*ool 4 apt linux-kernel

自从 Ubuntu 服务器发布了 Meltdown 漏洞补丁以来,我一直在升级它们的内核。我注意到几乎在所有服务器上,重新启动后我必须运行apt autoremove两次才能清理系统上仍然存在的所有旧内核。

如果我第一次运行它,它首先会删除两个旧版本的内核:

% sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-4.4.0-103 linux-headers-4.4.0-103-generic linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic linux-image-4.4.0-103-generic linux-image-4.4.0-104-generic
  linux-image-extra-4.4.0-103-generic linux-image-extra-4.4.0-104-generic
0 upgraded, 0 newly installed, 8 to remove and 2 not upgraded.
After this operation, 596 MB disk space will be freed.
Run Code Online (Sandbox Code Playgroud)

但是,完成后我apt autoremove再次运行,它会删除旧版本:

% sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-4.4.0-96 linux-headers-4.4.0-96-generic linux-image-4.4.0-96-generic linux-image-extra-4.4.0-96-generic
0 upgraded, 0 newly installed, 4 to remove and 2 not upgraded.
After this operation, 298 MB disk space will be freed.
Run Code Online (Sandbox Code Playgroud)

我想知道,为什么它不能一次性做到这一点?

Ste*_*itt 5

具体来说,kernel\xe2\x80\x99s 维护者脚本/etc/kernel/postinst.d/apt-auto-removal会构建要保留的内核列表,并将其作为 APT 配置存储在/etc/apt/apt.conf.d/01autoremove-kernels. 此过程保留当前正在运行的内核、正在配置的内核以及两个最新安装的内核。

\n\n

据推测,在第一次清理之前最后一次运行脚本时,-96最终受到保护,因为它属于这些类别之一。第一次清理后,它不再起作用,并成为删除的候选者。如果你想找出原因,该01autoremove-kernels文件包含调试信息;在第一次清理之前和之后再次查看它,应该可以揭示为什么不同的内核版本受到保护。

\n\n

内核自动删除是故意保守的并且过于谨慎。您可以使用 ; 自动(最终)处理这个问题unattended-upgrades。有关详细信息,请参阅Ubuntu wiki

\n