apt --purge autoremove 找不到旧内核

apt --purge autoremove 找不到旧内核

我在使用 Ubuntu 20.04,我试图了解我的 Linux 内核发生了什么,但有些东西对我来说看起来很奇怪。当前内核应该是:

@precision-3551:~$ uname -r
5.13.0-44-generic

但我还可以看到还有其他已安装的内核。有一点很奇怪,安装的内核要么是,5.13要么是5.4,中间没有任何东西:

@precision-3551:~$ dpkg --list | egrep -i --color 'linux-image|linux-headers'
ii  linux-headers-5.0.0-1034-oem-osp1          5.0.0-1034.39                       amd64        Linux kernel headers for version 5.0.0 on 64 bit x86 SMP
ii  linux-headers-5.13.0-41-generic            5.13.0-41.46~20.04.1                amd64        Linux kernel headers for version 5.13.0 on 64 bit x86 SMP
ii  linux-headers-5.13.0-44-generic            5.13.0-44.49~20.04.1                amd64        Linux kernel headers for version 5.13.0 on 64 bit x86 SMP
ii  linux-headers-5.4.0-113                    5.4.0-113.127                       all          Header files related to Linux kernel version 5.4.0
ii  linux-headers-5.4.0-113-generic            5.4.0-113.127                       amd64        Linux kernel headers for version 5.4.0 on 64 bit x86 SMP
ii  linux-headers-generic                      5.4.0.113.117                       amd64        Generic Linux kernel headers
ii  linux-headers-generic-hwe-20.04            5.13.0.44.49~20.04.28               amd64        Generic Linux kernel headers
rc  linux-image-5.0.0-1034-oem-osp1            5.0.0-1034.39                       amd64        Signed kernel image oem-osp1
ii  linux-image-5.13.0-41-generic              5.13.0-41.46~20.04.1                amd64        Signed kernel image generic
ii  linux-image-5.13.0-44-generic              5.13.0-44.49~20.04.1                amd64        Signed kernel image generic
rc  linux-image-5.4.0-100-generic              5.4.0-100.113                       amd64        Signed kernel image generic
rc  linux-image-5.4.0-104-generic              5.4.0-104.118                       amd64        Signed kernel image generic
rc  linux-image-5.4.0-105-generic              5.4.0-105.119                       amd64        Signed kernel image generic
rc  linux-image-5.4.0-107-generic              5.4.0-107.121                       amd64        Signed kernel image generic
rc  linux-image-5.4.0-109-generic              5.4.0-109.123                       amd64        Signed kernel image generic
rc  linux-image-5.4.0-110-generic              5.4.0-110.124                       amd64        Signed kernel image generic
ii  linux-image-5.4.0-113-generic              5.4.0-113.127                       amd64        Signed kernel image generic
rc  linux-image-5.4.0-65-generic               5.4.0-65.73~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-66-generic               5.4.0-66.74~18.04.2                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-70-generic               5.4.0-70.78~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-71-generic               5.4.0-71.79~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-72-generic               5.4.0-72.80~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-73-generic               5.4.0-73.82~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-74-generic               5.4.0-74.83~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-77-generic               5.4.0-77.86~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-80-generic               5.4.0-80.90~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-81-generic               5.4.0-81.91~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-84-generic               5.4.0-84.94~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-86-generic               5.4.0-86.97~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-87-generic               5.4.0-87.98~18.04.1                 amd64        Signed kernel image generic
rc  linux-image-5.4.0-89-generic               5.4.0-89.100~18.04.1                amd64        Signed kernel image generic
rc  linux-image-5.4.0-90-generic               5.4.0-90.101                        amd64        Signed kernel image generic
rc  linux-image-5.4.0-91-generic               5.4.0-91.102                        amd64        Signed kernel image generic
rc  linux-image-5.4.0-92-generic               5.4.0-92.103                        amd64        Signed kernel image generic
rc  linux-image-5.4.0-94-generic               5.4.0-94.106                        amd64        Signed kernel image generic
rc  linux-image-5.4.0-96-generic               5.4.0-96.109                        amd64        Signed kernel image generic
rc  linux-image-5.4.0-97-generic               5.4.0-97.110                        amd64        Signed kernel image generic
rc  linux-image-5.4.0-99-generic               5.4.0-99.112                        amd64        Signed kernel image generic
ii  linux-image-generic                        5.4.0.113.117                       amd64        Generic Linux kernel image
ii  linux-image-generic-hwe-20.04              5.13.0.44.49~20.04.28               amd64        Generic Linux kernel image
ii  linux-image-oem-osp1                       5.4.0.113.117                       amd64        Depends on the generic kernel image (dummy transitional package)
@precision-3551:~$ dpkg --list | grep -i -E --color 'linux-image|linux-kernel' | grep '^ii'
ii  linux-image-5.13.0-41-generic              5.13.0-41.46~20.04.1                amd64        Signed kernel image generic
ii  linux-image-5.13.0-44-generic              5.13.0-44.49~20.04.1                amd64        Signed kernel image generic
ii  linux-image-5.4.0-113-generic              5.4.0-113.127                       amd64        Signed kernel image generic
ii  linux-image-generic                        5.4.0.113.117                       amd64        Generic Linux kernel image
ii  linux-image-generic-hwe-20.04              5.13.0.44.49~20.04.28               amd64        Generic Linux kernel image
ii  linux-image-oem-osp1 

当我尝试清除时,没有得到任何列出的内容:

@precision-3551:~$ sudo apt --purge autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

我也调查过/etc/apt/apt.conf.d/01autoremove-kernels,正如这个答案,但在我的例子中该文件不存在。我认为通过删除内核5.4可以节省一些空间。我该怎么做,或者有什么迹象表明我不应该这样做?

答案1

让我们花一点时间简单地重新组织一下这个列表。现在可能更有意义了:

// OEM Kernel packages
ii  linux-image-oem-osp1                       5.4.0.113.117                       amd64        Depends on the generic kernel image (dummy transitional package)
ii  linux-headers-5.0.0-1034-oem-osp1          5.0.0-1034.39                       amd64        Linux kernel headers for version 5.0.0 on 64 bit x86 SMP
rc  linux-image-5.0.0-1034-oem-osp1            5.0.0-1034.39                       amd64        Signed kernel image oem-osp1

// Original 20.04 kernel 5.4 packages
ii  linux-image-generic                        5.4.0.113.117                       amd64        Generic Linux kernel image
ii  linux-image-5.4.0-113-generic              5.4.0-113.127                       amd64        Signed kernel image generic
ii  linux-headers-generic                      5.4.0.113.117                       amd64        Generic Linux kernel headers
ii  linux-headers-5.4.0-113                    5.4.0-113.127                       all          Header files related to Linux kernel version 5.4.0
ii  linux-headers-5.4.0-113-generic            5.4.0-113.127                       amd64        Linux kernel headers for version 5.4.0 on 64 bit x86 SMP

// Hardware Enablement (HWE) 20.04 kernel 5.13 packages
ii  linux-image-generic-hwe-20.04              5.13.0.44.49~20.04.28               amd64        Generic Linux kernel image
ii  linux-image-5.13.0-41-generic              5.13.0-41.46~20.04.1                amd64        Signed kernel image generic
ii  linux-image-5.13.0-44-generic              5.13.0-44.49~20.04.1                amd64        Signed kernel image generic
ii  linux-headers-generic-hwe-20.04            5.13.0.44.49~20.04.28               amd64        Generic Linux kernel headers
ii  linux-headers-5.13.0-41-generic            5.13.0-41.46~20.04.1                amd64        Linux kernel headers for version 5.13.0 on 64 bit x86 SMP
ii  linux-headers-5.13.0-44-generic            5.13.0-44.49~20.04.1                amd64        Linux kernel headers for version 5.13.0 on 64 bit x86 SMP
  • rc内核未安装,不占用空间。这些只是 apt 数据库中 apt 过去知道的内核条目。我们忽略其中的大部分。

  • 您有一个 OEM 内核元包和标头。OEM 内核在有限的时间内适用于特定硬件,直到该硬件的硬件支持进入主线内核。如果您的硬件在当前的 5.13 内核上运行良好,那么您不再需要那些 5.0 和 5.4 OEM 内核包。只需 apt remove them: sudo apt remove linux-image-oem-osp1 linux-headers-5.0.0-1034-oem-osp1。看到了吗?这很容易。

  • 您拥有 Ubuntu 20.04 附带的原始 5.4 内核堆栈。但您没有使用它(您使用的是 HWE 5.13 系列)。除非您打算恢复到 5.4,否则您可以简单地删除这五个软件包。

  • 您当前的 5.13 内核有两个版本,-44 和较旧的 -41。这才是正确的样子(您确实应该有两个)。不要删除任何这些软件包。让 apt 自动处理这个系列。

  • apt 似乎没有问题。它确实会自动删除旧内核——这就是为什么你rc列出了这么多内核。你安装了这么多内核,因为你——人类管理员——没有指示 apt 卸载那些 OEM 和 5.4 元包,并且这些元包所做的就是引入额外的内核!

答案2

您的内核状态为“rc”,但某些配置可能仍然存在。如果您想清除配置,可以执行sudo dpkg --purge <name of package>,例如sudo dpkg --purge linux-image-5.4.0-86-generic

相关内容