prepare_qemu_rc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. # Copyright 2021 The gRPC Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Source this rc script to setup and configure qemu userspace emulator on kokoro worker so that we can seamlessly emulate processes running
  16. # inside docker containers.
  17. # show pre-existing qemu registration
  18. cat /proc/sys/fs/binfmt_misc/qemu-aarch64
  19. # Kokoro ubuntu1604 workers have already qemu-user and qemu-user-static packages installed, but it's and old version that:
  20. # * prints warning about some syscalls (e.g "qemu: Unsupported syscall: 278")
  21. # * doesn't register with binfmt_misc with the persistent ("F") flag we need (see below)
  22. #
  23. # To overcome the above limitations, we use the https://github.com/multiarch/qemu-user-static
  24. # docker image to provide a new enough version of qemu-user-static and register it with
  25. # the desired binfmt_misc flags. The most important flag we need is "F" (set by "--persistent yes"),
  26. # which allows the qemu-aarch64-static binary to be loaded eagerly at the time of registration with binfmt_misc.
  27. # That way, we can emulate aarch64 binaries running inside docker containers transparently, without needing the emulator
  28. # binary to be accessible from the docker image we're emulating.
  29. # Note that on newer distributions (such as glinux), simply "apt install qemu-user-static" is sufficient
  30. # to install qemu-user-static with the right flags.
  31. docker run --rm --privileged multiarch/qemu-user-static:5.2.0-2 --reset --credential yes --persistent yes
  32. # Print current qemu reqistration to make sure everything is setup correctly.
  33. cat /proc/sys/fs/binfmt_misc/qemu-aarch64