I am using Ubuntu 18.04 and trying to uninstall older kernel images using apt. However, I get an error saying that it cannot be uninstalled because headers are missing. How can I uninstall them? Here is the partial output of the command sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-image-extra-3.13.0-39-generic linux-image-extra-3.13.0-40-generic
linux-image-extra-3.13.0-43-generic linux-image-extra-3.13.0-46-generic
linux-image-extra-3.13.0-48-generic linux-image-extra-3.13.0-49-generic
linux-image-extra-3.13.0-52-generic linux-image-extra-3.13.0-53-generic
linux-image-extra-3.13.0-54-generic linux-image-extra-3.13.0-55-generic
linux-image-extra-3.13.0-57-generic linux-image-extra-3.13.0-58-generic
linux-image-extra-3.13.0-59-generic linux-image-extra-3.13.0-61-generic
linux-image-extra-3.13.0-62-generic linux-image-extra-3.13.0-63-generic
linux-image-extra-3.13.0-65-generic linux-image-extra-3.13.0-66-generic
linux-image-extra-3.13.0-68-generic linux-image-extra-3.13.0-77-generic
linux-image-extra-3.13.0-88-generic linux-image-extra-3.13.0-91-generic
linux-image-extra-3.13.0-92-generic linux-image-extra-3.13.0-93-generic
0 upgraded, 0 newly installed, 24 to remove and 14 not upgraded.
24 not fully installed or removed.
After this operation, 3,646 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 459090 files and directories currently installed.)
Removing linux-image-extra-3.13.0-39-generic (3.13.0-39.66) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-39-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-39-generic /boot/vmlinuz-3.13.0-39-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-39-generic /boot/vmlinuz-3.13.0-39-generic
dkms: WARNING: Linux headers are missing, which may explain the above failures.
please install the linux-headers-3.13.0-39-generic package to fix this.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-39-generic /boot/vmlinuz-3.13.0-39-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-39-generic
WARNING: missing /lib/modules/3.13.0-39-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-39-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
cp: failed to restore the default file creation context: Invalid argument
E: /usr/share/initramfs-tools/hooks/kmod failed with return 1.
update-initramfs: failed for /boot/initrd.img-3.13.0-39-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-39-generic (--remove):
installed linux-image-extra-3.13.0-39-generic package post-removal
script subprocess returned error exit status 1
Removing linux-image-extra-3.13.0-40-generic (3.13.0-40.69) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-40-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-40-generic /boot/vmlinuz-3.13.0-40-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-40-generic /boot/vmlinuz-3.13.0-40-generic
dkms: WARNING: Linux headers are missing, which may explain the above failures.
please install the linux-headers-3.13.0-40-generic package to fix this.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-40-generic /boot/vmlinuz-3.13.0-40-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-40-generic
WARNING: missing /lib/modules/3.13.0-40-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-40-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
cp: failed to restore the default file creation context: Invalid argument
E: /usr/share/initramfs-tools/hooks/kmod failed with return 1.
update-initramfs: failed for /boot/initrd.img-3.13.0-40-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-40-generic (--remove):
installed linux-image-extra-3.13.0-40-generic package post-removal script subprocess returned error exit status 1
Removing linux-image-extra-3.13.0-43-generic (3.13.0-43.72) ...
depmod: FATAL: could not load /boot/System.map-3.13.0-43-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0- 43-generic /boot/vmlinuz-3.13.0-43-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.13.0-43-generic /boot/vmlinuz-3.13.0-43-generic
dkms: WARNING: Linux headers are missing, which may explain the above failures.
please install the linux-headers-3.13.0-43-generic package to fix this.
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-43-generic /boot/vmlinuz-3.13.0-43-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-43-generic
WARNING: missing /lib/modules/3.13.0-43-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/3.13.0-43-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
E: amd64-microcode: unsupported kernel version!
cp: failed to restore the default file creation context: Invalid argument
E: /usr/share/initramfs-tools/hooks/kmod failed with return 1.
update-initramfs: failed for /boot/initrd.img-3.13.0-43-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-43-generic (--remove):
installed linux-image-extra-3.13.0-43-generic package post-removal script subprocess returned error exit status 1
The output continues like that and the final part is as follows:
dpkg: error processing package linux-image-extra-3.13.0-93-generic (--remove):
installed linux-image-extra-3.13.0-93-generic package post-removal script subprocess 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-39-generic
linux-image-extra-3.13.0-40-generic
linux-image-extra-3.13.0-43-generic
linux-image-extra-3.13.0-46-generic
linux-image-extra-3.13.0-48-generic
linux-image-extra-3.13.0-49-generic
linux-image-extra-3.13.0-52-generic
linux-image-extra-3.13.0-53-generic
linux-image-extra-3.13.0-54-generic
linux-image-extra-3.13.0-55-generic
linux-image-extra-3.13.0-57-generic
linux-image-extra-3.13.0-58-generic
linux-image-extra-3.13.0-59-generic
linux-image-extra-3.13.0-61-generic
linux-image-extra-3.13.0-62-generic
linux-image-extra-3.13.0-63-generic
linux-image-extra-3.13.0-65-generic
linux-image-extra-3.13.0-66-generic
linux-image-extra-3.13.0-68-generic
linux-image-extra-3.13.0-77-generic
linux-image-extra-3.13.0-88-generic
linux-image-extra-3.13.0-91-generic
linux-image-extra-3.13.0-92-generic
linux-image-extra-3.13.0-93-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)
sudo apt-get install linux-headers-3.13.0-39-generic
as the output said. – mja Nov 09 '18 at 14:56