Ubuntu

手動刪除無法使用 apt/dpkg 刪除的包

  • July 29, 2021

我有一台裝有 WSL2/Ubuntu 20.04 的 PC。我最近嘗試在其上安裝一個軟體包(戴爾srvadmin軟體包)。由於 WSL2 沒有安裝,安裝已完成一半systemd

這使包處於半安裝/損壞狀態,我無法刪除/清除等。它與枯萎dpkgapt例如

tim@DESKTOP-Q35QTRS:~/interlocutor$ sudo dpkg -r --force-all srvadmin-hapi
(Reading database ... 54160 files and directories currently installed.)
Removing srvadmin-hapi (9.3.2) ...
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
dpkg: error processing package srvadmin-hapi (--remove):
installed srvadmin-hapi package pre-removal script subprocess returned error exit status 1
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
dpkg: error while cleaning up:
installed srvadmin-hapi package post-installation script subprocess returned error exit status 1
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Errors were encountered while processing:
srvadmin-hapi
tim@DESKTOP-Q35QTRS:~/interlocutor$

那麼我是否可以手動執行dpkg未能執行的步驟或以其他方式刪除損壞的包?

編輯,並作為第二行/var/lib/dpkg/info/srvadmin-hapi.prerm插入(即緊接在該行之後)。需要以 root 身份編輯此腳本。set -x``#!

然後dpkg -r --force-all srvadmin-hapi再次執行。這將向您展示 .prerm 腳本中發生了什麼,以及哪個命令失敗了。這應該為您提供足夠的資訊來解決問題並刪除軟體包。

或者,對於蠻力“修復”,如果它看起來不像 .prerm 做的很重要(或者如果它做的唯一重要的事情是執行systemctl stop srvadmin-hapisystemctl status類似的事情),那麼只需插入exit 0作為第二行.prerm 腳本。然後,您應該能夠清除包裝而不會出現其他問題。

引用自:https://unix.stackexchange.com/questions/662447