apt / dpkg: Ignore error in post-install script
You have been warned
This post shows how to cripple the installation of a Debian package, and make the system think it went through OK. This might very well bring your system’s behavior towards the exotic, unless you know perfectly what you’re doing.
In some few cases, like the one shown below, it might actually be a good idea.
Introduction
Sometimes the post-installation script of Debian packages fails for a good reason. So good that one wants to ignore the failure, and mark the package as installed, so its dependencies are in place. And so apt stops nagging about it.
On my Linux Mint 19 machine, this happened to me with grub-efi-amd64: Its installation involves updating something in /boot, which is mounted read-only, exactly for that reason: The system boots perfectly, why fiddle?
And indeed, it’s not fully installed (note the iF part):
$ dpkg -l grub-efi-amd64
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=====================================================-===============================-===============================-================================================================================================================
iF grub-efi-amd64 2.02-2ubuntu8.13 amd64 GRand Unified Bootloader, version 2 (EFI-AMD64 version)
There must be an easy way around it…?
OK, so how about giving it a push?
# dpkg --configure --force-all grub-efi-amd64 Setting up grub-efi-amd64 (2.02-2ubuntu8.13) ... Installing for x86_64-efi platform. grub-install: error: cannot delete `/boot/grub/x86_64-efi/lsacpi.mod': Read-only file system. Failed: grub-install --target=x86_64-efi WARNING: Bootloader is not properly installed, system may not be bootable cp: cannot create regular file '/boot/grub/unicode.pf2': Read-only file system dpkg: error processing package grub-efi-amd64 (--configure): installed grub-efi-amd64 package post-installation script subprocess returned error exit status 1 Errors were encountered while processing: grub-efi-amd64
Not only didn’t it work, but this error message appears every time I try installing anything with apt. It will always attempt to finish that installation. And fail.
After quite some googling, I’m convinced that there’s no way to tell apt or dpkg to ignore a failed post-installation. Not with a million warnings and confirmations. Nothing. The post installation must succeed, by hook or by crook. The packaging machinery simply won’t register a package as fully installed otherwise.
Maybe apt-mark?
Ehm, the truth is I wasn’t aware of this utility when I went through this. So maybe apt-mark can be used to mark the relevant package as installed, and that’s it. Will update if I run into a similar issue again.
The ugly fix
So that leaves us with the crook. Luckily, the script in question is in a known place, waiting to be edited:
# vi /var/lib/dpkg/info/grub-efi-amd64.postinst
For any other package, just replace the grub-efi-amd64 with what you have.
And just add an “exit 0″ as shown below. This makes the script return with success, without doing anything. You may want to examine what it would do, possibly perform some of the operations manually etc. But anyhow, it’s just this:
#!/bin/bash set -e exit 0; [ ... ]
And then try again:
# dpkg --configure grub-efi-amd64 Setting up grub-efi-amd64 (2.02-2ubuntu8.13) ...
Like a charm, of course. And now the package is happily installed:
$ dpkg -l grub-efi-amd64
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=================================
ii grub-efi-amd64 2.02-2ubuntu amd64 GRand Unified Bootloader, version
And don’t forget to remove that edit afterwards. Or possibly it might cause issues in the future…?
Reader Comments
wow, thanks.
this dirty but simple trick did it for me. Where everything else failed. finally I got secure boot again!
yeah, don’t forget to remove it afterwards and do a dpkg-reconfigure on the packages affected.
Thanks! This has been plaguing me on virtual servers. I tried apt-mark hold grub-efi-amd64-signed and shim-signed and I get warnings but at least apt-get works again.
Isso funciona lindamente!