首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么要自动移除我的旧内核?

为什么要自动移除我的旧内核?
EN

Ask Ubuntu用户
提问于 2021-03-22 19:17:48
回答 1查看 5K关注 0票数 4

根据Ubuntu帮助wiki:

您可以在终端中使用一个简单的自动删除命令删除旧内核:sudo apt-get autoremove --purge

由于某些原因,这对我不起作用,而且内核也在堆积:

代码语言:javascript
复制
 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]

我正在一台新构建的机器上运行Kubuntu20.04.2,在使用了多年的Mac之后,我只使用了几个月,所以我从未有意识地尝试过调整内核的任何内容。

我通过Discover禁用了unattended-upgrades,因为无声的Nvidia更新导致显示冻结。但是,我确实在每次更新之后运行sudo apt-get autoremove

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

代码语言:javascript
复制
// 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个。

谢谢你的阅读,我很感谢你能提供的任何帮助!

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

代码语言:javascript
复制
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-genericlinux-image-5.4.0-67-generic都被标记为自动,而以前的所有版本都被标记为手动。基于这个时间,我猜想通过Discover中的“update all”按钮进行更新会导致内核被标记为手动安装(以及标头和模块)。看起来,通过cli安装的唯一两个被正确地标记为自动安装(但没有被自动删除,因为它们是两个最新版本)。

我想答案是在通过Discover安装的版本上使用apt-mark auto,并在这里坚持使用cli,谢谢大家的帮助!

EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2021-03-23 23:08:17

因此,“没有人建议使用apt-mark showmanual,这对我来说是新的。”

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

看起来,通过Kubuntu的Discover中的“update all”按钮安装的所有内核,以及相关的模块和头,都被标记为手动安装。

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

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

现在,sudo apt-get autoremove正在检测这些包,从现在起,我将继续使用cli更新!再次感谢大家的帮助!

代码语言:javascript
复制
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] 
票数 8
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1325387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档