Build Linux software for foreign CPU architectures on non-x86_64

Martin Grigorov
2 min readJun 7, 2021

--

In my article Building Linux Packages for different CPU architectures with Docker and QEMU I have shown you how to run non-x86_64 Docker containers on x86_64 host machine.

But if your host is non-x86_64 one, e.g. s390x, then using multiarch/qemu-user-static is not an option because it is released only for linux/amd64 at DockerHub.

There is an alternative though — https://dbhi.github.io/qus/!

The only difference with my previous article is that instead of executing

$ docker run -it - - rm - - privileged multiarch/qemu-user-static - - credential yes  -- persistent yes

you need to execute:

$ docker run --rm --privileged aptman/qus -s -- -p [TARGET_ARCH]

where [TARGET_ARCH] is an optional list of CPU architectures you want to enable. If it is not provided then it will enable all supported architectures.

$ docker run --rm --privileged aptman/qus -s -- -p
cat ./qemu-binfmt-conf.sh | sh -s -- --path=/qus/bin -p --suffix -static
Setting /qus/bin/qemu-alpha-static as binfmt interpreter for alpha
Setting /qus/bin/qemu-arm-static as binfmt interpreter for arm
Setting /qus/bin/qemu-armeb-static as binfmt interpreter for armeb
Setting /qus/bin/qemu-sparc-static as binfmt interpreter for sparc
Setting /qus/bin/qemu-sparc32plus-static as binfmt interpreter for sparc32plus
Setting /qus/bin/qemu-sparc64-static as binfmt interpreter for sparc64
Setting /qus/bin/qemu-ppc-static as binfmt interpreter for ppc
Setting /qus/bin/qemu-ppc64-static as binfmt interpreter for ppc64
Setting /qus/bin/qemu-ppc64le-static as binfmt interpreter for ppc64le
Setting /qus/bin/qemu-m68k-static as binfmt interpreter for m68k
Setting /qus/bin/qemu-mips-static as binfmt interpreter for mips
Setting /qus/bin/qemu-mipsel-static as binfmt interpreter for mipsel
Setting /qus/bin/qemu-mipsn32-static as binfmt interpreter for mipsn32
Setting /qus/bin/qemu-mipsn32el-static as binfmt interpreter for mipsn32el
Setting /qus/bin/qemu-mips64-static as binfmt interpreter for mips64
Setting /qus/bin/qemu-mips64el-static as binfmt interpreter for mips64el
Setting /qus/bin/qemu-sh4-static as binfmt interpreter for sh4
Setting /qus/bin/qemu-sh4eb-static as binfmt interpreter for sh4eb
Setting /qus/bin/qemu-s390x-static as binfmt interpreter for s390x
Setting /qus/bin/qemu-aarch64-static as binfmt interpreter for aarch64
Setting /qus/bin/qemu-aarch64_be-static as binfmt interpreter for aarch64_be
Setting /qus/bin/qemu-hppa-static as binfmt interpreter for hppa
Setting /qus/bin/qemu-riscv32-static as binfmt interpreter for riscv32
Setting /qus/bin/qemu-riscv64-static as binfmt interpreter for riscv64
Setting /qus/bin/qemu-xtensa-static as binfmt interpreter for xtensa
Setting /qus/bin/qemu-xtensaeb-static as binfmt interpreter for xtensaeb
Setting /qus/bin/qemu-microblaze-static as binfmt interpreter for microblaze
Setting /qus/bin/qemu-microblazeel-static as binfmt interpreter for microblazeel
Setting /qus/bin/qemu-or1k-static as binfmt interpreter for or1k

Once the emulator(s) are registered you can continue with the same steps explained in 2) Build your software

As a bonus the project also provides a GitHub Action that you could use in your workflows with:

- uses: dbhi/qus/action@main
with:
targets: arm aarch64

Happy hacking!

--

--