Apt 无法删除部分安装的内核,也无法安装任何其他软件包

Apt 无法删除部分安装的内核,也无法安装任何其他软件包

在看似部分内核升级后,Apt 无法升级或安装新软件包。我试过,apt-get purge -f linux-image-extra-3.19.0-22-generic但失败了,并显示非常相似的错误消息。机器在启动到最新内核版本(grub 中的默认版本)时也会崩溃,但以前的版本可以正常工作。

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be REMOVED:
  linux-image-3.19.0-22-generic linux-image-extra-3.19.0-22-generic
The following packages will be upgraded:
  linux-cloud-tools-common
1 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
2 not fully installed or removed.
Need to get 0 B/24.3 kB of archives.
After this operation, 208 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 453815 files and directories currently installed.)
Removing linux-image-extra-3.19.0-22-generic (3.19.0-22.22) ...
depmod: FATAL: could not load /boot/System.map-3.19.0-22-generic: No such file or directory
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/dkms 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
update-initramfs: Generating /boot/initrd.img-3.19.0-22-generic
grep: /boot/config-3.19.0-22-generic: No such file or directory
depmod: WARNING: could not open /tmp/mkinitramfs_6gldfB/lib/modules/3.19.0-22-generic/modules.order: No such file or directory
depmod: WARNING: could not open /tmp/mkinitramfs_6gldfB/lib/modules/3.19.0-22-generic/modules.builtin: No such file or directory
run-parts: executing /etc/kernel/postinst.d/pm-utils 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/unattended-upgrades 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
Generating grub configuration file ...
ERROR: cannot determine partition label for rootfs /dev/sda9
run-parts: /etc/kernel/postinst.d/zz-update-grub exited with return code 1
dpkg: error processing package linux-image-extra-3.19.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Removing linux-image-3.19.0-22-generic (3.19.0-22.22) ...
Examining /etc/kernel/postrm.d .
run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
update-initramfs: Deleting /boot/initrd.img-3.19.0-22-generic
run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.19.0-22-generic /boot/vmlinuz-3.19.0-22-generic
Generating grub configuration file ...
ERROR: cannot determine partition label for rootfs /dev/sda9
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-3.19.0-22-generic.postrm line 328.
dpkg: error processing package linux-image-3.19.0-22-generic (--remove):
 subprocess installed post-removal script returned error exit status 1
Errors were encountered while processing:
 linux-image-extra-3.19.0-22-generic
 linux-image-3.19.0-22-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

我需要让 apt 重新工作并进入可以安装​​未来内核的状态。正确清除 3.19.0-22 内核会很好但没有必要。欢迎询问更多信息,在此先行致谢

--编辑--

0x450 的答案适用于任何非内核相关的软件包。内核和 grub 更新使 apt 和 dpkg 恢复到损坏状态。我注意到这个反复出现的错误消息:

Generating grub configuration file ... ERROR: cannot determine partition label for rootfs /dev/sda9

这可能是与 grub 配置文件相关的问题吗?


sudo apt-get install --reinstall linux-image-extra-3.19.0-22-generic会导致非常相似的错误(可以查看这里

sudo dpkg --configure -a创建错误

sudo apt-get purge linux-image-extra-3.19.0-22-generic创建错误

答案1

我遇到了完全相同的问题,但损坏的内核包是 3.13.0.57 版本。

检查问题:

检查dpkg status包裹:

dpkg --status linux-image-3.19.0-22-generic
dpkg --status linux-image-extra-3.19.0-22-generic

如果输出表明软件包处于不良状态,即安装一半或者未完全安装,这意味着它们分别已经断裂apt-getdpkg

解决方案:

dpkg必须手动从状态文件中删除受感染的内核包的条目,apt-get以便内核dpkg本身能够再次正常运行。步骤如下:

  1. 确保创建状态文件的备份,以防万一出现问题。

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

  2. 使用您喜欢的文本编辑器打开/var/lib/dpkg/status并搜索并删除仅有的破损包裹的参考信息。您不得删除任何其他内容!

  3. 运行sudo apt-get updatesudo apt-get upgrade确保一切都已修复。

  4. 此步骤是可选的,因为包管理器不再跟踪这些包,但如果您愿意,可以通过删除它们来释放一些磁盘空间。您可以安全地手动删除和中的所有损坏内核包条目/boot/usr/src非常小心确保只触摸与3.19.0-22版本。

答案2

根本原因

根本问题似乎是/boot/System.map-3.19.0-22-generic缺少了它,从而阻止了数据包的重新配置/删除。

建议的解决方案

我最初的建议是 sudo apt-get install --reinstall linux-image-extra-3.19.0-22-generic

由于这显然失败了(“无法配置半安装”),我建议多做一些有力例如使用以下选项

sudo dpkg --remove --force-remove-reinstreq linux-image-extra-3.19.0-22-generic

该建议基于回答。

替代方案:手动修复?

或者,您也可以尝试手动修复该文件?也许它在尝试重新安装时被 apt-get 解压了?现在在我的系统上复制有点困难

答案3

我认为你应该跑

sudo dpkg --configure -a

接下来是已经提到过的:

sudo apt-get purge linux-image-extra-3.19.0-22-generic

答案4

您可以使用 remove 而不是 purge,然后升级内核,并在终端中输入以下内容:

 sudo apt-get -f remove linux-image-extra-3.19.0-22-generic

然后删除sources.list文件,进入设置,更新并孵化所有的chanoical列表并再次关闭它。

然后重新安装最新的内核,并在终端中输入:

sudo apt-get install linux-amd64_ linux-efi
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get install aptitude
sudo aptitude linux-efi

这样也许能很好地发挥作用。

相关内容