Ubuntu – Errors were encountered while processing Linux kernel packages

aptkernelupgrade

Ubuntu server 14.04.

apt-get upgrade and apt-get autoremove and others ends with error:

 Errors were encountered while processing:
 linux-image-extra-3.13.0-96-generic
 linux-image-extra-3.19.0-64-generic
 linux-image-extra-3.19.0-65-generic
 linux-image-extra-3.19.0-66-generic
 linux-image-extra-3.19.0-68-generic

It prevents me from upgrade to 16.04
I've tried many advices but nothing helped

Does anyone have any idea?

Here is the complete output:

$ sudo apt-get autoremove
[sudo] password for drousar:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  linux-image-extra-3.13.0-96-generic linux-image-extra-3.19.0-64-generic
  linux-image-extra-3.19.0-65-generic linux-image-extra-3.19.0-66-generic
  linux-image-extra-3.19.0-68-generic
0 upgraded, 0 newly installed, 5 to remove and 11 not upgraded.
20 not fully installed or removed.
After this operation, 793 MB disk space will be freed.
Do you want to continue? [Y/n] Y
dpkg: warning: files list file for package 'linux-headers-3.13.0-103-generic' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'linux-headers-3.13.0-103' missing; assuming package has no files currently installed
(Reading database ... 130673 files and directories currently installed.)
Removing linux-image-extra-3.13.0-96-generic (3.13.0-96.143) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-96-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-96-generic /boot/vmlinuz-3.13.0-96-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-96-generic /boot/vmlinuz-3.13.0-96-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-96-generic
grep: /boot/config-3.13.0-96-generic: No such file or directory
WARNING: missing /lib/modules/3.13.0-96-generic
Device driver support needs thus be built-in linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-96-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.13.0-96-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.13.0-96-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-3.19.0-64-generic (3.19.0-64.72~14.04.1) ...
depmod: FATAL: could not load /boot/System.map-3.19.0-64-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-64-generic /boot/vmlinuz-3.19.0-64-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-64-generic /boot/vmlinuz-3.19.0-64-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-64-generic
grep: /boot/config-3.19.0-64-generic: No such file or directory
WARNING: missing /lib/modules/3.19.0-64-generic
Device driver support needs thus be built-in linux image!
depmod: ERROR: could not open directory /lib/modules/3.19.0-64-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.19.0-64-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.19.0-64-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-3.19.0-65-generic (3.19.0-65.73~14.04.1) ...
depmod: FATAL: could not load /boot/System.map-3.19.0-65-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-65-generic /boot/vmlinuz-3.19.0-65-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-65-generic /boot/vmlinuz-3.19.0-65-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-65-generic
grep: /boot/config-3.19.0-65-generic: No such file or directory
WARNING: missing /lib/modules/3.19.0-65-generic
Device driver support needs thus be built-in linux image!
depmod: ERROR: could not open directory /lib/modules/3.19.0-65-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.19.0-65-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.19.0-65-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-extra-3.19.0-66-generic (3.19.0-66.74~14.04.1) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-66-generic /boot/vmlinuz-3.19.0-66-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-66-generic /boot/vmlinuz-3.19.0-66-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-66-generic
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.19.0-66-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.19.0-66-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Removing linux-image-extra-3.19.0-68-generic (3.19.0-68.76~14.04.1) ...
depmod: FATAL: could not load /boot/System.map-3.19.0-68-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-68-generic /boot/vmlinuz-3.19.0-68-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-68-generic /boot/vmlinuz-3.19.0-68-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-68-generic
grep: /boot/config-3.19.0-68-generic: No such file or directory
WARNING: missing /lib/modules/3.19.0-68-generic
Device driver support needs thus be built-in linux image!
depmod: ERROR: could not open directory /lib/modules/3.19.0-68-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.19.0-68-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.19.0-68-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-extra-3.13.0-96-generic
 linux-image-extra-3.19.0-64-generic
 linux-image-extra-3.19.0-65-generic
 linux-image-extra-3.19.0-66-generic
 linux-image-extra-3.19.0-68-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Tried following:

sudo rm -f /var/lib/dpkg/info/linux-image-extra-{3.13.0-96,3.19.0-64,3.19.0-65,3.19.0-66,3.19.0-68}-generic.postrm
sudo apt-get purge linux-image-extra-{3.13.0-96,3.19.0-64,3.19.0-65,3.19.0-66,3.19.0-68}-generic

output:

drousar@ubk-ubuntu-test:~$ sudo rm -f /var/lib/dpkg/info/linux-image-extra-{3.13.0-96,3.19.0-64,3.19.0-65,3.19.0-66,3.19.0-68}-generic.postrm
[sudo] password for drousar:
drousar@ubk-ubuntu-test:~$ sudo apt-get purge linux-image-extra-{3.13.0-96,3.19.0-64,3.19.0-65,3.19.0-66,3.19.0-68}-generic
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
  linux-image-extra-3.13.0-96-generic linux-image-extra-3.19.0-64-generic
  linux-image-extra-3.19.0-65-generic linux-image-extra-3.19.0-66-generic
  linux-image-extra-3.19.0-68-generic
0 upgraded, 0 newly installed, 5 to remove and 11 not upgraded.
20 not fully installed or removed.
After this operation, 793 MB disk space will be freed.
Do you want to continue? [Y/n]
dpkg: warning: files list file for package 'linux-headers-3.13.0-103-generic' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'linux-headers-3.13.0-103' missing; assuming package has no files currently installed
(Reading database ... 130673 files and directories currently installed.)
Removing linux-image-extra-3.13.0-96-generic (3.13.0-96.143) ...
Removing linux-image-extra-3.19.0-64-generic (3.19.0-64.72~14.04.1) ...
Removing linux-image-extra-3.19.0-65-generic (3.19.0-65.73~14.04.1) ...
Removing linux-image-extra-3.19.0-66-generic (3.19.0-66.74~14.04.1) ...
Removing linux-image-extra-3.19.0-68-generic (3.19.0-68.76~14.04.1) ...
Setting up linux-image-3.13.0-103-generic (3.13.0-103.150) ...
Setting up linux-image-3.13.0-105-generic (3.13.0-105.152) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.19.0-77-generic
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-105-generic /boot/vmlinuz-3.13.0-105-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-105-generic /boot/vmlinuz-3.13.0-105-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-105-generic
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.13.0-105-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.13.0-105-generic.postinst line 1025.
dpkg: error processing package linux-image-3.13.0-105-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
Setting up linux-image-3.13.0-96-generic (3.13.0-96.143) ...
Setting up linux-image-3.19.0-64-generic (3.19.0-64.72~14.04.1) ...
Setting up linux-image-3.19.0-65-generic (3.19.0-65.73~14.04.1) ...
Setting up linux-image-3.19.0-66-generic (3.19.0-66.74~14.04.1) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
Failed to symbolic-link boot/initrd.img-3.19.0-66-generic to initrd.img:File exists at /var/lib/dpkg/info/linux-image-3.19.0-66-generic.postinst line 629.
dpkg: error processing package linux-image-3.19.0-66-generic (--configure):
 subprocess installed post-installation script returned error exit status 17
Setting up linux-image-3.19.0-68-generic (3.19.0-68.76~14.04.1) ...
Setting up linux-image-3.19.0-77-generic (3.19.0-77.85~14.04.1) ...
Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.13.0-105-generic
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-77-generic /boot/vmlinuz-3.19.0-77-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-77-generic /boot/vmlinuz-3.19.0-77-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-77-generic
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.19.0-77-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-3.19.0-77-generic.postinst line 1025.
dpkg: error processing package linux-image-3.19.0-77-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
dpkg: dependency problems prevent configuration of linux-image-extra-3.13.0-105-generic:
 linux-image-extra-3.13.0-105-generic depends on linux-image-3.13.0-105-generic; however:
  Package linux-image-3.13.0-105-generic is not configured yet.

dpkg: error processing package linux-image-extra-3.13.0-105-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-3.13.0-105-generic; however:
  Package linux-image-3.13.0-105-generic is not configured yet.
 linux-image-generic depends on linux-image-extra-3.13.0-105-generic; however:
  Package linux-image-extra-3.13.0-105-generic is not configured yet.

dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 3.13.0.105.113); however:
  Package linux-image-generNo apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
No apport report written because MaxReports is reached already
ic is not configured yet.

dpkg: error processing package linux-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-image-extra-3.19.0-77-generic:
 linux-image-extra-3.19.0-77-generic depends on linux-image-3.19.0-77-generic; however:
  Package linux-image-3.19.0-77-generic is not configured yet.

dpkg: error processing package linux-image-extra-3.19.0-77-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-image-generic-lts-vivid:
 linux-image-generic-lts-vivid depends on linux-image-3.19.0-77-generic; however:
  Package linux-image-3.19.0-77-generic is not configured yet.
 linux-image-generic-lts-vivid depends on linux-image-extra-3.19.0-77-generic; however:
  Package linux-image-extra-3.19.0-77-generic is not configured yet.

dpkg: error processing package linux-image-generic-lts-vivid (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic-lts-vivid:
 linux-generic-lts-vivid depends on linux-image-generic-lts-vivid (= 3.19.0.77.59); however:
  Package linux-image-generic-lts-vivid is not configured yet.

dpkg: error processing package linux-generic-lts-vivid (--configure):
 dependency problems - leaving unconfigured
Setting up linux-image-extra-3.13.0-103-generic (3.13.0-103.150) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-103-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-103-generic /boot/vmlinuz-3.13.0-103-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-103-generic /boot/vmlinuz-3.13.0-103-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-103-generic
grep: /boot/config-3.13.0-103-generic: No such file or directory
WARNING: missing /lib/modules/3.13.0-103-generic
Device driver support needs thus be built-in linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-103-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
mktemp: failed to create file via template ‘/var/tmp/mkinitramfs-FW_XXXXXX’: No such file or directory
update-initramfs: failed for /boot/initrd.img-3.13.0-103-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-3.13.0-103-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
No apport report written because MaxReports is reached already
Errors were encountered while processing:
 linux-image-3.13.0-105-generic
 linux-image-3.19.0-66-generic
 linux-image-3.19.0-77-generic
 linux-image-extra-3.13.0-105-generic
 linux-image-generic
 linux-generic
 linux-image-extra-3.19.0-77-generic
 linux-image-generic-lts-vivid
 linux-generic-lts-vivid
 linux-image-extra-3.13.0-103-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Best Answer

All these linux-image-extra-* packages depend on their respective linux-image-* counterpart. That includes the post-removal script (a series commands executed after a package was removed) which uses resources from those packages.

In this particular case it should be safe to just force the removal without the execution of the post-removal scripts. Unfortunately there's not package manager option to do that but you can delete the problematic script files and then remove the packages normally:

sudo rm -f /var/lib/dpkg/info/linux-image-extra-{3.13.0-96,3.19.0-64,3.19.0-65,3.19.0-66,3.19.0-68}-generic.postrm
sudo apt-get purge linux-image-extra-{3.13.0-96,3.19.0-64,3.19.0-65,3.19.0-66,3.19.0-68}-generic