Cross-Architecture Fedora Roots with DNF

Or, How to Build Non-x86 Fedora Containers

July 12, 2017
fedora

Cross-compilation is painful. If you’ve never tried it, it usually involves all sorts of trickery just to get the build system setup. More advanced features are generally out of reach. You want reproducable builds? In your dreams!

Until QEMU, you basically were stuck with either owning the hardware or running the gauntlet of cross-compilation. Testing packages written in assembly, like - say - libctx, was an exercise in futility. I know, I did it. But virtualization has given us a way around this. If we could get someone with access to the hardware to make an OS image for us, we could (maybe) get it to boot in a VM. Then, we could build on what appeared to be real hardware without the actual hardware.

But this also came with a lot of things we don’t need. For example, if you’re just going to run make, why do you need the whole OS to be booted and running? This goes beyond just a resource waste problem. When emulation isn’t perfect, you might not be able to get the whole system to boot. Or doing so might be its own special purgatory.

A much simpler solution was to build a cross-architecture root using tools like debootstrap. This could be accomplished by splitting the construction into three steps. First, you would unpack all the .deb packages into the new install root. Then, you could copy your qemu-$ARCH-static binary into the root. Finally, you would run the second half of the bootstrap phase inside the root where all the package scripts would be run using this emulator.

Fedora, however, has lacked this ability for a long time. However, I’m proud to report that there exists hope! I have created a pull request for DNF that enables us to create cross-architecture roots using QEMU. I’ll now demonstrate what this might look like after the patch is merged. Feel free to patch your own DNF locally and try it out for yourself!

First, you need to make sure that QEMU user-space emulation is set up on your host system. On Fedora, this is done with the following commands:

$ dnf install qemu-user-static
$ systemctl restart systemd-binfmt.service # This step soon-to-be optional

Second, we will install the remaining packages using the alternate CPU architecture (requires the patch above):

$ dnf install --releasever=25 \
    --installroot=/tmp/F25ARM \
    --forcearch=armv7hl       \
    --repo=fedora             \
    --repo=updates            \
    -y systemd passwd dnf fedora-release vim-minimal
...
$ chroot /tmp/F25ARM /usr/bin/uname -r -m
4.10.0-1.fc26.x86_64 armv7l

That’s more or less it. If this is the future you’d like to see, please help me get the pull request merged and the QEMU bug resolved. Happy hacking!

comments powered by Disqus