Somehow two packages (that I don't want anymore) got corrupted after a file system check and are now missing files.

I installed and initialized debsums and when I run it it gives a load of missing files (and only missing files).

I tried these commands (found all over the place):

  • sudo apt upgrade
  • sudo apt autoremove
  • sudo apt install brscan4
  • sudo apt remove brscan4
  • sudo dpkg --configure -a
  • sudo apt install --reinstall brscan4
  • sudo apt install -f --reinstall brscan4
  • sudo apt-get -f install (without package name)
  • sudo dpkg --remove --force-remove-reinstreq brscan4
  • sudo apt-get purge --remove brscan4
  • [added] dpkg -P brscan4

Notably, dpkg --configure -a seems to be recommended everywhere as if it's the final last-resort solution that's supposed to fix it.

They all give the exact same error:

Removing brscan4 (0.4.4-3) ...
/var/lib/dpkg/info/brscan4.prerm: 3: /var/lib/dpkg/info/brscan4.prerm: /opt/brother/scanner/brscan4/setupSaneScan4: not found
dpkg: error processing package brscan4 (--remove): installed brscan4 package pre-removal script subprocess returned error exit status 127

These commands do nothing to the corrupted packages:

  • sudo apt update
  • sudo apt update --fix-missing

How can I fix this short of reinstalling Ubuntu from scratch? (his final solution, see chat)

  • What do the commands dpkg -l brscan4, dpkg -L brscan4 say? – George Udosen Feb 13 '19 at 9:09
  • Try these commands in sequence, sudo apt autoremove followed by sudo apt update. Then, run sudo apt upgrade. – devGeek Feb 13 '19 at 9:22

When prerm/postrm/postinst are failing, you need to remove the package with more low-level tools, as apt will stop on this error.

The first try is to use dpkg -P brscan4 and when it works install brscan4 again using apt.

If still nothing works, edit the paths like /var/lib/dpkg/info/brscan4.prerm and insert exit 0 as second line. The script will not run and not produce an error. After that, reinstalling will probably fix the errors and the re-installed script hopefully runs without problems.

| improve this answer | |
  • sudo dpkg -P brscan4: same error again. – Mark Jeronimus Feb 13 '19 at 11:07
  • Then try the exit 0 method. Check afterwards, if the scripts got replaced and if not remove the exit 0 line yourself and possibly reinstall the package (to run the script in an appropriate way, once all needed files are there again). – allo Feb 13 '19 at 11:08
  • Thx, that did the trick. I just had to execute the apt remove command and edit every .prerm and .postinst file it threw at me and empty it, until the remove works. Repeat for other packages. – Mark Jeronimus Feb 13 '19 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.