更新

更新

从我读到的所有内容来看,Ubuntu 18.04sudo apt-get autoremove应该会清理旧内核。但是,出于某种原因,在安装新内核版本后,我剩下“linux-image-*”、“linux-headers-*”和“linux-modules-*”软件包,这些软件包莫名其妙地被标记为手动安装,因此不会被清理apt-get autoremove

我没有手动安装这些软件包(例如linux-image-4.15.0-70-generic),并且不知道是什么将它们标记为手动安装。

为什么这些软件包被标记为手动安装?我该如何阻止这种情况发生?

更新

我在这里回复@user535733,因为评论太长了。我认为这与 /etc/kernel/postinst.d/apt-auto-removal 中的脚本有所不同。

查看该脚本,它不会将软件包标记为手动安装,而是编写一个 apt 配置文件,其中包含“APT::NeverAutoRemove”部分,其中列出了不应删除的内核。我明白这一点。问题是我看到的软件包被标记为手动安装不是autoremove在该列表中。即使经过多次内核更新,它们也永远不会被删除。

并标记为手动安装,我的意思是apt-mark showmanual linux-*列出这些包但apt-mark showauto linux-*没有。

更新 2

我在我的 apt 历史中发现了这一点:

Remove: linux-headers-5.0.0-32:amd64 (5.0.0-32.34~18.04.2), linux-modules-extra-5.0.0-32-generic:amd64 (5.0.0-32.34~18.04.2), linux-headers-5.0.0-32-generic:amd64 (5.0.0-32.34~18.04.2), linux-image-4.15.0-70-generic:amd64 (4.15.0-70.79), linux-modules-5.0.0-32-generic:amd64 (5.0.0-32.34~18.04.2), linux-modules-extra-4.15.0-70-generic:amd64 (4.15.0-70.79), linux-image-5.0.0-32-generic:amd64 (5.0.0-32.34~18.04.2), gradle-6.0:amd64 (1.0-0ubuntu2), linux-modules-4.15.0-70-generic:amd64 (4.15.0-70.79)
Error: Sub-process /usr/bin/dpkg returned an error code (2)

而对应的term.log内容如下:

Log started: 2019-12-21  22:23:02
dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 2 expected programs not found in PATH or not executable
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin
Log ended: 2019-12-21  22:23:02

因此,看起来 autoremove 尝试删除这些软件包但失败了。(我认为它失败是因为它处于 cron 作业中,并且 PATH 设置不正确)。不过,我仍然不明白它们是如何被标记为手动安装的。我没有在 apt 历史记录或 term.log 中看到任何其他可疑内容

答案1

该脚本/etc/kernel/postinst.d/apt-auto-removal控制哪些内核包被 apt 标记为“手动”(不符合自动删除条件),哪些被 apt 标记为“自动”(符合条件)。

这样做有一个很好的理由:保留至少一个旧内核是非常明智的,以防新内核无法启动。

这与 Debian 每次只安装一个版本的软件包的常规做法相悖。因此 apt 无法很好地处理这种特殊情况。因此需要脚本。

脚本中使用的逻辑已在脚本中描述,并且易于理解。请查看它。

答案2

为什么你不使用 ukuu,你可以在下面找到如何安装 ukuu。

sudo add-apt-repository ppa:teejee2008/ppa
sudo apt-get update && sudo apt-get install ukuu

相关内容