3

I seem to have corrupted my apt database and I have no idea how to repair it. It fails on every command that involves linux-image-4.4.0-22-generic and linux-image-extra-4.4.0-22-generic. Here is the console output after running sudo apt autoremove.

jonathan@Aristotle:~$ sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  linux-headers-4.4.0-22 linux-headers-4.4.0-22-generic linux-image-4.4.0-22-generic linux-image-extra-4.4.0-22-generic
0 upgraded, 0 newly installed, 4 to remove and 0 not upgraded.
4 not fully installed or removed.
After this operation, 295 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 268155 files and directories currently installed.)
Removing linux-headers-4.4.0-22-generic (4.4.0-22.40) ...
Removing linux-headers-4.4.0-22 (4.4.0-22.40) ...
Removing linux-image-extra-4.4.0-22-generic (4.4.0-22.40) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Generating grub configuration file ...
grub-probe: error: not a directory.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-4.4.0-22-generic (4.4.0-22.40) ...
Examining /etc/kernel/prerm.d.
run-parts: executing /etc/kernel/prerm.d/dkms 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
dkms: removing: bbswitch 0.8 (4.4.0-22-generic) (x86_64)

-------- Uninstall Beginning --------
Module:  bbswitch
Version: 0.8
Kernel:  4.4.0-22-generic (x86_64)
-------------------------------------

Status: Before uninstall, this module version was ACTIVE on this kernel.

bbswitch.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.

depmod....

DKMS: uninstall completed.
dkms: removing: nvidia-340 340.96 (4.4.0-22-generic) (x86_64)

-------- Uninstall Beginning --------
Module:  nvidia-340
Version: 340.96
Kernel:  4.4.0-22-generic (x86_64)
-------------------------------------

Status: Before uninstall, this module version was ACTIVE on this kernel.

nvidia_340.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.


nvidia_340_uvm.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.

depmod....

DKMS: uninstall completed.
dkms: removing: virtualbox 5.0.18 (4.4.0-22-generic) (x86_64)

-------- Uninstall Beginning --------
Module:  virtualbox
Version: 5.0.18
Kernel:  4.4.0-22-generic (x86_64)
-------------------------------------

Status: Before uninstall, this module version was ACTIVE on this kernel.

vboxdrv.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.


vboxnetadp.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.


vboxnetflt.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.


vboxpci.ko:
 - Uninstallation
   - Deleting from: /lib/modules/4.4.0-22-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.

depmod....

DKMS: uninstall completed.
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Generating grub configuration file ...
grub-probe: error: not a directory.
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-22-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-4.4.0-22-generic
 linux-image-4.4.0-22-generic

E: Sub-process /usr/bin/dpkg returned an error code (1)

I have added a run with dpkg using full debugging where I attempt to remove linux-image-4.4.0-22-generic and linux-image-extra-4.4.0-22-generic.

jonathan@Aristotle:~$ sudo dpkg -D73773 -r linux-image-extra-4.4.0-22-generic linux-image-4.4.0-22-generic
D000001: ensure_diversions: new, (re)loading
D000001: process queue pkg linux-image-extra-4.4.0-22-generic:amd64 queue.len 1 progress 1, try 1
D000001: deferred_remove package linux-image-extra-4.4.0-22-generic:amd64
D000001: checking dependencies for remove 'linux-image-extra-4.4.0-22-generic:amd64'
(Reading database ... 235952 files and directories currently installed.)
Removing linux-image-extra-4.4.0-22-generic (4.4.0-22.40) ...
D020000: trigproc_activate_packageprocessing pkg=linux-image-extra-4.4.0-22-generic:amd64
D000001: removal_bulk package linux-image-extra-4.4.0-22-generic:amd64
D000002: fork/exec /var/lib/dpkg/info/linux-image-extra-4.4.0-22-generic.postrm ( remove )
depmod: FATAL: could not load /boot/System.map-4.4.0-22-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.
Please install the linux-headers-4.4.0-22-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.
Please install the linux-headers-4.4.0-22-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.
Please install the linux-headers-4.4.0-22-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-22-generic
WARNING: missing /lib/modules/4.4.0-22-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-22-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_dJ1Z6g/lib/modules/4.4.0-22-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_dJ1Z6g/lib/modules/4.4.0-22-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Generating grub configuration file ...
grub-probe: error: not a directory.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
D020000: post_script_tasks - ensure_diversions
D000001: ensure_diversions: same, skipping
D020000: post_script_tasks - trig_incorporate
D000001: process queue pkg linux-image-4.4.0-22-generic:amd64 queue.len 0 progress 1, try 1
D000001: deferred_remove package linux-image-4.4.0-22-generic:amd64
D000001: checking dependencies for remove 'linux-image-4.4.0-22-generic:amd64'
D000040: checking depending package 'linux-image-extra-4.4.0-22-generic:amd64'
D000040: checking virtual package 'fuse-module'
D000040: checking virtual package 'ivtv-modules'
D000040: checking virtual package 'kvm-api-4'
D000040: checking virtual package 'linux-image'
D000040: checking virtual package 'redhat-cluster-modules'
D000040: checking virtual package 'spl-dkms'
D000040: checking virtual package 'virtualbox-guest-modules'
D000040: checking virtual package 'zfs-dkms'
Removing linux-image-4.4.0-22-generic (4.4.0-22.40) ...
D020000: trigproc_activate_packageprocessing pkg=linux-image-4.4.0-22-generic:amd64
D000001: removal_bulk package linux-image-4.4.0-22-generic:amd64
D000002: fork/exec /var/lib/dpkg/info/linux-image-4.4.0-22-generic.postrm ( remove )
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Generating grub configuration file ...
grub-probe: error: not a directory.
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-22-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
D020000: post_script_tasks - ensure_diversions
D000001: ensure_diversions: same, skipping
D020000: post_script_tasks - trig_incorporate
D010000: trigproc_run_deferred
Errors were encountered while processing:
 linux-image-extra-4.4.0-22-generic
 linux-image-4.4.0-22-generic

This run suggests that I am going to have to dig into the low level scripts to determine what is happening. There are really three problems here:

  • How did the database get corrupted in the first place?
  • Why can dpkg not recover from the error when trying to remove the packages?
  • What repair procedure is available.

I did a further run using the dpkg option --force remove-reinstreq with the following result.

jonathan@Aristotle:~$ sudo dpkg -D73773 --force remove-reinstreq -r linux-image-extra-4.4.0-22-generic linux-image-4.4.0-22-generic
[sudo] password for jonathan: 
D000001: ensure_diversions: new, (re)loading
D000001: process queue pkg linux-image-extra-4.4.0-22-generic:amd64 queue.len 1 progress 1, try 1
D000001: deferred_remove package linux-image-extra-4.4.0-22-generic:amd64
D000001: checking dependencies for remove 'linux-image-extra-4.4.0-22-generic:amd64'
(Reading database ... 235952 files and directories currently installed.)
Removing linux-image-extra-4.4.0-22-generic (4.4.0-22.40) ...
D020000: trigproc_activate_packageprocessing pkg=linux-image-extra-4.4.0-22-generic:amd64
D000001: removal_bulk package linux-image-extra-4.4.0-22-generic:amd64
D000002: fork/exec /var/lib/dpkg/info/linux-image-extra-4.4.0-22-generic.postrm ( remove )
depmod: FATAL: could not load /boot/System.map-4.4.0-22-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/dkms 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.
Please install the linux-headers-4.4.0-22-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.
Please install the linux-headers-4.4.0-22-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
Error! Your kernel headers for kernel 4.4.0-22-generic cannot be found.
Please install the linux-headers-4.4.0-22-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-22-generic
WARNING: missing /lib/modules/4.4.0-22-generic
Ensure all necessary drivers are built into the linux image!
depmod: ERROR: could not open directory /lib/modules/4.4.0-22-generic: No such file or directory
depmod: FATAL: could not search modules: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_g7jrQG/lib/modules/4.4.0-22-generic/modules.order: No such file or directory
depmod: WARNING: could not open /var/tmp/mkinitramfs_g7jrQG/lib/modules/4.4.0-22-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Generating grub configuration file ...
grub-probe: error: not a directory.
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
D020000: post_script_tasks - ensure_diversions
D000001: ensure_diversions: same, skipping
D020000: post_script_tasks - trig_incorporate
D000001: process queue pkg linux-image-4.4.0-22-generic:amd64 queue.len 0 progress 1, try 1
D000001: deferred_remove package linux-image-4.4.0-22-generic:amd64
D000001: checking dependencies for remove 'linux-image-4.4.0-22-generic:amd64'
D000040: checking depending package 'linux-image-extra-4.4.0-22-generic:amd64'
D000040: checking virtual package 'fuse-module'
D000040: checking virtual package 'ivtv-modules'
D000040: checking virtual package 'kvm-api-4'
D000040: checking virtual package 'linux-image'
D000040: checking virtual package 'redhat-cluster-modules'
D000040: checking virtual package 'spl-dkms'
D000040: checking virtual package 'virtualbox-guest-modules'
D000040: checking virtual package 'zfs-dkms'
Removing linux-image-4.4.0-22-generic (4.4.0-22.40) ...
D020000: trigproc_activate_packageprocessing pkg=linux-image-4.4.0-22-generic:amd64
D000001: removal_bulk package linux-image-4.4.0-22-generic:amd64
D000002: fork/exec /var/lib/dpkg/info/linux-image-4.4.0-22-generic.postrm ( remove )
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
update-initramfs: Deleting /boot/initrd.img-4.4.0-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 4.4.0-22-generic /boot/vmlinuz-4.4.0-22-generic
Generating grub configuration file ...
grub-probe: error: not a directory.
run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 1
Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-4.4.0-22-generic.postrm line 328.
dpkg: error processing package linux-image-4.4.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
D020000: post_script_tasks - ensure_diversions
D000001: ensure_diversions: same, skipping
D020000: post_script_tasks - trig_incorporate
D010000: trigproc_run_deferred
Errors were encountered while processing:
 linux-image-extra-4.4.0-22-generic
 linux-image-4.4.0-22-generic

The immediate problem seems to be that depmod encounters fatal errors because it cannot access the files /boot/System.map-4.4.0-22-generic and /lib/modules/4.4.0-22-generic which seem to have been deleted in an earlier run that then encountered a fatal error after deleting them.

This suggests that it will not b possible to determine the original cause of the situation and leaves us with two problems:

  • Why cannot dpkg with the --force remove-reinstreq option complete the process of removing these two files?
  • What repair procedure is available to recover from the current situation.

It seems to me that the first point might be treated as a bug in the dpkg system but I have not yet had the chance to see if this is the case. In any case it will be a potentially difficult problem to resolve because the database is now in a thoroughly inconsistent state as a result of the physical removal of these files without completing the removal process.

The second point is my current priority and I need to know if there is any way short of reinstalling Ubuntu to repair the database.

Does anyone have suggestions on how to address these issues.?

3 Answers 3

0

I completely crashed ubuntu 14.04 to a terminal only, removing meta-city.
Everything was re-installed with

sudo apt-get install --reinstall ubuntu-desktop

hope this helps!

0

Looks like grub is not properly configured. Take a look at this https://francisfisher.me.uk/problem/2013/grub-probe-error-not-a-directory-grub-1-99-in-ubuntu-linux-12-04/ try fixing grub and it should pass.

-1

This seems to be a bug where the removal script for the linux-image doesn't realise it's supposed to be removing it and instead tried to recreate the vmlinux files. Hopefully the bug will be fixed soon.

1
  • linux-image packages are not removed with autoremove. It was a deliberate decision.
    – Anwar
    Jul 17, 2016 at 8:44

You must log in to answer this question.

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