bun*_*nny 4 apt settings kernel kubuntu
您可以在终端中使用简单的 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]
Run Code Online (Sandbox Code Playgroud)
我在一台新构建的机器上运行 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$";
};
Run Code Online (Sandbox Code Playgroud)
所以,我非常困惑,正在寻找一种方法来清理系统而不破坏任何东西,然后将保留的内核数量限制为 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
Run Code Online (Sandbox Code Playgroud)
编辑 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,感谢所有提供帮助的人!
所以,@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]
Run Code Online (Sandbox Code Playgroud)