Running Raspbian on x86 docker
Setting up a cross compilation environment is quite tedious and it is much easier to rebuild a software natively on raspberry pi, but what if you don’t have on pi spare next to you or if you want to automate the build process on a generic x86 server.
Hopefully, the binfmt_mis
Linux kernel module allows to register interpreters for various binary formats based on a magic number. In conjonction with the qemu-user-static
user-space emulator for arm, it allows us to create a docker image
of the arm raspbian distribution which can run on a directly x86 desktop or server.
Installing Docker on an Ubuntu x86 host
Fist install binfmt-support and qemu-user-static on the x86 host. On Ubuntu LTS 14.04:
Building arm/raspbian docker image for x86 with qemu
Use the following script to download the image from raspberrypi.org and convert if to a docker image.
Get the rpi-build-docker-img script.
Performance
The raw CPU performance on the emulation is slightly slower that when running on the native but has the great advantage to be able to run on any server to automate build or image modification.
I used sysbench as descripbe bellow to benchmark the three configuration.
(See table to interpret the /proc/cpuinfo on raspberry-pi)
Results:
system | sysbench Total time |
---|---|
Host native (i7 6 cores) | 1.1145s |
raspeberry-pi native (Model B+ ARMv6/512MB) | 54.3638s |
qemu-arm | 60.7251s |
References
- Using qemu-user-static with root for a raspbian image can be found here and here
- Qemu User Emulation
- How to benchmark your system cpu with sysbench
Issues
Update: I encounter a crash with tcg.c:1693: tcg fatal error
while cloning a git tree with qemu-user-static 2.0.0+dfsg-2ubuntu1.22. This is apparently a known issue. See: https://patches.linaro.org/patch/32473/.
The issue doesn’t occurs with qemu-arm-static of Ubuntu 15.10 (A copy is stored at http://jguiraudet.github.io/assests/bin/qemu-arm-static)