由于空间不足,无法升级 Linux 内核,但无法删除旧内核

由于空间不足,无法升级 Linux 内核,但无法删除旧内核
uname -r

5.15.0-60-generic

我的 apt 升级失败,原因如下:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
Get more security updates through Ubuntu Pro with 'esm-apps' enabled:
  mc libmagickcore-6.q16-6-extra node-hosted-git-info imagemagick libzmq5
  python2.7-minimal libmagickwand-6.q16-6 python2.7 python3-rsa mc-data
  node-tar imagemagick-6.q16 libeditorconfig0 libjs-jquery-ui libopenexr24
  libsdl2-2.0-0 libmysofa1 libmagickcore-6.q16-6 glances libpython2.7-minimal
  libpython2.7-stdlib imagemagick-6-common
Learn more about Ubuntu Pro at https://ubuntu.com/pro
0 to upgrade, 0 to newly install, 0 to remove and 0 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up linux-firmware (1.187.36) ...
update-initramfs: Generating /boot/initrd.img-5.15.0-60-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.15.0-60-generic with 1.
dpkg: error processing package linux-firmware (--configure):
 installed linux-firmware package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 linux-firmware
E: Sub-process /usr/bin/dpkg returned an error code (1)

  1. 首先,我对此有点困惑。我似乎已经处于 5.15.0-60-generic 状态,为什么它试图
update-initramfs: failed for /boot/initrd.img-5.15.0-60-generic with 1.

  1. 我认为这是由于磁盘空间不足造成的:
df -H

Filesystem                 Size  Used Avail Use% Mounted on
udev                       135G     0  135G   0% /dev
tmpfs                       28G  3.0M   28G   1% /run
/dev/mapper/vgubuntu-root  982G  838G   94G  90% /
tmpfs                      136G  296M  135G   1% /dev/shm
tmpfs                      5.3M  4.1k  5.3M   1% /run/lock
tmpfs                      136G     0  136G   0% /sys/fs/cgroup
/dev/nvme0n1p2             738M  588M   97M  86% /boot
/dev/nvme0n1p1             536M  6.4M  530M   2% /boot/efi
/dev/sda2                  7.0T  1.5T  5.2T  23% /mnt/usb-8tb
tmpfs                       28G   25k   28G   1% /run/user/125
tmpfs                       28G   70k   28G   1% /run/user/1000

因此,我尝试删除旧的 Linux 内核,因为它们似乎占用了空间:

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n  | grep linux-image
20      linux-image-generic-hwe-20.04
9520    linux-image-5.8.0-43-generic
9927    linux-image-5.11.0-36-generic
9928    linux-image-5.11.0-37-generic
9933    linux-image-5.11.0-38-generic
9956    linux-image-5.13.0-25-generic
9956    linux-image-5.13.0-27-generic
9965    linux-image-5.13.0-28-generic
9965    linux-image-5.13.0-30-generic
9965    linux-image-5.13.0-35-generic
9968    linux-image-5.13.0-37-generic
9968    linux-image-5.13.0-39-generic
9971    linux-image-5.13.0-40-generic
9971    linux-image-5.13.0-41-generic
9971    linux-image-5.13.0-44-generic
9972    linux-image-5.13.0-48-generic
9973    linux-image-5.13.0-51-generic
9973    linux-image-5.13.0-52-generic
10775   linux-image-5.15.0-41-generic
10778   linux-image-5.15.0-43-generic
11196   linux-image-5.15.0-46-generic
11207   linux-image-5.15.0-52-generic
11208   linux-image-5.15.0-50-generic
11209   linux-image-5.15.0-48-generic
11210   linux-image-5.15.0-53-generic
11212   linux-image-5.15.0-56-generic
11214   linux-image-5.15.0-57-generic
11215   linux-image-5.15.0-58-generic
11223   linux-image-5.15.0-60-generic
11499   linux-image-5.11.0-40-generic
11502   linux-image-5.11.0-41-generic
11502   linux-image-5.11.0-43-generic
11504   linux-image-5.11.0-44-generic
11504   linux-image-5.11.0-46-generic
  1. 但是当尝试删除任何较旧的文件时,它说只会释放 0 个字节。

感谢您对这些问题提供的一些指导 - 非常感谢。

答案1

假设:fsck没问题,即没有抱怨。

现在,

保留linux-image-generic-hwe-20.04原位,因为这是用于 ubuntu 后续更新的元包。

其他的只是占用空间,除了由它打印的uname -r和可能在它之前的一个(作为备份,以防万一发生故障时安全)

这些其他的应该是可拆卸的,例如
sudo apt purge linux-image-5.8.0-43-generic (对于上面列表中的第一个)
您也可以在第一个之后添加更多,只需确保每个之间至少有一个空格即可。

...甚至
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | grep linux-image >~/kernels

然后确保该文件中只有要删除的名称......
(例如,编辑nano ~/kernels,只留下要删除的包,保存文件)
然后做:

sudo apt purge $(cat ~/kernels)
...或类似。

相关内容