根据Ubuntu帮助维基:的说法:
您可以在终端中使用简单的autoremove命令删除旧内核:
sudo apt-get autoremove --purge 由于某种原因,这对我不起作用,内核正在堆积。
所以,我超级困惑,正在寻找一种在不破坏任何东西的情况下清理系统的方法,然后将保留的内核数量限制在2-3个。
谢谢您的阅读,我会非常感激您能提供的任何帮助!
编辑:根据@user535733的要求,这里有一些额外的输出:
编辑2:在更新以包括额外输出后,又添加了一个内核(linux-image-5.4.0-67-generic)。我注意到,linux-image-5.4.0-66-generic和linux-image-5.4.0-67-generic都被标记为自动安装,而所有之前的版本都被标记为手动安装。根据时间推断,我猜测通过Discover商店中的“全部更新”按钮进行更新似乎导致内核被标记为手动安装(连同头文件和模块一起)。看起来只有通过命令行安装的两个版本被正确标记为自动安装(但由于它们是最新版本,所以没有被自动删除)。
我想答案是对通过Discover商店安装的版本使用apt-mark auto命令,并从此处开始使用命令行。感谢所有帮助过我的人!
您可以在终端中使用简单的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,所以我从未有意识地尝试过调整内核的任何内容。
我通过Discover商店禁用了unattended-upgrades
,因为静默的Nvidia更新导致显示器冻结。不过,每次更新后我会运行sudo apt-get autoremove
。
在发布问题之前,我寻找了答案,并发现大多数答案都是很多年前的,尽管this previous question的一个答案让我检查了我的/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商店中的“全部更新”按钮进行更新似乎导致内核被标记为手动安装(连同头文件和模块一起)。看起来只有通过命令行安装的两个版本被正确标记为自动安装(但由于它们是最新版本,所以没有被自动删除)。
我想答案是对通过Discover商店安装的版本使用apt-mark auto命令,并从此处开始使用命令行。感谢所有帮助过我的人!
sudo apt update
和sudo apt upgrade
和sudo apt autoremove
和uname -r
的输出。 - user535733