我无法安装或卸载任何东西,否则会出现此错误

我无法安装或卸载任何东西,否则会出现此错误

我第一次尝试卸载 Virtualbox 时收到此错误。错误是:

root@Amar:~# sudo apt-get autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
 The following packages will be REMOVED:
  linux-image-extra-4.4.0-21-generic linux-image-extra-4.4.0-22-generic     
 linux-image-extra-4.4.0-24-generic
0 upgraded, 0 newly installed, 3 to remove and 1659 not upgraded.
4 not fully installed or removed.
After this operation, 359 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 445742 files and directories currently installed.)
Removing linux-image-extra-4.4.0-21-generic (4.4.0-21.37) ...
depmod: FATAL: could not load /boot/System.map-4.4.0-21-generic: No such  file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-21-generic  /boot/vmlinuz-4.4.0-21-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-21-generic /boot/vmlinuz-4.4.0-21-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-21-generic
E: busybox or busybox-static, version 1:1.22.0-17~ or later, is required but not installed
update-initramfs: failed for /boot/initrd.img-4.4.0-21-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-21-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-4.4.0-22-generic (4.4.0-22.40) ...
depmod: FATAL: could not load /boot/System.map-4.4.0-22-generic: No such  file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-22-generic
E: busybox or busybox-static, version 1:1.22.0-17~ or later, is required but not installed
update-initramfs: failed for /boot/initrd.img-4.4.0-22-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-4.4.0-24-generic (4.4.0-24.43) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-24- generic /boot/vmlinuz-4.4.0-24-generic                                        
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-24-generic /boot/vmlinuz-4.4.0-24-generic                                                                                                          
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-24-generic /boot/vmlinuz-4.4.0-24-generic                                                                                               
update-initramfs: Generating /boot/initrd.img-4.4.0-24-generic                                                                                                                                            
E: busybox or busybox-static, version 1:1.22.0-17~ or later, is required but not installed                                                                                                                
update-initramfs: failed for /boot/initrd.img-4.4.0-24-generic with 1.                                                                                                                                    
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1                                                                                                                               
 dpkg: error processing package linux-image-extra-4.4.0-24-generic (--remove):                                                                                                                             
 subprocess installed post-removal script returned error exit status 1                                                                                                                                    
Errors were encountered while processing:                                                                                                                                                                 
 linux-image-extra-4.4.0-21-generic                                                                                                                                                                       
 linux-image-extra-4.4.0-22-generic                                                                                                                                                                       
 linux-image-extra-4.4.0-24-generic                                                                                                                                                                       
E: Sub-process /usr/bin/dpkg returned an error code (1)

不知何故,软件包卸载/安装但不完全。

清除和自动删除根本不起作用。

我也尝试安装 busybox 以及运行以下命令:

sudo apt-get -f install

但什么也没起作用。

答案1

有趣的是,我注意到了这一点:

E: busybox or busybox-static, version 1:1.22.0-17~ or later, is required but not installed

您能否验证是否安装了 busybox-static。看来它是运行删除后脚本所必需的。尝试一下看看它是否已安装。

$ dpkg -l | grep busybox-static

它应该给出如下输出:

ii  busybox-static 1:1.22.0-15ubuntu1 amd64 Standalone rescue shell with tons of builtin utilities

两个“ii”表示已安装,同时显示版本。如果您有除“ii”以外的其他内容,请尝试安装 busybox-static:

apt-get install busybox-static

我确实知道您说您无法安装任何东西,所以它可能无法工作。


所以,让我们明确一点。你实际上永远都不需要这样做,但在某些情况下,这只是最后的手段。你可以清楚地看到,是“移除后脚本”失败了。软件包的脚本位于/var/lib/dpkg/info。我们基本上会告诉你的软件包管理器,移除后不应该发生任何事情。这是谎言,但有时,你需要撒谎来解决问题。结过婚的人都知道这一点。

开始,获取 root 权限:

jawtheshark@shark:~$ sudo bash
[sudo] password for jawtheshark: 
root@shark:~#

切换到我提到的目录:

root@shark:~# cd /var/lib/dpkg/info
root@shark:/var/lib/dpkg/info#

此时,我们要做几件事:

  • 备份删除后的脚本,以防你以后想回滚
  • 给删除后脚本一个新命令,基本上就是“什么都不做”

导致问题的软件包名为linux-image-extra-4.4.0-21-genericlinux-image-extra-4.4.0-22-genericlinux-image-extra-4.4.0-24-generic。删除后的脚本以 为后缀.postrm。让我们备份这些脚本:

root@shark:/var/lib/dpkg/info# for n in 21 22 24; do cp linux-image-extra-4.4.0-$n-generic.postrm linux-image-extra-4.4.0-$n-generic.postrm.backup ; done 
root@shark:/var/lib/dpkg/info# ls *.backup
linux-image-extra-4.4.0-21-generic.postrm.backup  linux-image-extra-4.4.0-24-generic.postrm.backup
linux-image-extra-4.4.0-22-generic.postrm.backup
root@shark:/var/lib/dpkg/info# 

如您所见,您现在有了每个脚本的备份文件。现在让我们“更新”这些脚本:

root@shark:/var/lib/dpkg/info# for n in 21 22 24; do printf '#!/bin/sh\nexit 0\n' > linux-image-extra-4.4.0-$n-generic.postrm ; done 

这将在指定的文件中写入以下脚本:

#!/bin/sh
exit 0

理论上,删除后脚本不会再失败,因此 apt 会认为一切正常,并继续执行。

再次强调:这是不可取的,只有在别无选择的情况下才应该这样做。这可能无法真正解决问题,因为据我所知,initramfs-tools 存在问题,导致这些脚本中止。

相关内容