xref: /aosp_15_r20/external/grpc-grpc-java/buildscripts/qemu_helpers/prepare_qemu.sh (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1#!/bin/bash
2#
3# Setup and configure qemu userspace emulator on kokoro worker so that we can seamlessly emulate processes running
4# inside docker containers.
5
6set -ex
7
8# show pre-existing qemu registration
9cat /proc/sys/fs/binfmt_misc/qemu-aarch64
10
11# Kokoro ubuntu1604 workers have already qemu-user and qemu-user-static packages installed, but it's and old version that:
12# * prints warning about some syscalls (e.g "qemu: Unsupported syscall: 278")
13# * doesn't register with binfmt_misc with the persistent ("F") flag we need (see below)
14#
15# To overcome the above limitations, we use the https://github.com/multiarch/qemu-user-static
16# docker image to provide a new enough version of qemu-user-static and register it with
17# the desired binfmt_misc flags. The most important flag we need is "F" (set by "--persistent yes"),
18# which allows the qemu-aarch64-static binary to be loaded eagerly at the time of registration with binfmt_misc.
19# That way, we can emulate aarch64 binaries running inside docker containers transparently, without needing the emulator
20# binary to be accessible from the docker image we're emulating.
21# Note that on newer distributions (such as glinux), simply "apt install qemu-user-static" is sufficient
22# to install qemu-user-static with the right flags.
23docker run --rm --privileged multiarch/qemu-user-static:5.2.0-2 --reset --credential yes --persistent yes
24
25# Print current qemu reqistration to make sure everything is setup correctly.
26cat /proc/sys/fs/binfmt_misc/qemu-aarch64
27