Unable to remove (ksh) package in Ubuntu 18.04 Bionic due to missing binfmt-support package

Written by - 0 comments

Published on - Listed in Linux


On an Ubuntu 18.04 (Bionic), the following problem showed up when I was trying to remove a package (ksh) using apt:

root@bionic:~# apt-get remove ksh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  ksh
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 3,384 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 52797 files and directories currently installed.)
Removing ksh (93u+20120801-3.1ubuntu1) ...
/var/lib/dpkg/info/ksh.prerm: 11: /var/lib/dpkg/info/ksh.prerm: update-binfmts: not found
dpkg: error processing package ksh (--remove):
 installed ksh package pre-removal script subprocess returned error exit status 127
Errors were encountered while processing:
 ksh
E: Sub-process /usr/bin/dpkg returned an error code (1)

A deb package pre-removal (pkg.prerm) script

The failure comes from the so-called Debian package pre-remove (prerm) definition. This is a shell script launched before the package's files are deleted from the system:

root@bionic:~# cat /var/lib/dpkg/info/ksh.prerm
#!/bin/sh

set -e

case "$1" in
    remove|deconfigure)
        update-alternatives --remove ksh /bin/ksh93
    # remove compatibility symlink if broken
    test '!' -h /usr/bin/ksh || test -e /usr/bin/ksh || rm -f /usr/bin/ksh

    update-binfmts --package ksh --remove ksh /bin/ksh93
    ;;

    upgrade|failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 0
    ;;
esac



exit 0

The pre-removal script of the ksh package wants to run the update-binfmts command. But update-binfmts can cause problems in LXC containers, hence this package was removed a while ago:

root@bionic:~# dpkg -l|grep binfmt
rc  binfmt-support      2.1.8-2         amd64        Support for extra binary formats

This missing command now leads to an error inside the pre-removal script of the ksh package. Because it uses set -e, it fails and exits immediately. apt receives the error exit code and stops the package removal. apt now runs into a situation which cannot be fixed by itself.

Fixing the pre-removal script

In this situation, the pre-removal script of the affected package needs to be adjusted. By commenting (disabling) the update-binfmts command, the pre-removal script should run through just fine and allow the removal of the package:

root@bionic:~# sed -i "s/update-binfmts/#update-binfmts/" /var/lib/dpkg/info/ksh.prerm
root@bionic:~# cat /var/lib/dpkg/info/ksh.prerm | grep binfmt
    #update-binfmts --package ksh --remove ksh /bin/ksh93

root@bionic:~# apt-get remove ksh
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  ksh
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 3,384 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 52797 files and directories currently installed.)
Removing ksh (93u+20120801-3.1ubuntu1) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...

root@bionic:~# dpkg -l|grep ksh
rc  ksh   93u+20120801-3.1ubuntu1    amd64    Real, AT&T version of the Korn shell

 

VoilĂ , ksh package now successfully removed.

This method (fixing/adjusting the pre-removal script) should also apply to other packages which require certain (non-existant) commands.

What about newer ksh packages?

The problem described above happend with the ksh package in Ubuntu 18.04 (Bionic). Taking a look at the ksh package in Ubuntu 20.04 (Focal), this problem should not occur in Ubuntu 20.04 anymore. The pre-removal script now contains a check, that the update-binfmts command actually exists:

     if command -v update-binfmts >/dev/null; then
        test -e /var/lib/binfmts/ksh && \
            update-binfmts --package ksh --remove ksh \
            /bin/ksh || true
    fi



Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Office   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder