Emulating PPC64 inside Docker

PPC64, the architecture of the IBM POWER4 through POWER7, is big-endian. The POWER8 through POWER10 also have a little-endian mode, which is why PPC64LE is significantly more common nowadays, even though these newer processors can still switch to big-endian mode. I have a bit of manually-vectorized code that specifically supports POWER7 or newer POWERs running in big-endian mode, so to make sure that still works I occasionally need to emulate a PPC64 Linux. There are not many suitable distributions left — Debian dropped the architecture after Debian 8, Ubuntu after 16.04, Void Linux for PowerPC is discontinued, even Fedora dropped it after Fedora 28. Out of the big distributions, that only leaves CentOS 7, which is getting old and only has one year of support left. However, there is Adélie Linux, a relatively new distribution still in development, and Debian unstable still has a PPC64 port. Read on below for Dockerfiles that you can use to run the two inside Docker on amd64 via multiarch.

First, install qemu-user-static or register multiarch if you haven’t already done so. You only need one:

apt-get install qemu-user-static
#docker run --rm --privileged multiarch/qemu-user-static

Debian unstable

FROM --platform=x86_64 multiarch/qemu-user-static:x86_64-ppc64 AS multiarch

FROM debian:latest AS debian

RUN apt-get update && apt-get install -y debootstrap debian-ports-archive-keyring
RUN mkdir rootfs && debootstrap --keyring=/usr/share/keyrings/debian-ports-archive-keyring.gpg --arch=ppc64 --foreign sid rootfs http://deb.debian.org/debian-ports/
RUN rm -rf rootfs/proc

FROM scratch
COPY --from=multiarch /usr/bin/qemu-ppc64-static /usr/bin/qemu-ppc64-static
COPY --from=multiarch /usr/bin/qemu-ppc64-static /usr/bin/qemu-ppc64
COPY --from=debian rootfs /

RUN /debootstrap/debootstrap --second-stage

Put this into a file called Dockerfile in an otherwise empty directory, then run

docker build -t mkuron/ppc64 .

and confirm that you are running on emulated ppc64:

docker run --rm -it mkuron/ppc64 uname -a

Adélie Linux

FROM --platform=x86_64 multiarch/qemu-user-static:x86_64-ppc64 AS multiarch

FROM debian:latest AS debian
RUN apt-get update && apt-get install -y curl xz-utils
RUN curl -Lo rootfs.txz https://distfiles.adelielinux.org/adelie/1.0/iso/rc2/adelie-rootfs-ppc64-1.0-rc2.txz
RUN mkdir rootfs && tar xf rootfs.txz -C rootfs

FROM scratch
COPY --from=multiarch /usr/bin/qemu-ppc64-static /usr/bin/qemu-ppc64-static
COPY --from=multiarch /usr/bin/qemu-ppc64-static /usr/bin/qemu-ppc64
COPY --from=debian rootfs /

RUN apk --no-cache upgrade

Put this into a file called Dockerfile in an otherwise empty directory, then run

docker build -t mkuron/adelie:ppc64 .

and confirm that you are running on emulated ppc64:

docker run --rm -it mkuron/adelie:ppc64 uname -a

Leave a Reply

Your email address will not be published. Required fields are marked *