After a long period mostly standardized around the 64-bit x86 architecture, HPC systems, developer laptops, and desktops are becoming more diverse. ARM and POWER HPC systems are deployed on-premise, and ARM systems can also be constructed using cloud resources. On the desktop, Apple’s M1 / M2 CPUs bring ARM to a wide range of users.
Given this situation, you may need to build a container on a machine with a different CPU architecture than the system on which you will use the container. Sylabs’ Singularity Enterprise supports remote builds, using build hosts of different architectures. This ensures quick and easy full-speed builds are accessible to customers who have deployed Singularity Enterprise on-premise.
If you cannot use Singularity Enterprise or need to work with more exotic architectures, you can build containers using emulation of the required architecture. This requires a running x86_64 Linux system or virtual machine, with SingularityCE or PRO installed. Some patience is also needed. Emulation is slow, but it works.
Enable qemu-static binfmt_misc
We can set up our machine to transparently run and build containers for a different architecture by using qemu-static and binfmt_misc.
QEMU is a powerful emulator for a wide range of architectures and machines. The qemu-static binaries are static builds of emulators for different architectures.
binfmt_misc is a Linux kernel feature that allows associating executable files with an interpreter or other program that should run them
The multiarch/qemu-user-static project provides a simple way to bring up-to-date qemu-static binaries on your system, and register them with binfmt_misc, so your system can then handle other architectures.
multiarch/qemu-user-static supports Singularity. To set up your system, you’ll need to run the container as the root user, as detailed in the project’s README.