1

I have a PC with WSL2/Ubuntu 20.04. I recently tried installing a package on it (the Dell srvadmin package). The installation fell over half way through as WSL2 doesn't have systemd on it.

This has left the package in a half-installed/broken status and I can't remove/purge etc. it with wither dpkg or apt e.g.

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$

So is it possible for me to manually do the steps that dpkg is failing to do or otherwise somehow remove the broken package?

TimGJ
  • 225
  • 3
  • 9
  • Further to @cas answer below, I edited `/var/lib/dpkg/info/srvadmin-hapi.prerm` and altered the `set -e` command to a `set -x` and ran the `dpkg` command. Not only did this give me way more information, it actually uninstalled the package. The `set -e` was causing the script to abort when it got any non-zero return code. – TimGJ Jul 29 '21 at 09:20

1 Answers1

3

Edit /var/lib/dpkg/info/srvadmin-hapi.prerm, and insert set -x as the second line (i.e. immediately after the #! line). Editing this script will need to be done as root.

Then run dpkg -r --force-all srvadmin-hapi again. This will show you what's happening inside the .prerm script, and exactly which command is failing. That should give you enough info to fix the problem and remove the package.

Alternatively, for a brute-force "fix", if it doesn't look like the .prerm doing much important (or if the only significant thing it does is to execute systemctl stop srvadmin-hapi or systemctl status or similar), then just insert exit 0 as the second line of the .prerm script. You should then be able to purge the package without further problems.

cas
  • 1
  • 7
  • 119
  • 185
  • 1
    BTW, this answer assumes that the package's `.{pre,post}{inst,rm}` executable is a shell script. Almost all of them are, 99.9999+%. Several are perl scripts instead. At least one is a compiled binary (bash's .preinst). There may be others written in other languages, but I don't know of any (and couldn't find any running `file` on the package scripts in my own `/var/lib/dpkg/info/` directories....but there are tens of thousands of packages I **haven't** installed on my systems and my curiosity isn't strong enough to unpack and examine all the .deb files in my local mirror) – cas Jul 30 '21 at 16:53