Skip to content

Commit 5518b77

Browse files
committed
qemu-static: handle resolute's -static-less qemu binaries
Ubuntu 26.04's qemu-user-binfmt drops the -static suffix on the actual binary names: /usr/bin/qemu-aarch64 instead of /usr/bin/qemu-aarch64 -static. The chroot-deploy code in qemu-static.sh hardcoded the historical name and would fail on resolute hosts even with the apt package now resolved. deploy_qemu_binary_to_chroot: - Resolve the host source path: try /usr/bin/${QEMU_BINARY} (the -static name) first, fall back to the bare name. - Copy to both /usr/bin/qemu-<arch>-static and /usr/bin/qemu-<arch> inside the chroot, so whichever path the host's binfmt registration points at resolves at chroot time. The qemu-user -static package on older releases registers the -static name; the qemu-user-binfmt package on resolute registers the bare name. undeploy_qemu_binary_from_chroot: - Remove and restore both names symmetrically. Reported by @pyavitz on the previous commit's PR.
1 parent f00b32b commit 5518b77

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

lib/functions/rootfs/qemu-static.sh

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,27 @@ function deploy_qemu_binary_to_chroot() {
1717
return 0
1818
fi
1919

20-
declare src_host="/usr/bin/${QEMU_BINARY}"
20+
# Source: try the historical name first (qemu-<arch>-static), fall back
21+
# to the bare name shipped by Ubuntu resolute's qemu-user-binfmt package
22+
# (e.g. /usr/bin/qemu-aarch64).
23+
declare qemu_no_suffix="${QEMU_BINARY%-static}"
24+
declare src_host=""
25+
if [[ -f "/usr/bin/${QEMU_BINARY}" ]]; then
26+
src_host="/usr/bin/${QEMU_BINARY}"
27+
elif [[ -f "/usr/bin/${qemu_no_suffix}" ]]; then
28+
src_host="/usr/bin/${qemu_no_suffix}"
29+
else
30+
exit_with_error "Missing qemu binary on host: tried /usr/bin/${QEMU_BINARY} and /usr/bin/${qemu_no_suffix}"
31+
fi
32+
33+
# Destination: deploy under both names so the chroot resolves whichever
34+
# path the host's binfmt registration points at — the older qemu-user-
35+
# static package registers /usr/bin/qemu-<arch>-static, while resolute's
36+
# qemu-user-binfmt registers /usr/bin/qemu-<arch>.
2137
declare dst_target="${chroot_target}/usr/bin/${QEMU_BINARY}"
38+
declare dst_target_alt="${chroot_target}/usr/bin/${qemu_no_suffix}"
2239
declare dst_target_bkp="${dst_target}.armbian.orig"
40+
declare dst_target_alt_bkp="${dst_target_alt}.armbian.orig"
2341

2442
# Assume we're getting a clean base to work with. Namely, we count on the rootfs cache to _not_ have left a dangling binary.
2543
# If the dst_target already exists, it means the target actually has the qemu-static package installed.
@@ -28,9 +46,16 @@ function deploy_qemu_binary_to_chroot() {
2846
display_alert "Preserving existing qemu binary" "${QEMU_BINARY} during ${caller}" "info"
2947
run_host_command_logged mv -v "${dst_target}" "${dst_target_bkp}"
3048
fi
49+
if [[ "${dst_target}" != "${dst_target_alt}" && -f "${dst_target_alt}" ]]; then
50+
display_alert "Preserving existing qemu binary" "${qemu_no_suffix} during ${caller}" "info"
51+
run_host_command_logged mv -v "${dst_target_alt}" "${dst_target_alt_bkp}"
52+
fi
3153

32-
display_alert "Deploying qemu-user-static binary to chroot" "${QEMU_BINARY} during ${caller}" "info"
54+
display_alert "Deploying qemu-user-static binary to chroot" "${QEMU_BINARY} during ${caller} (from ${src_host})" "info"
3355
run_host_command_logged cp -pv "${src_host}" "${dst_target}"
56+
if [[ "${dst_target}" != "${dst_target_alt}" ]]; then
57+
run_host_command_logged cp -pv "${src_host}" "${dst_target_alt}"
58+
fi
3459

3560
return 0
3661
}
@@ -45,8 +70,11 @@ function undeploy_qemu_binary_from_chroot() {
4570
return 0
4671
fi
4772

73+
declare qemu_no_suffix="${QEMU_BINARY%-static}"
4874
declare dst_target="${chroot_target}/usr/bin/${QEMU_BINARY}"
75+
declare dst_target_alt="${chroot_target}/usr/bin/${qemu_no_suffix}"
4976
declare dst_target_bkp="${dst_target}.armbian.orig"
77+
declare dst_target_alt_bkp="${dst_target_alt}.armbian.orig"
5078

5179
# Check the binary we deployed is there. If not, panic, as we've lost control.
5280
if [[ ! -f "${dst_target}" ]]; then
@@ -56,11 +84,18 @@ function undeploy_qemu_binary_from_chroot() {
5684
# Remove the binary we deployed, and restore the original if we had to preserve it.
5785
display_alert "Removing qemu-user-static binary from chroot" "${QEMU_BINARY} during ${caller}" "info"
5886
run_host_command_logged rm -fv "${dst_target}"
87+
if [[ "${dst_target}" != "${dst_target_alt}" && -f "${dst_target_alt}" ]]; then
88+
run_host_command_logged rm -fv "${dst_target_alt}"
89+
fi
5990

6091
if [[ -f "${dst_target_bkp}" ]]; then
6192
display_alert "Restoring original qemu binary" "${QEMU_BINARY} during ${caller}" "info"
6293
run_host_command_logged mv -v "${dst_target_bkp}" "${dst_target}"
6394
fi
95+
if [[ "${dst_target}" != "${dst_target_alt}" && -f "${dst_target_alt_bkp}" ]]; then
96+
display_alert "Restoring original qemu binary" "${qemu_no_suffix} during ${caller}" "info"
97+
run_host_command_logged mv -v "${dst_target_alt_bkp}" "${dst_target_alt}"
98+
fi
6499

65100
return 0
66101
}

0 commit comments

Comments
 (0)