无法清除旧内核

无法清除旧内核

我有 ubuntu 20.04。我一直遇到 /boot 文件夹空间不足的问题。

$ sudo apt list --installed | grep linux-image

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

linux-image-5.11.0-38-generic/focal-updates,focal-security,now 5.11.0-38.42~20.04.1 amd64 [installed]
linux-image-5.11.0-40-generic/focal-updates,focal-security,now 5.11.0-40.44~20.04.2 amd64 [installed,automatic]
linux-image-5.11.0-41-generic/focal-updates,focal-security,now 5.11.0-41.45~20.04.1 amd64 [installed,automatic]
linux-image-5.11.0-43-generic/focal-updates,focal-security,now 5.11.0-43.47~20.04.2 amd64 [installed,automatic]
linux-image-5.11.0-44-generic/focal-updates,focal-security,now 5.11.0-44.48~20.04.2 amd64 [installed,automatic]
linux-image-5.11.0-46-generic/focal-updates,focal-security,now 5.11.0-46.51~20.04.1 amd64 [installed]
linux-image-5.13.0-25-generic/focal-updates,focal-security,now 5.13.0-25.26~20.04.1 amd64 [installed]
linux-image-5.13.0-27-generic/focal-updates,focal-security,now 5.13.0-27.29~20.04.1 amd64 [installed]
linux-image-5.13.0-28-generic/focal-updates,focal-security,now 5.13.0-28.31~20.04.1 amd64 [installed]
linux-image-5.13.0-30-generic/focal-updates,focal-security,now 5.13.0-30.33~20.04.1 amd64 [installed]
linux-image-5.13.0-35-generic/focal-updates,focal-security,now 5.13.0-35.40~20.04.1 amd64 [installed,automatic]
linux-image-5.13.0-37-generic/focal-updates,focal-security,now 5.13.0-37.42~20.04.1 amd64 [installed,automatic]
linux-image-5.13.0-48-generic/focal-updates,focal-security,now 5.13.0-48.54~20.04.1 amd64 [installed,automatic]
linux-image-5.13.0-51-generic/focal-updates,focal-security,now 5.13.0-51.58~20.04.1 amd64 [installed]
linux-image-5.13.0-52-generic/focal-updates,focal-security,now 5.13.0-52.59~20.04.1 amd64 [installed]
linux-image-5.15.0-41-generic/focal-updates,focal-security,now 5.15.0-41.44~20.04.1 amd64 [installed]
linux-image-5.15.0-43-generic/focal-updates,focal-security,now 5.15.0-43.46~20.04.1 amd64 [installed]
linux-image-5.15.0-46-generic/focal-updates,focal-security,now 5.15.0-46.49~20.04.1 amd64 [installed]
linux-image-5.15.0-48-generic/focal-updates,focal-security,now 5.15.0-48.54~20.04.1 amd64 [installed]
linux-image-5.15.0-50-generic/focal-updates,focal-security,now 5.15.0-50.56~20.04.1 amd64 [installed]
linux-image-5.15.0-52-generic/focal-updates,focal-security,now 5.15.0-52.58~20.04.1 amd64 [installed]
linux-image-5.15.0-53-generic/focal-updates,focal-security,now 5.15.0-53.59~20.04.1 amd64 [installed]
linux-image-5.15.0-56-generic/focal-updates,focal-security,now 5.15.0-56.62~20.04.1 amd64 [installed]
linux-image-5.15.0-57-generic/focal-updates,focal-security,now 5.15.0-57.63~20.04.1 amd64 [installed]
linux-image-5.15.0-58-generic/focal-updates,focal-security,now 5.15.0-58.64~20.04.1 amd64 [installed]
linux-image-5.15.0-67-generic/focal-updates,focal-security,now 5.15.0-67.74~20.04.1 amd64 [installed]
linux-image-5.15.0-69-generic/focal-updates,focal-security,now 5.15.0-69.76~20.04.1 amd64 [installed]
linux-image-5.15.0-71-generic/focal-updates,focal-security,now 5.15.0-71.78~20.04.1 amd64 [installed]
linux-image-5.15.0-79-generic/focal-updates,focal-security,now 5.15.0-79.86~20.04.2 amd64 [installed]
linux-image-5.15.0-82-generic/focal-updates,focal-security,now 5.15.0-82.91~20.04.1 amd64 [installed]
linux-image-5.15.0-84-generic/focal-updates,focal-security,now 5.15.0-84.93~20.04.1 amd64 [installed]
linux-image-5.15.0-87-generic/focal-updates,focal-security,now 5.15.0-87.97~20.04.1 amd64 [installed]
linux-image-5.15.0-88-generic/focal-updates,focal-security,now 5.15.0-88.98~20.04.1 amd64 [installed]
linux-image-5.15.0-91-generic/focal-updates,focal-security,now 5.15.0-91.101~20.04.1 amd64 [installed]
linux-image-5.8.0-59-generic/focal-updates,focal-security,now 5.8.0-59.66~20.04.1 amd64 [installed]
linux-image-5.8.0-63-generic/focal-updates,focal-security,now 5.8.0-63.71~20.04.1 amd64 [installed]
linux-image-generic-hwe-20.04/focal-updates,focal-security,now 5.15.0.91.101~20.04.48 amd64 [installed,automatic]
linux-image-unsigned-5.11.0-27-generic/focal-updates,focal-security,now 5.11.0-27.29~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.11.0-34-generic/focal-updates,focal-security,now 5.11.0-34.36~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.11.0-36-generic/focal-updates,focal-security,now 5.11.0-36.40~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.11.0-37-generic/focal-updates,focal-security,now 5.11.0-37.41~20.04.2 amd64 [installed,automatic]
linux-image-unsigned-5.13.0-39-generic/focal-updates,focal-security,now 5.13.0-39.44~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.13.0-40-generic/focal-updates,focal-security,now 5.13.0-40.45~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.13.0-41-generic/focal-updates,focal-security,now 5.13.0-41.46~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.13.0-44-generic/focal-updates,focal-security,now 5.13.0-44.49~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.15.0-70-generic/focal-updates,focal-security,now 5.15.0-70.77~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.15.0-72-generic/focal-updates,focal-security,now 5.15.0-72.79~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.15.0-73-generic/focal-updates,focal-security,now 5.15.0-73.80~20.04.1 amd64 [installed,automatic]
linux-image-unsigned-5.15.0-86-generic/focal-updates,focal-security,now 5.15.0-86.96~20.04.1 amd64 [installed,automatic]

/boot 文件夹内容:

$ ls -l /boot
total 342408
-rw-r--r-- 1 root root    262258 Aug 18 10:34 config-5.15.0-82-generic
-rw-r--r-- 1 root root    262265 Nov 16 08:58 config-5.15.0-91-generic
drwx------ 3 root root      4096 Dec 31  1969 efi
drwxr-xr-x 4 root root      4096 Dec 14 11:32 grub
-rw-r--r-- 1 root root 129102715 Sep 19 07:56 initrd.img-5.15.0-82-generic
-rw-r--r-- 1 root root  55717600 Dec 14 11:30 initrd.img-5.15.0-86-generic
-rw-r--r-- 1 root root 129129902 Dec 14 10:45 initrd.img-5.15.0-91-generic
lrwxrwxrwx 1 root root        28 Dec 14 11:30 initrd.img.old -> initrd.img-5.15.0-91-generic
drwx------ 2 root root     16384 Jun  9  2021 lost+found
-rw-r--r-- 1 root root    182704 Aug 18  2020 memtest86+.bin
-rw-r--r-- 1 root root    184380 Aug 18  2020 memtest86+.elf
-rw-r--r-- 1 root root    184884 Aug 18  2020 memtest86+_multiboot.bin
-rw------- 1 root root   6240491 Aug 18 10:34 System.map-5.15.0-82-generic
-rw------- 1 root root   6242483 Nov 16 08:58 System.map-5.15.0-91-generic
lrwxrwxrwx 1 root root        25 Dec 14 11:30 vmlinuz -> vmlinuz-5.11.0-25-generic
-rw------- 1 root root  11522568 Aug 18 12:03 vmlinuz-5.15.0-82-generic
-rw------- 1 root root  11517416 Nov 16 09:01 vmlinuz-5.15.0-91-generic
lrwxrwxrwx 1 root root        25 Dec 14 11:30 vmlinuz.old -> vmlinuz-5.15.0-91-generic

如果我运行:

sudo apt remove --purge linux-image-unsigned-5.11.0-25-generic

我得到:

$ sudo apt remove --purge linux-image-unsigned-5.11.0-25-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 linux-modules-5.11.0-25-generic : Depends: linux-image-5.11.0-25-generic but it is not going to be installed or
                                            linux-image-unsigned-5.11.0-25-generic but it is not going to be installed
 linux-modules-extra-5.11.0-25-generic : Depends: linux-image-5.11.0-25-generic but it is not going to be installed or
                                                  linux-image-unsigned-5.11.0-25-generic but it is not going to be installed
 linux-signatures-nvidia-5.11.0-25-generic : Depends: linux-image-5.11.0-25-generic but it is not going to be installed or
                                                      linux-image-unsigned-5.11.0-25-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

如果我运行该命令,它建议:

$ sudo apt --fix-broken install

它显示(移动到 pastebin 以释放字符):

https://pastebin.com/FmpseWKi

/boot 分区大小

$ df -h | grep boot
/dev/nvme0n1p2             704M  343M  310M  53% /boot
/dev/nvme0n1p1             511M   87M  425M  17% /boot/efi

我不知道如何清除这些旧内核以及如何防止 /boot 文件夹被填满。

更新 我尝试按照 user68186 的建议使用 Synaptic(在发布的链接中也有建议)。当我尝试仅卸载Linux-映像-5.13.0-25-通用,它还想安装Linux-映像-未签名-5.13.0-25-通用.我在这里读到删除 linux-image 内核会导致安装 linux-image-unsigned 包 这是因为我还需要删除相应的模块包。我选择了Linux 模块额外-5.13.0-25-通用Linux-映像-5.13.0-25-通用,这就是我得到的:

(Reading database ... 2036888 files and directories currently installed.)
Removing linux-signatures-nvidia-5.13.0-25-generic (5.13.0-25.26~20.04.1+1) ...
Removing linux-modules-extra-5.13.0-25-generic (5.13.0-25.26~20.04.1) ...
Removing linux-modules-5.13.0-25-generic (5.13.0-25.26~20.04.1) ...
Removing linux-image-5.13.0-25-generic (5.13.0-25.26~20.04.1) ...
I: /boot/vmlinuz.old is now a symlink to vmlinuz-5.15.0-82-generic
I: /boot/initrd.img.old is now a symlink to initrd.img-5.15.0-82-generic
I: /boot/vmlinuz is now a symlink to vmlinuz-5.15.0-91-generic
I: /boot/initrd.img is now a symlink to initrd.img-5.15.0-91-generic
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-5.13.0-25-generic
/etc/kernel/postrm.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-91-generic
Found initrd image: /boot/initrd.img-5.15.0-91-generic
Found linux image: /boot/vmlinuz-5.15.0-82-generic
Found initrd image: /boot/initrd.img-5.15.0-82-generic
Adding boot menu entry for UEFI Firmware Settings
done
Setting up linux-image-unsigned-5.11.0-36-generic (5.11.0-36.40~20.04.1) ...
Setting up linux-image-5.13.0-48-generic (5.13.0-48.54~20.04.1) ...
Setting up linux-image-unsigned-5.15.0-73-generic (5.15.0-73.80~20.04.1) ...
Setting up linux-image-unsigned-5.13.0-39-generic (5.13.0-39.44~20.04.1) ...
(Reading database ... 2029733 files and directories currently installed.)
Purging configuration files for linux-modules-5.13.0-25-generic (5.13.0-25.26~20.04.1) ...
Processing triggers for linux-image-5.13.0-48-generic (5.13.0-48.54~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.13.0-48-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.13.0-48-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-91-generic
Found initrd image: /boot/initrd.img-5.15.0-91-generic
Found linux image: /boot/vmlinuz-5.15.0-82-generic
Found initrd image: /boot/initrd.img-5.15.0-82-generic
Adding boot menu entry for UEFI Firmware Settings
done
Processing triggers for linux-image-unsigned-5.15.0-73-generic (5.15.0-73.80~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.15.0-73-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.15.0-73-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-91-generic
Found initrd image: /boot/initrd.img-5.15.0-91-generic
Found linux image: /boot/vmlinuz-5.15.0-82-generic
Found initrd image: /boot/initrd.img-5.15.0-82-generic
Adding boot menu entry for UEFI Firmware Settings
done
Processing triggers for linux-image-unsigned-5.13.0-39-generic (5.13.0-39.44~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.13.0-39-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.13.0-39-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.15.0-91-generic
Found initrd image: /boot/initrd.img-5.15.0-91-generic
Found linux image: /boot/vmlinuz-5.15.0-82-generic
Found initrd image: /boot/initrd.img-5.15.0-82-generic
Adding boot menu entry for UEFI Firmware Settings
done
Processing triggers for linux-image-unsigned-5.11.0-36-generic (5.11.0-36.40~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.11.0-36-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.11.0-36-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.11.0-36-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-unsigned-5.11.0-36-generic (--configure):
 installed linux-image-unsigned-5.11.0-36-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-unsigned-5.11.0-36-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
A package failed to install.  Trying to recover:
Setting up linux-image-unsigned-5.11.0-36-generic (5.11.0-36.40~20.04.1) ...
Processing triggers for linux-image-unsigned-5.11.0-36-generic (5.11.0-36.40~20.04.1) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.11.0-36-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.11.0-36-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
cpio: write error: Broken pipe
sort: write failed: 'standard output': Broken pipe
sort: write error
E: mkinitramfs failure cpio 2 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.11.0-36-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-unsigned-5.11.0-36-generic (--configure):
 installed linux-image-unsigned-5.11.0-36-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-image-unsigned-5.11.0-36-generic

对于这里该做什么您有什么建议吗?

更新 2

我跑了

sudo apt autopurge 

并得到了这个(不幸的是它不允许我在这个问题上添加任何文字,所以我不得不把它放在 pastebin 中):

https://pastebin.com/wb00JM5y

更新 3

我终于能够使用 Synaptic 删除旧内核了。出于某种原因,它在 5.11.0-36 和 5.11.0-25 上出现了问题。就好像我必须先删除 36,然后它才允许我删除 25。但在删除了这些之后,我可以毫无错误地删除所有其他内核。

答案1

sudo apt autoremove可以使用或删除不再使用且系统不再需要的软件包sudo apt autopurge。后者还将删除配置文件(如果要删除的软件包有配置文件)。

这也将删除所有旧内核,两个最新的内核将被自动保留。

答案2

Launchpad 上有一个名为linux-purge可以轻松清除旧内核。

这些是安装说明:

在终端中运行以下命令链以在系统中安装 linux-purge:

sh -c 'cd /tmp && wget -N https://git.launchpad.net/linux-purge/plain/install-linux-purge.sh && chmod +x ./install-linux-purge.sh && sudo ./install-linux-purge.sh && rm ./install-linux-purge.sh' && [ "$BASH" ] && echo Replaced current shell in order to make the Bash completion work. && exec bash

由于脚本中使用了 sudo,因此系统可能会提示您输入密码。

此后,只需使用 运行它sudo linux-purge,它将默认删除除最新两个内核之外的所有内容。

答案3

我能够使用 Synaptic 软件包管理器 GUI 删除旧内核。最初,我在删除 5.11.0-36 和 5.11.0-25 内核时遇到了问题。除非我先删除 36 内核,否则就会出现错误。

我发现如果我选择“linux-模块-<version>-generic" 它会自动选择其他相关包,这减少了我必须选择的包的数量。

相关内容