为什么 apt-get autoremove 无法删除我的旧内核?

为什么 apt-get autoremove 无法删除我的旧内核?

根据Ubuntu 帮助维基:

您可以在终端中使用简单的 autoremove 命令删除旧内核:

sudo apt-get autoremove --purge

由于某种原因,这对我来说不起作用,并且内核正在堆积起来:

 apt list --installed | rg linux-image

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

linux-image-5.4.0-31-generic/focal-updates,focal-security,now 5.4.0-31.35 amd64 [installed]
linux-image-5.4.0-40-generic/focal-updates,focal-security,now 5.4.0-40.44 amd64 [installed]
linux-image-5.4.0-42-generic/focal-updates,focal-security,now 5.4.0-42.46 amd64 [installed]
linux-image-5.4.0-45-generic/focal-updates,focal-security,now 5.4.0-45.49 amd64 [installed]
linux-image-5.4.0-47-generic/focal-updates,focal-security,now 5.4.0-47.51 amd64 [installed]
linux-image-5.4.0-48-generic/focal-updates,focal-security,now 5.4.0-48.52 amd64 [installed]
linux-image-5.4.0-52-generic/focal-updates,focal-security,now 5.4.0-52.57 amd64 [installed]
linux-image-5.4.0-54-generic/focal-updates,now 5.4.0-54.60 amd64 [installed]
linux-image-5.4.0-56-generic/now 5.4.0-56.62 amd64 [installed,local]
linux-image-5.4.0-58-generic/focal-updates,focal-security,now 5.4.0-58.64 amd64 [installed]
linux-image-5.4.0-60-generic/focal-updates,focal-security,now 5.4.0-60.67 amd64 [installed]
linux-image-5.4.0-62-generic/focal-updates,focal-security,now 5.4.0-62.70 amd64 [installed]
linux-image-5.4.0-64-generic/focal-updates,now 5.4.0-64.72 amd64 [installed]
linux-image-5.4.0-65-generic/focal-updates,focal-security,now 5.4.0-65.73 amd64 [installed]
linux-image-5.4.0-66-generic/focal-updates,focal-security,now 5.4.0-66.74 amd64 [installed,automatic]
linux-image-generic/now 5.4.0.66.69 amd64 [installed,upgradable to: 5.4.0.67.70]

我在一台新机器上运行着 Kubuntu 20.04.2,在用了 Mac 多年之后,我才用了几个月,所以我从来没有有意识地尝试调整内核的任何内容。

unattended-upgrades通过 Discover 商店禁用了它,因为静默 Nvidia 更新导致显示屏冻结。不过,sudo apt-get autoremove每次更新后我都会运行它。

我在发帖之前寻找了答案,发现大多数答案都是很多年前的,尽管先前这个问题导致我检查了我的/etc/apt/apt.conf.d/01autoremove-kernels文件,它似乎正确地只关注最新的两个内核:

// DO NOT EDIT! File autogenerated by /etc/kernel/postinst.d/apt-auto-removal
APT::NeverAutoRemove
{
   "^linux-.*-5\.4\.0-65-generic$";
   "^linux-.*-5\.4\.0-66-generic$";
   "^kfreebsd-.*-5\.4\.0-65-generic$";
   "^kfreebsd-.*-5\.4\.0-66-generic$";
   "^gnumach-.*-5\.4\.0-65-generic$";
   "^gnumach-.*-5\.4\.0-66-generic$";
   "^.*-modules-5\.4\.0-65-generic$";
   "^.*-modules-5\.4\.0-66-generic$";
   "^.*-kernel-5\.4\.0-65-generic$";
   "^.*-kernel-5\.4\.0-66-generic$";
};

所以,我非常困惑,正在寻找一种在不破坏任何东西的情况下清理系统的方法,然后将保留的内核数量限制为 2-3。

感谢您的阅读,我将非常感激您提供的任何帮助!

编辑:根据@user535733 的请求,这里有一些额外的输出:

sudo apt update
Hit:1 http://us.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu focal-updates InRelease                                                                                              
Hit:3 http://security.ubuntu.com/ubuntu focal-security InRelease                                                                      
Hit:4 http://us.archive.ubuntu.com/ubuntu focal-backports InRelease                                                                   
Ign:5 https://apt.fury.io/flirc  InRelease                                                
Hit:6 http://ppa.launchpad.net/appimagelauncher-team/stable/ubuntu focal InRelease
Hit:7 http://download.opensuse.org/repositories/home:/ungoogled_chromium/Ubuntu_Focal  InRelease
Ign:8 https://apt.fury.io/flirc  Release                                                       
Ign:9 https://apt.fury.io/flirc  Packages                                
Ign:10 https://apt.fury.io/flirc  Translation-en                         
Hit:11 http://ppa.launchpad.net/jonaski/strawberry/ubuntu focal InRelease
Ign:12 https://apt.fury.io/flirc  Translation-en_US                      
Get:9 https://apt.fury.io/flirc  Packages                                
Ign:10 https://apt.fury.io/flirc  Translation-en                         
Hit:13 http://ppa.launchpad.net/micahflee/ppa/ubuntu focal InRelease
Ign:12 https://apt.fury.io/flirc  Translation-en_US                      
Ign:10 https://apt.fury.io/flirc  Translation-en                         
Ign:12 https://apt.fury.io/flirc  Translation-en_US                      
Hit:14 http://ppa.launchpad.net/mkusb/ppa/ubuntu focal InRelease
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Ign:10 https://apt.fury.io/flirc  Translation-en
Ign:12 https://apt.fury.io/flirc  Translation-en_US
Fetched 6,518 B in 2s (3,153 B/s)
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.

sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

uname -r
5.4.0-67-generic

编辑 2:在更新以包含附加输出后,添加了另一个内核(linux-image-5.4.0-67-generic)。我注意到linux-image-5.4.0-66-generic和都linux-image-5.4.0-67-generic标记为自动,而所有以前的版本都标记为手动。根据这个时间,我猜测通过 Discover 商店中的“全部更新”按钮进行更新不知何故导致内核被标记为手动安装(连同标题和模块)。看起来只有两个通过 cli 安装的内核被正确标记为自动安装(但由于它们是两个最新版本,因此没有受到自动删除的影响)。

我猜答案是使用apt-mark auto通过 Discover 商店安装的版本,并从这里坚持使用 cli,感谢所有帮助过的人!

答案1

因此,@nobody 建议使用apt-mark showmanual,这对我来说是新的。

由于这是我第一次使用 Linux,所以在最初的几个月里我一直使用 Kubuntu 的 Discover Store 来更新所有内容。

看起来通过 Kubuntu 的 Discover 商店中的“全部更新”按钮安装的所有内核以及相关模块和标头都被标记为手动安装。

幸运的是,命令行更新正确地将新内核、标头和模块标记为自动安装。

使用来自 的错误标记包列表apt-mark showmanual | grep linux-,我能够轻松地更正所有 65 个包的状态sudo apt-mark auto $(cat path/to/listofpackages.txt),这要归功于建议发布在这里

现在sudo apt-get autoremove正在检测这些包,从现在起我一定会坚持使用 CLI 更新!再次感谢所有帮助过我的人!

sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-5.4.0-40 linux-headers-5.4.0-40-generic linux-headers-5.4.0-42 linux-headers-5.4.0-42-generic linux-headers-5.4.0-45
  linux-headers-5.4.0-45-generic linux-headers-5.4.0-47 linux-headers-5.4.0-47-generic linux-headers-5.4.0-48 linux-headers-5.4.0-48-generic
  linux-headers-5.4.0-52 linux-headers-5.4.0-52-generic linux-headers-5.4.0-54 linux-headers-5.4.0-54-generic linux-headers-5.4.0-56
  linux-headers-5.4.0-56-generic linux-headers-5.4.0-58 linux-headers-5.4.0-58-generic linux-headers-5.4.0-60 linux-headers-5.4.0-60-generic
  linux-headers-5.4.0-62 linux-headers-5.4.0-62-generic linux-headers-5.4.0-64 linux-headers-5.4.0-64-generic linux-headers-5.4.0-65
  linux-headers-5.4.0-65-generic linux-image-5.4.0-40-generic linux-image-5.4.0-42-generic linux-image-5.4.0-45-generic linux-image-5.4.0-47-generic
  linux-image-5.4.0-48-generic linux-image-5.4.0-52-generic linux-image-5.4.0-54-generic linux-image-5.4.0-56-generic linux-image-5.4.0-58-generic
  linux-image-5.4.0-60-generic linux-image-5.4.0-62-generic linux-image-5.4.0-64-generic linux-image-5.4.0-65-generic linux-modules-5.4.0-40-generic
  linux-modules-5.4.0-42-generic linux-modules-5.4.0-45-generic linux-modules-5.4.0-47-generic linux-modules-5.4.0-48-generic linux-modules-5.4.0-52-generic
  linux-modules-5.4.0-54-generic linux-modules-5.4.0-56-generic linux-modules-5.4.0-58-generic linux-modules-5.4.0-60-generic linux-modules-5.4.0-62-generic
  linux-modules-5.4.0-64-generic linux-modules-5.4.0-65-generic linux-modules-extra-5.4.0-40-generic linux-modules-extra-5.4.0-42-generic
  linux-modules-extra-5.4.0-45-generic linux-modules-extra-5.4.0-47-generic linux-modules-extra-5.4.0-48-generic linux-modules-extra-5.4.0-52-generic
  linux-modules-extra-5.4.0-54-generic linux-modules-extra-5.4.0-56-generic linux-modules-extra-5.4.0-58-generic linux-modules-extra-5.4.0-60-generic
  linux-modules-extra-5.4.0-62-generic linux-modules-extra-5.4.0-64-generic linux-modules-extra-5.4.0-65-generic
0 upgraded, 0 newly installed, 65 to remove and 0 not upgraded.
After this operation, 4,682 MB disk space will be freed.
Do you want to continue? [Y/n] 

相关内容