Ubuntu 16.04 损坏的内核包不允许我使用 apt-get 安装或删除任何东西

Ubuntu 16.04 损坏的内核包不允许我使用 apt-get 安装或删除任何东西

每当我尝试使用 apt-get 做任何事情时,无论是安装、删除、清除、更新还是升级,我总是遇到相同的错误。

ses@ses-VirtualBox:~/Downloads$ sudo apt-get install ssh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-45 linux-headers-4.4.0-45-generic linux-image-4.4.0-45-generic linux-image-extra-4.4.0-45-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
Suggested packages:
  ssh-askpass rssh molly-guard monkeysphere
The following packages will be REMOVED:
  linux-image-extra-4.4.0-38-generic linux-image-extra-4.4.0-42-generic
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh ssh-import-id
0 upgraded, 5 newly installed, 2 to remove and 0 not upgraded.
10 not fully installed or removed.
Need to get 0 B/643 kB of archives.
After this operation, 320 MB disk space will be freed.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
(Reading database ... 308434 files and directories currently installed.)
Removing linux-image-extra-4.4.0-38-generic (4.4.0-38.57) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: executing /etc/kernel/postinst.d/vboxadd 4.4.0-38-generic /boot/vmlinuz-4.4.0-38-generic
run-parts: failed to exec /etc/kernel/postinst.d/vboxadd: Exec format error
run-parts: /etc/kernel/postinst.d/vboxadd exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-38-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-4.4.0-42-generic (4.4.0-42.62) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: executing /etc/kernel/postinst.d/vboxadd 4.4.0-42-generic /boot/vmlinuz-4.4.0-42-generic
run-parts: failed to exec /etc/kernel/postinst.d/vboxadd: Exec format error
run-parts: /etc/kernel/postinst.d/vboxadd exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-42-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-4.4.0-38-generic
 linux-image-extra-4.4.0-42-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

我尝试回答这个问题,但没有成功: Apt 无法删除部分安装的内核,也无法安装任何其他软件包

检查 dpkg 状态文件,我发现两个包都只安装了一半

Package: linux-image-extra-4.4.0-38-generic
Status: deinstall ok half-installed
Priority: optional
Section: kernel
Installed-Size: 158607
Maintainer: Ubuntu Kernel Team <[email protected]>
Architecture: amd64
Source: linux
Version: 4.4.0-38.57
Depends: linux-image-4.4.0-38-generic, crda | wireless-crda
Description: Linux kernel extra modules for version 4.4.0 on 64 bit x86 SMP
 This package contains the Linux kernel extra modules for version 4.4.0 on
 64 bit x86 SMP.
 .
 Also includes the corresponding System.map file, the modules built by the
 packager, and scripts that try to ensure that the system is not left in an
 unbootable state after an update.
 .
 Supports Generic processors.
 .
 Geared toward desktop and server systems.
 .
 You likely do not want to install this package directly. Instead, install
 the linux-generic meta-package, which will ensure that upgrades work
 correctly, and that supporting packages are also installed.

** 编辑

根据 user.dz 的指示手动删除内核包后 paste.ubuntu.com/23487716

同时,在 sudo apt-get install -f Ubuntu 期间,系统提示我出现系统错误 在此处输入图片描述

答案1

笔记:正如 ChaiT.Rex 在下面评论的那样,只需要步骤 4 和 5 即可解决问题。

我为可能需要手动删除某些软件包的人保留了步骤 1、2 和 3 的记录。但请先尝试这个https://askubuntu.com/a/490677/26246看起来更容易。

手动卸载内核包

  1. 手动移除它们,当心如果您重新输入以下命令,rm -rf则以 root 身份运行时该命令是危险的。

     sudo rm -rf /lib/modules/4.4.0-38-generic /lib/modules/4.4.0-42-generic
     sudo rm -rf /usr/share/doc/linux-image-extra-4.4.0-38-generic /usr/share/doc/linux-image-extra-4.4.0-42-generic
     sudo rm /var/lib/dpkg/info/linux-image-extra-4.4.0-38-generic* /var/lib/dpkg/info/linux-image-extra-4.4.0-42-generic*
    
  2. 在 dpkg 状态文件中更改其状态。

    做好备份以防万一

     sudo cp /var/lib/dpkg/status /var/lib/dpkg/status.backup0
    

    查找相关条目(具有预期输出的命令,行号会有所不同):

     ~$ grep -n -e "linux-image-extra-4.4.0-38-generic" -e "linux-image-extra-4.4.0-42-generic" /var/lib/dpkg/status
     18488:Package: linux-image-extra-4.4.0-42-generic
     77123:Package: linux-image-extra-4.4.0-38-generic
    

    打开状态文件进行编辑并更改包状态:

     sudo nano +18488 /var/lib/dpkg/status
    

    从:

     Package: linux-image-extra-4.4.0-38-generic
     Status: install ok installed
    

    到:

     Package: linux-image-extra-4.4.0-38-generic
     Status: deinstall ok config-files
    

    Ctrl+o保存。Ctrl+x退出。

    对 linux-image-extra-4.4.0-42-generic 进行相同的更改。

  3. 手动删除 linux-image-4.4.0-38-generic 和 linux-image-4.4.0-42-generic

     sudo rm -f *4.4.0-38-generic *4.4.0-42-generic
     sudo rm -rf /usr/share/doc/linux-image-4.4.0-38-generic /usr/share/doc/linux-image-4.4.0-42-generic
    

    与之前相同,将其状态编辑为deinstall ok config-files

     $ grep -n -e "Package: linux-image-4.4.0-38-generic" -e "Package: linux-image-4.4.0-42-generic" /var/lib/dpkg/status
     61217:Package: linux-image-4.4.0-38-generic
     98051:Package: linux-image-4.4.0-42-generic
    

删除 VirtualBox DKMS 驱动程序的内核后安装脚本。

  1. 删除那个麻烦的virtualbox文件

     sudo rm /etc/kernel/postinst.d/vboxadd
    

继续破损包裹操作

  1. 更新 dpkg 状态和 grub 菜单

     sudo dpkg --audit
     sudo apt-get install -f
     sudo update-grub
    

相关内容