How to install i386/amd64 packages on ARM or any other arch from Ubuntu Ports

I need to run some x86 binary with QEMU on a Raspberry Pi (armhf port, ARMv7) to make a printer work with Canon’s crappy binary UFRII drivers. How to just install its x86 dependencies on armhf (not how to run them)?

I can install the x86 binary with:

root@raspberry-pi:~# dpkg --force-architecture -i /tmp/cnrdrvcups-ufr2-uk_5.10-1_i386.deb

but then apt keeps complaining that its dependencies are missing. I’ll probably actually need them to run the UFRII converter—so I’d really like to install the i386 dependencies via apt.

I can add the i386 architecture but apt-get update fails to download some resources, probably because armhf resides on ports.ubuntu.com while x86 packages are on the main mirrors. (I’ve once successfully installed i386 packages on amd64 before.)

root@raspberry-pi:~# dpkg --add-architecture i386       
root@raspberry-pi:~# apt-get update                  
Hit:1 http://ports.ubuntu.com/ubuntu-ports bionic InRelease
Get:2 http://ports.ubuntu.com/ubuntu-ports bionic-updates InRelease [88.7 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports bionic-backports InRelease [74.6 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports bionic-security InRelease [88.7 kB]
Ign:5 http://ports.ubuntu.com/ubuntu-ports bionic/main i386 Packages
Ign:6 http://ports.ubuntu.com/ubuntu-ports bionic/restricted i386 Packages
Ign:7 http://ports.ubuntu.com/ubuntu-ports bionic/universe i386 Packages
Ign:8 http://ports.ubuntu.com/ubuntu-ports bionic/multiverse i386 Packages
Ign:5 http://ports.ubuntu.com/ubuntu-ports bionic/main i386 Packages
Ign:6 http://ports.ubuntu.com/ubuntu-ports bionic/restricted i386 Packages
Ign:7 http://ports.ubuntu.com/ubuntu-ports bionic/universe i386 Packages
Ign:8 http://ports.ubuntu.com/ubuntu-ports bionic/multiverse i386 Packages
Ign:5 http://ports.ubuntu.com/ubuntu-ports bionic/main i386 Packages
Ign:6 http://ports.ubuntu.com/ubuntu-ports bionic/restricted i386 Packages
Ign:7 http://ports.ubuntu.com/ubuntu-ports bionic/universe i386 Packages
Ign:8 http://ports.ubuntu.com/ubuntu-ports bionic/multiverse i386 Packages
Err:5 http://ports.ubuntu.com/ubuntu-ports bionic/main i386 Packages
  404  Not Found [IP: 91.189.88.150 80]
Ign:6 http://ports.ubuntu.com/ubuntu-ports bionic/restricted i386 Packages
Ign:7 http://ports.ubuntu.com/ubuntu-ports bionic/universe i386 Packages
Ign:8 http://ports.ubuntu.com/ubuntu-ports bionic/multiverse i386 Packages
Ign:9 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main i386 Packages
Ign:10 http://ports.ubuntu.com/ubuntu-ports bionic-updates/restricted i386 Packages
Ign:11 http://ports.ubuntu.com/ubuntu-ports bionic-updates/universe i386 Packages
Ign:12 http://ports.ubuntu.com/ubuntu-ports bionic-updates/multiverse i386 Packages
Ign:9 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main i386 Packages
Ign:10 http://ports.ubuntu.com/ubuntu-ports bionic-updates/restricted i386 Packages
Ign:11 http://ports.ubuntu.com/ubuntu-ports bionic-updates/universe i386 Packages
Ign:12 http://ports.ubuntu.com/ubuntu-ports bionic-updates/multiverse i386 Packages
Ign:9 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main i386 Packages
Ign:10 http://ports.ubuntu.com/ubuntu-ports bionic-updates/restricted i386 Packages
Ign:11 http://ports.ubuntu.com/ubuntu-ports bionic-updates/universe i386 Packages
Ign:12 http://ports.ubuntu.com/ubuntu-ports bionic-updates/multiverse i386 Packages
Err:9 http://ports.ubuntu.com/ubuntu-ports bionic-updates/main i386 Packages
  404  Not Found [IP: 91.189.88.150 80]
Ign:10 http://ports.ubuntu.com/ubuntu-ports bionic-updates/restricted i386 Packages
Ign:11 http://ports.ubuntu.com/ubuntu-ports bionic-updates/universe i386 Packages
Ign:12 http://ports.ubuntu.com/ubuntu-ports bionic-updates/multiverse i386 Packages
Ign:13 http://ports.ubuntu.com/ubuntu-ports bionic-backports/main i386 Packages
Ign:14 http://ports.ubuntu.com/ubuntu-ports bionic-backports/universe i386 Packages
Ign:13 http://ports.ubuntu.com/ubuntu-ports bionic-backports/main i386 Packages
Ign:14 http://ports.ubuntu.com/ubuntu-ports bionic-backports/universe i386 Packages
Ign:13 http://ports.ubuntu.com/ubuntu-ports bionic-backports/main i386 Packages
Ign:14 http://ports.ubuntu.com/ubuntu-ports bionic-backports/universe i386 Packages
Err:13 http://ports.ubuntu.com/ubuntu-ports bionic-backports/main i386 Packages
  404  Not Found [IP: 91.189.88.150 80]
Ign:14 http://ports.ubuntu.com/ubuntu-ports bionic-backports/universe i386 Packages
Ign:15 http://ports.ubuntu.com/ubuntu-ports bionic-security/main i386 Packages
Ign:16 http://ports.ubuntu.com/ubuntu-ports bionic-security/restricted i386 Packages
Ign:17 http://ports.ubuntu.com/ubuntu-ports bionic-security/universe i386 Packages
Ign:18 http://ports.ubuntu.com/ubuntu-ports bionic-security/multiverse i386 Packages
Ign:15 http://ports.ubuntu.com/ubuntu-ports bionic-security/main i386 Packages
Ign:16 http://ports.ubuntu.com/ubuntu-ports bionic-security/restricted i386 Packages
Ign:17 http://ports.ubuntu.com/ubuntu-ports bionic-security/universe i386 Packages
Ign:18 http://ports.ubuntu.com/ubuntu-ports bionic-security/multiverse i386 Packages
Ign:15 http://ports.ubuntu.com/ubuntu-ports bionic-security/main i386 Packages
Ign:16 http://ports.ubuntu.com/ubuntu-ports bionic-security/restricted i386 Packages
Ign:17 http://ports.ubuntu.com/ubuntu-ports bionic-security/universe i386 Packages
Ign:18 http://ports.ubuntu.com/ubuntu-ports bionic-security/multiverse i386 Packages
Err:15 http://ports.ubuntu.com/ubuntu-ports bionic-security/main i386 Packages
  404  Not Found [IP: 91.189.88.150 80]
Ign:16 http://ports.ubuntu.com/ubuntu-ports bionic-security/restricted i386 Packages
Ign:17 http://ports.ubuntu.com/ubuntu-ports bionic-security/universe i386 Packages
Ign:18 http://ports.ubuntu.com/ubuntu-ports bionic-security/multiverse i386 Packages
Fetched 252 kB in 2s (112 kB/s)
Reading package lists... Done
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic/main/binary-i386/Packages  404  Not Found [IP: 91.189.88.150 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic-updates/main/binary-i386/Packages  404  Not Found [IP: 91.189.88.150 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic-backports/main/binary-i386/Packages  404  Not Found [IP: 91.189.88.150 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/dists/bionic-security/main/binary-i386/Packages  404  Not Found [IP: 91.189.88.150 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.

How to fix this? I probably need to adjust/add something to /etc/apt/sources.list but that doesn’t contain the strings i386/amd64. So I don’t know where to start. This is my current sources file:

## Note, this file is written by cloud-init on first boot of an instance
## modifications made here will not survive a re-bundle.
## if you wish to make changes you can:
## a.) add 'apt_preserve_sources_list: true' to /etc/cloud/cloud.cfg
##     or do the same in user-data
## b.) add sources in /etc/apt/sources.list.d
## c.) make changes to template file /etc/cloud/templates/sources.list.tmpl

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ports.ubuntu.com/ubuntu-ports bionic main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ports.ubuntu.com/ubuntu-ports bionic-updates main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports bionic universe
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic universe
deb http://ports.ubuntu.com/ubuntu-ports bionic-updates universe
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://ports.ubuntu.com/ubuntu-ports bionic multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic multiverse
deb http://ports.ubuntu.com/ubuntu-ports bionic-updates multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://ports.ubuntu.com/ubuntu-ports bionic-backports main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-backports main restricted universe multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu bionic partner
# deb-src http://archive.canonical.com/ubuntu bionic partner

deb http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports bionic-security universe
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security universe
deb http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports bionic-security multiverse

I found the question How to install i386 packages on Ubuntu on ARM-based Nexus 7? but people there just answer that running x86 on ARM isn’t possible. That’s true but not the correct answer to the original question.

Update: This is the output of dpkg-deb for the desired driver package including its 1st level dependencies:

root@raspberry-pi:~# dpkg-deb --info /tmp/cnrdrvcups-ufr2-uk_5.10-1_i386.deb 
 new Debian package, version 2.0.
 size 21503884 bytes: control archive=20743 bytes.
    2058 bytes,    16 lines      control              
   62636 bytes,   896 lines      md5sums              
     339 bytes,    17 lines   *  postinst             #!/bin/sh
      90 bytes,     9 lines   *  postrm               #!/bin/sh
 Package: cnrdrvcups-ufr2-uk
 Version: 5.10-1
 Section: net
 Priority: optional
 Architecture: i386
 Depends: cupsys | cups, libcups2 | libcupsys2 (>= 1.2.7)
 Conflicts: cnrcupsiradv715zk, cnrcupsiradv615zk, cnrcupsiradv525zk, cnrcupsiradv7153zk, cnrcupsiradv6153zk, cnrcupsiradv5253zk, cnrcupsiradv85053zk, cnrcupsiradv85853zk, cnrcupsiradv65753zk, cnrcupsiradv65553zk, cnrcupsiradvc35203zk, cnrcupsiradvc35253zk, cnrcupsiradvc75803zk, cnrcupsiradvc75653zk, cnrcupsiradvc2563zk, cnrcupsiradvc55353zk, cnrcupsiradvc55503zk, cnrcupsiradv45453zk, cnrcupsiradv45253zk, cnrcupsiradvc4753zk, cnrcupswg7000zk, cnrcupswg7000zzk, cnrcupslbp853czk, cnrcupslbp852czk, cnrcupsd1600zk
 Replaces: cnrdrvcups-ufr2-us, cnrdrvcups-lipslx, cnrcupsiradv715zk, cnrcupsiradv615zk, cnrcupsiradv525zk, cnrcupsiradv7153zk, cnrcupsiradv6153zk, cnrcupsiradv5253zk, cnrcupsiradv85053zk, cnrcupsiradv85853zk, cnrcupsiradv65753zk, cnrcupsiradv65553zk, cnrcupsiradvc35203zk, cnrcupsiradvc35253zk, cnrcupsiradvc75803zk, cnrcupsiradvc75653zk, cnrcupsiradvc2563zk, cnrcupsiradvc55353zk, cnrcupsiradvc55503zk, cnrcupsiradv45453zk, cnrcupsiradv45253zk, cnrcupsiradvc4753zk, cnrcupswg7000zk, cnrcupswg7000zzk, cnrcupslbp853czk, cnrcupslbp852czk, cnrcupsd1600zk
 Provides: cnrcupsiradv715zk, cnrcupsiradv615zk, cnrcupsiradv525zk, cnrcupsiradv7153zk, cnrcupsiradv6153zk, cnrcupsiradv5253zk, cnrcupsiradv85053zk, cnrcupsiradv85853zk, cnrcupsiradv65753zk, cnrcupsiradv65553zk, cnrcupsiradvc35203zk, cnrcupsiradvc35253zk, cnrcupsiradvc75803zk, cnrcupsiradvc75653zk, cnrcupsiradvc2563zk, cnrcupsiradvc55353zk, cnrcupsiradvc55503zk, cnrcupsiradv45453zk, cnrcupsiradv45253zk, cnrcupsiradvc4753zk, cnrcupswg7000zk, cnrcupswg7000zzk, cnrcupslbp853czk, cnrcupslbp852czk, cnrcupsd1600zk
 Installed-Size: 76096
 Maintainer: CANON INC. <[email protected]>
 Source: cnrdrvcups-lb
 Description: Canon UFR2 Printer Driver for Linux
  Canon UFR2 Printer Driver for Linux.
  This UFR2 printer driver provides printing functions for Canon LBP/iR
  printers operating under the CUPS (Common UNIX Printing System) environment.

Solution 1:

I later found out by trial & error that you need to make the default entries in /etc/apt/sources.list more specific:

dpkg --add-architecture 'i386'

# replace 'deb' with 'deb [arch=armhf]'
sed 's/^deb http/deb [arch=armhf] http/' -i '/etc/apt/sources.list'

Add a file like /etc/apt/sources.list.d/i386.list with the x86 mirror servers:

deb [arch=i386] http://security.ubuntu.com/ubuntu/ focal-security  main restricted universe multiverse
deb [arch=i386]  http://archive.ubuntu.com/ubuntu/ focal           main restricted universe multiverse
deb [arch=i386]  http://archive.ubuntu.com/ubuntu/ focal-updates   main restricted universe multiverse
deb [arch=i386]  http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
apt-get update

I could successfully install and run the UFRII driver with:

apt-get install qemu-user

# undeclared dependencies of UFRII driver package
apt-get install  libcupsimage2:i386 libjpeg62:i386 libstdc++6:i386 libxml2:i386 ghostscript:i386

apt-get install /path/to/ufrii_driver.deb