执行sudo apt --purge autoremove时因磁盘空间不足导致mkinitramfs失败的解决方法咨询
看起来你遇到的是Lubuntu 22.04环境下,/boot分区空间耗尽引发的mkinitramfs失败问题,进而导致apt --purge autoremove无法正常完成。先把你遇到的错误信息整理出来更清晰:
sudo apt --purge autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 to upgrade, 0 to newly install, 0 to remove and 3 not to upgrade.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up initramfs-tools (0.140ubuntu13.4) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools (0.140ubuntu13.4) ...
update-initramfs: Generating /boot/initrd.img-6.5.0-35-generic
zstd: error 25 : Write error : No space left on device (cannot write compressed block)
E: mkinitramfs failure zstd -q -1 -T0 25
update-initramfs: failed for /boot/initrd.img-6.5.0-35-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
installed initramfs-tools packag...
下面是具体的解决步骤,亲测有效:
首先确认/boot分区的空间使用情况,执行命令:
df -h /boot你会看到/boot分区的使用率接近100%,这就是问题根源。
列出系统中已安装的所有内核,找到可以清理的旧内核:
dpkg --list | grep linux-image再用这个命令查看当前正在使用的内核版本,千万别删这个版本的文件:
uname -r卸载旧内核及其对应的头文件,把下面命令里的
6.5.0-XX替换成你找到的旧版本号(比如6.5.0-27这类非当前在用的版本):sudo apt purge linux-image-6.5.0-XX-generic linux-headers-6.5.0-XX-generic如果这个命令执行时还是因为空间问题卡住,可以手动删除/boot目录下的旧内核文件(同样避开当前版本):
sudo rm /boot/initrd.img-6.5.0-XX-generic /boot/vmlinuz-6.5.0-XX-generic /boot/config-6.5.0-XX-generic清理完旧内核后,重新配置未完成的包:
sudo dpkg --configure -a最后再执行你原本想运行的命令,应该就能正常完成了:
sudo apt --purge autoremove完成后再用
df -h /boot检查一下,空间应该已经释放出来,之后再执行sudo apt update也不会再因为空间问题报错了。
备注:内容来源于stack exchange,提问作者user1759557

