11

Whenever I try to do anything with apt-get whether it's installing, removing, purging, update, upgrade I always get hit with the same error.

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)

I tried following this question but no luck: Apt fails to remove partially installed kernel and can't install any other packages

checking the dpkg status file I see that both packages are half-installed

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.

** Edits

after removing kernel packages manually per user.dz's instructions paste.ubuntu.com/23487716

meanwhile during sudo apt-get install -f Ubuntu alerted me about a system error enter image description here

6
  • What happens when your run sudo apt-get install -f?
    – negusp
    Nov 16, 2016 at 13:55
  • I get the same issue
    – dses
    Nov 16, 2016 at 14:29
  • 2
    Did you recently install VirtualBox? The problem is the line run-parts: failed to exec /etc/kernel/postinst.d/vboxadd: Exec format error. vboxadd will be run every single time you add or remove a kernel, and will continue to interrupt the installation or removal every time. Exec format error usually means that the executable mentioned was compiled for the wrong architecture. What is the output of file /etc/kernel/postinst.d/vboxadd? Nov 16, 2016 at 23:28
  • /etc/kernel/postinst.d/vboxadd: empty
    – dses
    Nov 16, 2016 at 23:44
  • I wonder why sudo apt-get install ssh tries to remove those linux-image-extra packages.
    – jarno
    Apr 3, 2017 at 21:46

1 Answer 1

12

Note: As ChaiT.Rex commented below, only steps 4 & 5 are required to fix the problem.

I leave steps 1,2&3 documented for anyone who may need to manually remove some packages. But try first this https://askubuntu.com/a/490677/26246 which looks easier.

Manually uninstall kernel packages

  1. Remove them manually, be careful if you are retyping the below commands rm -rf is a dangerous command when it's run as 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. Change their status in dpkg status file.

    Make backup just in case

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

    Find the related entries (command with expected output, line number will be different):

     ~$ 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
    

    Open status file for edit and change the package status:

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

    from:

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

    to:

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

    Ctrl+o to save. Ctrl+x to exit.

    Make same changes to linux-image-extra-4.4.0-42-generic .

  3. Manually remove linux-image-4.4.0-38-generic & linux-image-4.4.0-42-generic too

     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
    

    Same as before edit their status to 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
    

Remove kernel post install script for VirtualBox DKMS driver.

  1. Remove that troublesome virtualbox file

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

Continue broken package operations

  1. Update dpkg status & grub menu

     sudo dpkg --audit
     sudo apt-get install -f
     sudo update-grub
    
10
  • Ok I was able to successfully install and remove a package after following your instructions. However I get following errors listed above after running sudo apt-get install -f
    – dses
    Nov 16, 2016 at 15:48
  • @dses, updated my answer, could start it over from step one.
    – user.dz
    Nov 16, 2016 at 16:28
  • so again following your steps did allow me to use apt normally. There is just the issue that I now get additional kernel package errors and Ubuntu displayed a system error during "apt install -f" as displayed in the edits section of the question.
    – dses
    Nov 16, 2016 at 21:59
  • 1
    @user.dz I think that, if removing /etc/kernel/postinst.d/vboxadd does work, that's all that's really needed. Everything in that directory is run every time a kernel is installed or removed, and that file having an Exec format error interrupts the removal of those kernels every time. Nov 16, 2016 at 23:33
  • 1
    @ChaiT.Rex, you are right, I didn't notice that in the beginning.
    – user.dz
    Nov 16, 2016 at 23:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .