diff options
| author | Mohsen Tahmasebi <mhntah@gmail.com> | 2023-04-03 11:57:59 +0330 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 09:27:59 +0100 |
| commit | 6dc45a80e764eacd6e311c32164b623bbe7f8e08 (patch) | |
| tree | 8ddbb348856f24d27bd22bf06f2b16789c3e65bf | |
| parent | 4e9275398278c4cab8ba68f3d9ca54ab97b73922 (diff) | |
Register binfmt_misc entry for docker build (#685)
| -rwxr-xr-x | build-docker.sh | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/build-docker.sh b/build-docker.sh index 01b9f8e..5495dfa 100755 --- a/build-docker.sh +++ b/build-docker.sh @@ -107,6 +107,40 @@ else ) fi +# Check if binfmt_misc is required +binfmt_misc_required=1 +case $(uname -m) in + aarch64) + binfmt_misc_required=0 + ;; + arm*) + binfmt_misc_required=0 + ;; +esac + +# Check if qemu-arm-static and /proc/sys/fs/binfmt_misc are present +if [[ "${binfmt_misc_required}" == "1" ]]; then + if ! qemu_arm=$(which qemu-arm-static) ; then + echo "qemu-arm-static not found (please install qemu-user-static)" + exit 1 + fi + if [ ! -f /proc/sys/fs/binfmt_misc/register ]; then + echo "binfmt_misc required but not mounted, trying to mount it..." + if ! mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc ; then + echo "mounting binfmt_misc failed" + exit 1 + fi + echo "binfmt_misc mounted" + fi + # Register qemu-arm for binfmt_misc (binfmt_misc won't care duplicate entries unless they have common names) + reg="echo ':qemu-arm-rpi:M::"\ +"\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:"\ +"\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:"\ +"$qemu_arm:F' > /proc/sys/fs/binfmt_misc/register" + echo "Registering qemu-arm for binfmt_misc..." + sudo bash -c "$reg" 2>/dev/null || true +fi + trap 'echo "got CTRL+C... please wait 5s" && ${DOCKER} stop -t 5 ${DOCKER_CMDLINE_NAME}' SIGINT SIGTERM time ${DOCKER} run \ "${DOCKER_CMDLINE_PRE[@]}" \ |
