由于 linux 映像/固件问题,apt/dpkg 无法工作

由于 linux 映像/固件问题,apt/dpkg 无法工作

我最近安装了 Debian 12。Apt 可以工作,但抱怨未完全配置 linux 映像。我尝试删除映像并升级,但现在我无法使用 apt 或 dpkg 删除或安装任何内容。它存在“未完全安装或删除”软件包的问题,​​在尝试解决该问题时遇到错误,然后中止。

总结一下我遇到的问题(详情如下):

  • 无法 apt/dpkg 删除、清除、安装或升级
  • dpkg 删除后脚本子进程返回错误
  • raspi-firmware 抱怨 /boot/firmware 可能无法安装
  • 我确实有一个 1K EXT4-fs 分区未安装
  • raspi-firmware - 我需要这个吗?运行 Panasonic Toughbook CF-31
  • initramfs-tools - 如果我只是删除 raspi-firmware 就会抱怨

我正在使用内核 6.1.0-9-amd64,但由于 linux-image-6.1.0-10-amd64 而遇到这些问题。根据我在网上找到的信息,我手动删除了与后一个包关联的所有文件,但仍然收到错误。 (dpkg-query -L linux-image-6.1.0-10-amd64 验证该包确实“不包含任何文件”)

这是尝试安装或删除任何软件包时 apt 返回的输出示例:

Reading package lists...
Building dependency tree...
Reading state information...
Suggested packages:
  cmatrix-xfont
The following packages will be REMOVED:
  linux-image-6.1.0-10-amd64
The following NEW packages will be installed:
  cmatrix
0 upgraded, 1 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
Need to get 17.5 kB of archives.
After this operation, 408 MB disk space will be freed.
Do you want to continue? [Y/n]
Get:1 https://deb.debian.org/debian bookworm/main amd64 cmatrix amd64 2.0-3 [17.5 kB]
Fetched 17.5 kB in 1s (12.3 kB/s)
(Reading database ... 252302 files and directories currently installed.)
Removing linux-image-6.1.0-10-amd64 (6.1.37-1) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-6.1.0-10-amd64
/etc/kernel/postrm.d/z50-raspi-firmware:
raspi-firmware: missing /boot/firmware, did you forget to mount it?
run-parts: /etc/kernel/postrm.d/z50-raspi-firmware exited with return code 1
dpkg: error processing package linux-image-6.1.0-10-amd64 (--remove):
 installed linux-image-6.1.0-10-amd64 package post-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
Errors were encountered while processing:
 linux-image-6.1.0-10-amd64
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

按照它所说的内容,我会看到 /etc/kernel/postinst.d/z50-raspi-firmware 的第 35 行,当以下条件成立时,会抛出错误:

! mountpoint -q /boot/firmware

我不熟悉 -q 在这种情况下的含义。我没有从 chroot 或虚拟机运行 dpkg。我的根分区中有 /boot/firmware 目录。如果相关的话,我确实有一个未挂载的 1K Ext4-fs 分区 sda2,它无法挂载,并显示 dmesg 报告:“无法读取超级块”。

由于我没有运行 Rasberry Pi,因此我尝试删除这些文件并运行 apt autoremove,

  • /etc/initramfs/post-update.d/z50-raspi-firmware
  • /etc/kernel/postrm.d/z50-raspi-固件

但阿普说:

Removing linux-image-6.1.0-10-amd64 (6.1.37-1) ...
/etc/kernel/postrm.d/initramfs-tools:
update-initramfs: Deleting /boot/initrd.img-6.1.0-10-amd64
/etc/kernel/postrm.d/z50-raspi-firmware:
/etc/kernel/postrm.d/z50-raspi-firmware: 2: exec: /etc/kernel/postins
t.d/z50-raspi-firmware: not found
run-parts: /etc/kernel/postrm.d/z50-raspi-firmware exited with return
 code 127

似乎有什么东西告诉 initramfs-tools 期望找到 raspi-firmware。我看到 dpkg-query -L 包括 /usr/share/initramfs-tools/hooks/raspi-firmware-fsck 并尝试删除它,但没有什么区别。

我看到了类似的问题,但解决方案对我来说还不够。我是堆栈交换的新手,我不确定如何或是否应将这个问题附加到该问题上。 dpkg:处理包 linux-image-amd64 时出错(--configure):依赖性问题 - 未配置

答案1

为了使链接问题中的解决方案发挥作用,必须首先恢复 postinst.d/z50-raspi-formware。

创建/etc/kernel/postinst.d/z50-raspi-firmware由两行组成的:

#!/bin/sh
true

使其可执行:

chmod a=rx /etc/kernel/postinst.d/z50-raspi-firmware

然后清除应该起作用:

apt purge raspi-firmware

完成此操作后,我可以毫无错误地运行 apt autoremoveinstall等等。

相关内容