From b4531870b4f1ff9752b8e8e839bc8560e71e3e23 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 13 Apr 2021 11:56:56 +0200 Subject: [PATCH] add prepare_qemu.sh script --- .../aarch64/qemu_helpers/prepare_qemu.sh | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100755 kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh diff --git a/kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh b/kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh new file mode 100755 index 0000000000..aa78e994cd --- /dev/null +++ b/kokoro/linux/aarch64/qemu_helpers/prepare_qemu.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Setup and configure qemu userspace emulator on kokoro worker so that we can seamlessly emulate processes running +# inside docker containers. + +set -ex + +# show pre-existing qemu registration +cat /proc/sys/fs/binfmt_misc/qemu-aarch64 + +# Kokoro ubuntu1604 workers have already qemu-user and qemu-user-static packages installed, but it's and old version that: +# * prints warning about some syscalls (e.g "qemu: Unsupported syscall: 278") +# * doesn't register with binfmt_misc with the "F" flag we need (see below) +# To avoid the "unsupported syscall" warnings, we download a recent version of qemu-aarch64-static. +# On newer distributions (such as glinux), simply "apt install qemu-user-static" is sufficient. +curl -sSL --output qemu-aarch64-static https://github.com/multiarch/qemu-user-static/releases/download/v5.2.0-2/qemu-aarch64-static +chmod ugo+x qemu-aarch64-static +sudo mv qemu-aarch64-static /usr/local/bin +/usr/local/bin/qemu-aarch64-static --version + +# register qemu-aarch64-static with binfmt_misc to use it as emulator for aarch64 binaries (based on their magic and mask) +# The format of the configuration string is ":name:type:offset:magic:mask:interpreter:flags" +# The most important flag is "F", which allows the qemu-aarch64-static binary to be loaded regardless of chroot and namespaces. +# That way, we can emulate aarch64 binaries running inside docker containers transparently, without needing the emulator +# to be accessible from the docker image we're emulating. +echo -1 | sudo tee /proc/sys/fs/binfmt_misc/qemu-aarch64 # delete the existing registration +echo ":qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/local/bin/qemu-aarch64-static:OCF" | sudo tee /proc/sys/fs/binfmt_misc/register + +# Print current qemu reqistration to make sure everything is setup correctly. +cat /proc/sys/fs/binfmt_misc/qemu-aarch64