armbian / armbian/build

[Bug]: Docker: binfmts are not registered

Open
#8,480 12 comments 1 reaction 0 assignees View on GitHub
Bug
Dominant language
Shell
Stars
5.4k
Forks
3.1k
Avg merge
1d 9h
Merged PRs (30d)
204

Description

### What happened?

Attempting to build an image results in the following errors:
```
[🐳|🌱] Cross arch build [ target arm64 on host amd64 ]
[🐳|💥] Failed to update binfmts [ update-binfmts --enable qemu-arm ]
[🐳|💥] Failed to update binfmts [ update-binfmts --enable qemu-aarch64 ]
[🐳|💥] Failed to update binfmts [ update-binfmts --enable qemu-riscv64 ]
[🐳|🌱] checking [ arch-test for 'arm64' ]
[🐳|🔨] arm64: not supported on this machine/kernel
[🐳|💥] Error 1 occurred in main shell [ at /armbian/lib/functions/logging/runners.sh:223
run_host_command_logged_raw() --> lib/functions/logging/runners.sh:223
run_host_command_logged() --> lib/functions/logging/runners.sh:205
prepare_host_binfmt_qemu() --> lib/functions/rootfs/qemu-static.sh:94
prepare_host_noninteractive() --> lib/functions/host/prepare-host.sh:120
do_with_logging() --> lib/functions/logging/section-logging.sh:81
prepare_host() --> lib/functions/host/prepare-host.sh:17
prepare_host_init() --> lib/functions/main/start-end.sh:64
main_default_start_build() --> lib/functions/main/start-end.sh:17
do_with_default_build() --> lib/functions/main/default-build.sh:41
cli_standard_build_run() --> lib/functions/cli/cli-build.sh:25
armbian_cli_run_command() --> lib/functions/cli/utils-cli.sh:136
cli_entrypoint() --> lib/functions/cli/entrypoint.sh:176
main() --> compile.sh:50
]
```

Worth noting:
- My OS is Gentoo, and even installing qemu and setting up binfmts on the host side doesn't help.
- Running `docker run --rm --privileged multiarch/qemu-user-static --reset -p yes` makes the issue go away, but I don't think it is acceptable to have to run this on every boot when I want to build an armbian image.
- Even if the host has the binfmts enabled from a native package and mounting `binfmt_misc` shows all the registered binfmts, `arch-test` will still not detect those.

I've done some investigation of this issue in the past few days, and using `docker-shell` I found the following:
1. The package `qemu-user-static` already includes all the binfmts in `/usr/lib/binfmt.d/`, which is the location for systemd-binfmt
2. These binfmts can be registered with just `cat /usr/lib/binfmt.d/qemu-$ARCH.conf > /proc/sys/fs/binfmt_misc/register`
3. The package does not install files for `binfmt-support`.
4. There exists a script that can generate binfmt-support templates from these files: https://github.com/qemu/qemu/blob/a74434580e1051bff12ab5eee5586058295c497f/scripts/qemu-binfmt-conf.sh#L301-L311

I have thought about making a PR, but current I can't decide how to approach making the fix, as I see there two options:
1. Using the `/usr/lib/binfmt.d/qemu-*.conf` files directly to register "manually"
2. Using the `qemu-binfmt-conf.sh --debian` approach and generate templates for `binfmt-support` (not including the linked script, but simply using it as an example)

### How to reproduce?

1. `./compile.sh BOARD=` with a docker daemon (`PREFER_DOCKER=yes` if it doesn't use it automatically)

### Branch

main (main development branch)

### On which host OS are you running the build script and observing this problem?

Other (Gentoo)

### Are you building on Windows WSL2?

- [ ] Yes, my Ubuntu/Debian/OtherOS is running on WSL2

### Relevant log URL

https://paste.armbian.com/atenoteqor

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.