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


11

每当我尝试使用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 <kernel-team@lists.ubuntu.com>
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.

**编辑

每个用户手动删除内核软件包后。dz的说明 paste.ubuntu.com/23487716

同时在sudo apt-get install -f Ubuntu期间通知我有关系统错误的信息 在此处输入图片说明


跑步时会发生什么sudo apt-get install -f
negusp '16

我遇到了同样的问题
dses

1
您最近安装了VirtualBox吗?问题是线run-parts: failed to exec /etc/kernel/postinst.d/vboxadd: Exec format errorvboxadd将在每次添加或删除内核时运行,并且每次都会继续中断安装或删除。Exec format error通常意味着所提到的可执行文件是针对错误的体系结构进行编译的。输出是file /etc/kernel/postinst.d/vboxadd什么?
Chai T. Rex

/etc/kernel/postinst.d/vboxadd:空
dses

我不知道为什么要sudo apt-get install ssh尝试删除那些linux-image-extra软件包。
jarno '04

Answers:


11

注意:正如下面的ChaiT.Rex所评论的,只需要执行步骤4和5即可解决此问题。

对于那些可能需要手动删除某些软件包的人,我保留了步骤1,2和3。但请先尝试使用此/ubuntu//a/490677/26246,它看起来更简单。

  1. 手动删除它们,要小心,如果你重新输入下面的命令rm -rf时,它的运行作为根是一个危险的命令。

    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
    
  4. 删除那个麻烦的virtualbox文件

    sudo rm /etc/kernel/postinst.d/vboxadd
    
  5. 更新dpkg状态和grub菜单

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

确定,按照您的指示,我能够成功安装和删除软件包。但是,在运行sudo apt-get install -f
dses

@dses更新了我的答案,可以从第一步开始。
user.dz

因此,再次按照您的步骤操作确实可以让我正常使用apt。只是有一个问题,我现在遇到了其他内核软件包错误,而Ubuntu在问题的“编辑”部分显示的“ apt install -f”期间显示了系统错误。
dses

1
@ user.dz我认为,如果删除/etc/kernel/postinst.d/vboxadd确实有效,那么这就是真正需要的。每次安装或删除内核时,该目录中的所有内容都会运行,并且带有Exec format error中断的文件每次都会中断这些内核的删除。
Chai T. Rex

1
@ ChaiT.Rex,您是对的,一开始我没有注意到。
user.dz '16
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.