apt autoremove 无法删除 linux-image 软件包

apt autoremove 无法删除 linux-image 软件包

我似乎损坏了我的 apt 数据库,我不知道如何修复它。它在每个涉及的命令上都失败了linux-image-4.4.0-22-generic and linux-image-extra-4.4.0-22-generic。这是运行后的控制台输出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: 子进程 /usr/bin/dpkg 返回错误代码 (1)

我添加了使用完整调试的 dpkg 运行,其中我尝试删除 linux-image-4.4.0-22-generic 和 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

这次运行表明我必须深入研究低级脚本来确定发生了什么。这里实际上有三个问题:

  • 数据库一开始是如何被破坏的?
  • 为什么dpkg尝试删除包时无法从错误中恢复?
  • 有哪些修复程序可用。

我使用 dpkg 选项 --force remove-reinstreq 进行了进一步运行,结果如下。

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

眼前的问题似乎是depmod遇到致命错误,因为它无法访问在之前的运行中似乎已被删除的文件/boot/System.map-4.4.0-22-generic and /lib/modules/4.4.0-22-generic,删除这些文件后又遇到致命错误。

这表明我们不可能确定这种情况的根本原因,并给我们留下两个问题:

  • 为什么使用 --force remove-reinstreq 选项的 dpkg 无法完成删除这两个文件的过程?
  • 有哪些修复程序可以恢复当前状况。

在我看来,第一点可能被视为 dpkg 系统的一个错误,但我还没有机会看到是否确实如此。无论如何,这将是一个难以解决的问题,因为由于在没有完成删除过程的情况下物理删除了这些文件,数据库现在处于完全不一致的状态。

第二点是我当前的首要任务,我需要知道除了重新安装 Ubuntu 之外是否有其他方法来修复数据库。

有人对如何解决这些问题有什么建议吗?

答案1

我彻底让 ubuntu 14.04 崩溃,只剩一个终端,删除了 meta-city。
一切都重新安装了

sudo apt-get install --reinstall ubuntu-desktop

希望这可以帮助!

答案2

看起来 grub 配置不正确。看看这个https://francisfisher.me.uk/problem/2013/grub-probe-error-not-a-directory-grub-1-99-in-ubuntu-linux-12-04/尝试修复 grub 并且它应该可以通过。

答案3

这似乎是一个错误,linux-image 的删除脚本没有意识到它应该删除它,而是试图重新创建 vmlinux 文件。希望这个错误能尽快修复。

相关内容