Working with Intel Containers on Power
This article lists the steps needed to run Intel Containers on Power (ppc64le). You can use this approach for a quick dev/test scenario.
Setup
The Linux system needs to be setup to use Qemu user mode emulation. For this, we need to register the appropriate Qemu binary as the interpreter/handler for any Intel binaries. Ensure that you are using the latest OS release with 4+ series kernel.
Perform the following steps on your Power (ppc64le) system
- Download Qemu static binary
# wget http://www.rpmfind.info/linux/fedora-secondary/releases/34/Everything/ppc64le/os/Packages/q/qemu-user-static-5.2.0-5.fc34.1.ppc64le.rpm# rpm2cpio qemu-user-static-5.2.0-5.fc34.1.ppc64le.rpm | cpio -idmv# cp usr/bin/qemu-x86_64-static /usr/bin/qemu-x86_64-static# chmod +x /usr/bin/qemu-x86_64-static
- Register with ‘F’ flag
# echo ':qemu-x86_64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-x86_64-static:F' > /proc/sys/fs/binfmt_misc/register
After running the above command, you should see the following output on the host.
# cat /proc/sys/fs/binfmt_misc/qemu-x86_64
enabled
interpreter /usr/bin/qemu-x86_64-static
flags: F
offset 0
magic 7f454c4602010100000000000000000002003e00
mask fffffffffffefe00fffffffffffffffffeffffff
The above indicates that any x86_64 binary (magic — 7f454c460….) will be executed with /usr/bin/qemu-x86_64-static.
The magic string is the information encoded in the header of the binary. You can use ‘readelf’ command to check the header of the binary:
# readelf -h <x86_64 binary>
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
[snip]
Run Intel Container Images
On completion of the above steps, running Intel container images on Power is as simple as executing the following commands:
# docker run amd64/busybox uname -aOr# podman run amd64/busybox uname -a
Unregister the Qemu Binary
Running the following command will disable the emulation
# echo "-1" > /proc/sys/fs/binfmt_misc/qemu-x86_64
References
Here is a list of some of my older articles which touches upon the topic of using Qemu for multi-arch development.
Build ppc64le docker image on Intel — https://www.katacoda.com/bpradipt/scenarios/multiarch-build-docker
Run ppc64le docker image on Intel — https://www.katacoda.com/bpradipt/scenarios/ppc64le-docker
Approaches to build and test docker images on Intel — http://cloudgeekz.com/1352/powerpc-docker-images-on-intel.html
Travis with Qemu for multi-arch CI — https://developer.ibm.com/linuxonpower/2017/07/28/travis-multi-architecture-ci-workflow/
Multi-arch docker development on Mac — http://cloudgeekz.com/1589/multi-architecture-dev-docker-mac.html