Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created April 30, 2020 11:50
Show Gist options
  • Save maxlapshin/bbf0e4dfd6486c3affd321938cc28014 to your computer and use it in GitHub Desktop.
Save maxlapshin/bbf0e4dfd6486c3affd321938cc28014 to your computer and use it in GitHub Desktop.
#!/bin/sh
# How to prepare your linux box to run ARM64 images in docker
# https://codepyre.com/2019/12/arming-yourself/
wget https://download.qemu.org/qemu-4.2.0.tar.xz
tar xf qemu-4.2.0.tar.xz
cd qemu-4.2.0
apt install -y bison flex build-essential libglib2.0-dev libpixman-1-dev qemu binfmt-support
./configure --target-list=aarch64-linux-user,arm-linux-user --static
make -j 50
cp aarch64-linux-user/qemu-aarch64 /usr/bin/qemu-aarch64-static
cp arm-linux-user/qemu-arm /usr/bin/qemu-arm-static
mkdir -p /lib/binfmt.d
# Create a configuration for arm32v7
sh -c 'echo :qemu-arm:M::\\x7f\\x45\\x4c\\x46\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xfe\\xff\\xff\\xff:/usr/bin/qemu-arm-static:F > /lib/binfmt.d/qemu-arm-static.conf'
# Create a configuration for arm64v8
sh -c 'echo :qemu-aarch64:M::\\x7f\\x45\\x4c\\x46\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\xfe\\xff\\xff\\xff:/usr/bin/qemu-aarch64-static:F > /lib/binfmt.d/qemu-aarch64-static.conf'
# Restart the service to force an evaluation of the /lib/binfmt.d directory
systemctl restart systemd-binfmt.service
docker run --rm --privileged multiarch/qemu-user-static:register --reset
# reboot
# Now check:
# $ docker run --rm -it arm64v8/alpine:3.11
# / #
#
# You are running arm64 system on an intel docker box
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment