如何从Ubuntu 18.04上从引导中删除旧内核版本
Canonical为Ubuntu 18提供定期更新.04系统,包括内核更新,以尽可能地管理系统的资源。
本文将为我们提供一些不同的方法来从Ubuntu 18的启动菜单中删除旧内核。
04.当我们安装一个新内核时,旧的内核不会删除,因为它可以启动,如果我们对此错误进行错误新的一个或者其他原因。
请注意,旧内核消耗了一些对别的东西有用的空间。
我们有时需要更新内核以获取兼容性,因为它负责接地所有应用程序。
检查旧内核
为了避免使用Ubuntu 18的当前启动内核的任何错误。
04系统,确保检查其版本
# uname -r 4.15.0-23-generic
在尝试删除旧内核之前,我们必须先检查系统中是否存在旧内核。
为此,我们可以在系统启动时查看GRUB
我们可以选择"Ubuntu的高级选项"。
我们可以在列表顶部看到当前内核,旧内核仅为以下4. 15.13.
通用
还有另一种方法来检查命令行中的旧内核。
这将列出旧内核而不是当前的内核
# dpkg -l | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) ii linux-image-4.15.0-13-generic 4.15.0-13.14 amd64 Linux kernel image for version 4.15.0 on 64 bit x86 SMP
我们可以看到我们有效地安装了标有II的旧内核。
如果我们已经完成了一些升级或者手动安装,我们可以看到更多旧内核。
检查内核时存在一些状态
- II:表示安装内核/包装并有资格删除。
- RC:表示内核已被删除。
- IU:像警告一样的东西告诉不要删除。这意味着未安装但排队以便安装在APT中。
确保在做任何事情之前查看状态。
现在我们已经找到了一些内核,现在让我们看看不同的方法来删除每个或者整个。
1)在命令行中删除旧内核
无论我们是否通过系统更新,都有一些有用的命令删除旧内核。
通常,我们通过常规系统更新安装,但由于某种原因,我们可以决定进行手动安装。
a)apt命令
APT命令有助于卸载包含在Ubuntu 18中不需要的旧内核的软件包。
04系统。
我们可以检查自动安装的那些如下所示
# apt-mark showauto 'linux-image-.*' linux-image-4.15.0-13-generic linux-image-4.15.0-23-generic linux-image-extra-4.15.0-13-generic linux-image-generic
我们可以检查那些手动安装的人如下
# apt-mark showmanual 'linux-image-.*'
如我们所见,我们没有手动安装内核。
我们可以使用以下删除参数删除所有旧内核:
# apt remove linux-image-4.15.0-13-generic Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: linux-image-4.15.0-13-generic* linux-image-extra-4.15.0-13-generic .... .... you Jan need to re-run your boot loader[grub]
删除内核时,请确保更新GRUB以查看是否在生成GRUB时发生任何错误
# update-grub Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.15.0-23-generic Found initrd image: /boot/initrd.img-4.15.0-23-generic Found memtest86+ image: /boot/memtest86+.elf Found memtest86+ image: /boot/memtest86+.bin done
现在,如果已删除,我们可以再次检查
# dpkg -l | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) rc linux-image-4.15.0-13-generic 4.15.0-13.14 amd64 Linux kernel image for version 4.15.0 on 64 bit x86 SMP
我们可以看到状态RC,显示它已被删除。
我们还可以在引导菜单上检查,并查看当前引导内核显示
我们还可以使用"APT自动侵入"命令,但我们应该注意到该命令用于删除自动安装的包,以满足其他包的依赖项,不再需要依赖性。
所以检查是否没有我们需要在要删除的包列表中存在的包
# apt autoremove --purge
b)dpkg命令
我们还可以使用DPKG命令在Ubuntu 18上删除特定内核.04系统。
这次我们需要指示包和另外的依赖项
# dpkg --purge linux-image-4.15.0-13-generic linux-image-extra-4.15.0-13-generic (Reading database ... 165680 files and directories currently installed.) ... ... Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.15.0-23-generic Found initrd image: /boot/initrd.img-4.15.0-23-generic Found memtest86+ image: /boot/memtest86+.elf Found memtest86+ image: /boot/memtest86+.bin done ...
我们可以再次检查迹线,但我们会看到完全删除的是,因为我们没有输出显示它已被删除(RC)
# dpkg -l | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)
你也可以看grub
c)使用脚本
我们在GitHub上找到了一个有趣的互动脚本,可以删除旧内核。
它使用dpkg命令,但有趣的是它列出了内核以删除并询问意见。
首先安装git
# apt install git
现在克隆这个项目
# git clone https://github.com/kivisade/kernel-purge.git Cloning into 'kernel-purge'... remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3 Unpacking objects: 100% (3/3), done.
输入文件夹并提供权限
# cd kernel-purge && chmod +x kernel-purge.sh
现在运行脚本
# ./kernel-purge.sh Running kernel version is: 4.15.0-23 The following (unused) KERNEL packages will be removed: linux-headers-4.15.0-13 linux-headers-4.15.0-13-generic linux-image-4.15.0-13-generic linux-image-extra-4.15.0-13-generic Do you want to continue [yN]? y Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: linux-headers-4.15.0-13* linux-headers-4.15.0-13-generic* linux-image-4.15.0-13-generic* linux-image-extra-4.15.0-13-generic* 0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded. After this operation, 335 MB disk space will be freed. (Reading database ... 168812 files and directories currently installed.) ... ... Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.15.0-23-generic Found initrd image: /boot/initrd.img-4.15.0-23-generic Found memtest86+ image: /boot/memtest86+.elf Found memtest86+ image: /boot/memtest86+.bin done ... ...
现在,我们可以检查内核是否已得到有效删除。
我们将不会有一个输出所以旧内核已被删除
# dpkg -l | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r)
2)使用图形工具删除旧内核
我们还可以使用图形工具卸载内核包。
该工具将在此过程中询问密码,因为我们需要进行管理权限。
a)Ubuntu Cleaner
Ubuntu Cleaner是一款用户友好的系统实用程序,旨在清洁浏览器缓存,删除不需要的应用程序,并获取旧内核的镜头。
如果我们想删除,Ubuntu会有所帮助:
- 应用程序缓存包括大多数主要浏览器
- apt缓存
- 老核
- 不需要的软件包
官方存储库中默认情况下不存在包,因此我们需要添加PPA。
请记住,在Ubuntu 18上。
04添加PPA后,我们无需更新包缓存,因为它自动启动。
所以添加ppa如下
~# add-apt-repository ppa:gerardpuig/ppa Official Ubuntu Cleaner stable repository More info: https://launchpad.net/~gerardpuig/+archive/ubuntu/ppa Press [ENTER] to continue or Ctrl-c to cancel adding it. Hit:1 http://cm.archive.ubuntu.com/ubuntu bionic InRelease Get:2 http://cm.archive.ubuntu.com/ubuntu bionic-updates InRelease [83.2 kB] Get:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB] Get:4 http://cm.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB] Get:5 http://security.ubuntu.com/ubuntu bionic-security/main amd64 DEP-11 Metadata [204 B] ... ...
现在,我们可以安装该工具
# apt install ubuntu-cleaner Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: libpython-stdlib python python-apt python-aptdaemon ... ...
然后启动软件
然后选择旧内核部分,然后选择核删除
我们将被要求输入密码,并将开始此过程
现在,我们可以检查内核是否仍然存在。
我们可以看到表示它已删除的状态
# dpkg -l | grep -E 'linux-image-[0-9]+' | grep -Fv $(uname -r) rc linux-image-4.15.0-13-generic 4.15.0-13.14 amd64 Linux kernel image for version 4.15.0 on 64 bit x86 SMP
b)synaptic
Synaptic是由Debian基础系统使用的高级包装工具(APT)的图形界面,以处理包装/软件的安装。
它不是一个用户友好的工具,因此可以非常令人困惑,这就是为什么你必须非常小心。
# apt install synaptic Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: docbook-xml libept1.5.0 libgtk2-perl libpango-perl librarian0 rarian-compat sgml-base sgml-data xml-core
现在启动申请
现在移动到部分 - >内核和模块,选择核心以删除和标记以完成删除。
确保在列表中选择正确的内核
它会问你的确认
我们可以看到它会自动标记依赖项。
申请删除内核
它会要求确认。
申请
我们可以看到显示该过程的窗口。
如果你仔细看,你将在最后看到GRUB已经生成并且旧内核没有礼物。