Debian:使用 dpkg 修复损坏的 apt

Debian:使用 dpkg 修复损坏的 apt

我的一个 Raspberry Pi(运行 OSMC 的 Pi 2)出现更新错误。尝试执行手动 dist 升级失败,并在 apt 软件包本身上出现可疑错误:

Preconfiguring packages ...
/tmp/ca-certificates.config.M9vjue: 70: /tmp/ca-certificates.config.M9vjue: uniq: not found
ca-certificates failed to preconfigure, with exit status 127
(Reading database ... 30176 files and directories currently installed.)
Preparing to unpack .../archives/apt_1.4.11_armhf.deb ...
/usr/bin/dpkg-maintscript-helper: 588: /usr/bin/dpkg-maintscript-helper: basename: not found
dpkg: warning: subprocess old pre-removal script returned error exit status 127
dpkg: trying script from the new package instead ...
/usr/bin/dpkg-maintscript-helper: 588: /usr/bin/dpkg-maintscript-helper: basename: not found
dpkg: error processing archive /var/cache/apt/archives/apt_1.4.11_armhf.deb (--unpack):
 subprocess new pre-removal script returned error exit status 127
Failed to try-restart apt-daily-upgrade.timer: Unit apt-daily-upgrade.timer is masked.
Failed to try-restart apt-daily.timer: Unit apt-daily.timer is masked.
/usr/bin/dpkg-maintscript-helper: 588: /usr/bin/dpkg-maintscript-helper: basename: not found
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
 /var/cache/apt/archives/apt_1.4.11_armhf.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

进一步检查确认 apt 已损坏:

$ sudo dpkg --configure -a
Processing triggers for libc-bin (2.24-11+deb9u4) ...
dpkg: error processing package apt (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Errors were encountered while processing:
 apt

删除 APT(例如dpkg -r)进行重新安装并不是一个真正的选择,因为rbp2-设备-osmc依赖于取决于apt-utils,所以它会导致系统崩溃。

如何在不擦除整个安装的情况下恢复 apt?

答案1

跑步:

sudo dpkg --unpack /var/cache/apt/archives/apt_1.4.11_armhf.deb
sudo dpkg --configure apt

或重新安装apt

wget http://ftp.univ-nantes.fr/debian-security/pool/updates/main/a/apt/apt_1.4.11_armhf.deb
sudo dpkg -i apt_1.4.11_armhf.deb

man dpkg:

--unpack package-file...
      Unpack the package, but don't configure it. If --recursive or -R 
      option is  specified,  package-file  must  refer  to  a  directory instead.

答案2

事实证明 AB 是对的 - coreutils 出了问题,重新安装它解决了这个问题:

# dpkg -i /var/cache/apt/archives/coreutils_8.26-3_armhf.deb
(Reading database ... 30176 files and directories currently installed.)
Preparing to unpack .../coreutils_8.26-3_armhf.deb ...
Unpacking coreutils (8.26-3) over (8.26-3) ...
Setting up coreutils (8.26-3) ...

接下来的 apt-get dist-upgrade 进展非常成功。我现在的猜测是,导致 Kodi 悲伤面孔循环的同一问题可能损坏了 microSD 文件系统,该系统在常规自动自检过程中丢失了太多块,导致部分 coreutils 丢失。

谢谢AB!!

相关内容