From 342a1efcfb48e6d71f1c8f1f58f2c0149134b8b0 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Wed, 6 May 2026 00:49:01 -0500 Subject: [PATCH] Add QEMU binfmt setup and fix static installer - Fix typo in static.installer: /pkg/ -> /pkgs/ - Add missing mkdir -p /build before makeself - Mount pkgs directory via podman build -v so static.installer can access previously built static tarballs without relying on bind mounts relative to the build context - Register qemu-user-static binfmt handlers for cross-compilation - Make --git-repo optional when using --setup --- buildtools/build-release | 34 ++++++++++++++++++++-- buildtools/containerfiles/static.installer | 5 ++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/buildtools/build-release b/buildtools/build-release index d72054f9..6c307f51 100755 --- a/buildtools/build-release +++ b/buildtools/build-release @@ -22,6 +22,8 @@ def build(git_repo, args += ['--build-arg=GIT_REPO=file:///tmp/mergerfs.git'] else: args += [f'--build-arg=GIT_REPO={git_repo}'] + os.makedirs(pkgdirpath,exist_ok=True) + args += ['-v',f'{os.path.realpath(pkgdirpath)}:/pkgs:ro'] args += ['-o',pkgdirpath, '-f',containerfile, f'--build-arg=BRANCH={branch}', @@ -30,8 +32,6 @@ def build(git_repo, # TODO: Capture output and write to log print(args) rv = subprocess.run(args) - - os.makedirs(pkgdirpath,exist_ok=True) report_filepath = os.path.join(pkgdirpath,"build-report.txt") with open(report_filepath,"a+") as f: build = os.path.basename(containerfile) @@ -66,6 +66,30 @@ def setup(): sys.exit(1) print(args) subprocess.run(args) + setup_binfmt() + + +def setup_binfmt(): + """Register qemu-user-static binfmt handlers (needed on Arch, etc.).""" + binfmt_conf = """\ +:qemu-aarch64:M::\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xb7\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-aarch64-static:F +:qemu-arm: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:/usr/bin/qemu-arm-static:F +:qemu-armeb:M::\\x7fELF\\x01\\x02\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x28:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff:/usr/bin/qemu-armeb-static:F +:qemu-riscv64:M::\\x7fELF\\x02\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\xf3\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-riscv64-static:F +:qemu-i386:M::\\x7fELF\\x01\\x01\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x03\\x00:\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xfe\\xff\\xff\\xff:/usr/bin/qemu-i386-static:F +""" + conf_path = '/etc/binfmt.d/qemu-static.conf' + print(f"Writing {conf_path}") + try: + with open(conf_path, 'w') as f: + f.write(binfmt_conf) + except PermissionError: + print(f"Permission denied writing {conf_path}; trying with sudo...") + subprocess.run(['sudo', 'tee', conf_path], + input=binfmt_conf.encode(), check=True) + + print("Restarting systemd-binfmt...") + subprocess.run(['sudo', 'systemctl', 'restart', 'systemd-binfmt']) def podman_cleanup(): @@ -92,7 +116,7 @@ def parse_args(): required=False, action='store_true') p.add_argument('--git-repo', - required=True, + required=False, type=str) return p.parse_args() @@ -112,6 +136,10 @@ def main(): setup() sys.exit(0) + if not args.git_repo: + print("error: the following arguments are required: --git-repo") + sys.exit(1) + containerfiles = [] basepath = 'buildtools/containerfiles' if os.path.exists(f'{basepath}/{args.target}'): diff --git a/buildtools/containerfiles/static.installer b/buildtools/containerfiles/static.installer index 77cea23b..ea0d2fee 100644 --- a/buildtools/containerfiles/static.installer +++ b/buildtools/containerfiles/static.installer @@ -2,8 +2,9 @@ ARG BUILD_TIMESTAMP=0 FROM --platform=linux/amd64 ubuntu:latest as build RUN apt-get update && apt-get install -y makeself RUN mkdir -p /tmp/mergerfs/ -RUN --mount=type=bind,src=pkgs,dst=/pkgs ls -lhd /pkgs -RUN --mount=type=bind,src=pkgs,dst=/pkgs cp -v /pkg/*static*.gz /tmp/mergerfs/ +RUN ls -lhd /pkgs +RUN cp -v /pkgs/*static*.gz /tmp/mergerfs/ +RUN mkdir -p /build RUN makeself /tmp/mergerfs/ /build/mergerfs-installer.run "mergerfs" echo "foo" FROM scratch