From 007727c5bc14340cb4709b06bca0197cce4d9399 Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Mon, 22 Nov 2021 22:37:32 -0800 Subject: [PATCH 1/2] Install qemu-* files from tonistiigi/binfmt They contain additional patches missing from the Alpine repo. Also install qemu-x86_64 on the aarch64 ISO. Signed-off-by: Jan Dubois --- Dockerfile | 6 ++++++ Makefile | 2 ++ genapkovl-lima.sh | 17 ++++++++++++++++- mkimg.lima.sh | 3 --- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 99c6ea1..981d4e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,8 @@ ARG ALPINE_VERSION=latest +ARG BINFMT_IMAGE=tonistiigi/binfmt:latest + +FROM ${BINFMT_IMAGE} as binfmt + FROM alpine:${ALPINE_VERSION} RUN apk add alpine-sdk build-base apk-tools alpine-conf busybox \ fakeroot xorriso squashfs-tools sudo \ @@ -8,6 +12,8 @@ RUN apk add alpine-sdk build-base apk-tools alpine-conf busybox \ ARG TARGETARCH RUN if [ "${TARGETARCH}" = "amd64" ]; then apk add syslinux; fi +COPY --from=binfmt /usr/bin /binfmt + RUN addgroup root abuild RUN abuild-keygen -i -a -n RUN apk update diff --git a/Makefile b/Makefile index 239f1d4..7dda9da 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ ARCH_ALIAS_aarch64 = arm64 ARCH_ALIAS = $(shell echo "$(ARCH_ALIAS_$(ARCH))") NERDCTL_VERSION=0.14.0 +BINFMT_IMAGE=tonistiigi/binfmt:qemu-v6.1.0 .PHONY: mkimage mkimage: @@ -25,6 +26,7 @@ mkimage: docker build \ --tag mkimage:$(ALPINE_VERSION)-$(ARCH) \ --build-arg ALPINE_VERSION=$(ALPINE_VERSION) \ + --build-arg BINFMT_IMAGE=$(BINFMT_IMAGE) \ --platform linux/$(ARCH_ALIAS) \ . diff --git a/genapkovl-lima.sh b/genapkovl-lima.sh index 78ace56..38f073c 100755 --- a/genapkovl-lima.sh +++ b/genapkovl-lima.sh @@ -159,7 +159,16 @@ if [ "${LIMA_INSTALL_DOCKER}" == "true" ]; then fi if [ "${LIMA_INSTALL_BINFMT_MISC}" == "true" ]; then - echo "qemu-aarch64" >> "$tmp"/etc/apk/world + # install qemu-aarch64 on x86_64 and vice versa + OTHERARCH=aarch64 + if [ "$(uname -m)" == "${OTHERARCH}" ]; then + OTHERARCH=x86_64 + fi + + # Installing into /usr/bin instead of /usr/local/bin because that's + # where /etc/init.d/qemu-binfmt will be looking for it + mkdir -p "${tmp}/usr/bin/" + cp /binfmt/qemu-${OTHERARCH} "${tmp}/usr/bin/" mkdir -p "${tmp}/etc/init.d/" APKBUILD=/home/build/aports/community/qemu-openrc/APKBUILD @@ -168,6 +177,12 @@ if [ "${LIMA_INSTALL_BINFMT_MISC}" == "true" ]; then wget "${URL}/v${PKGVER}/qemu-binfmt.initd" -O "${tmp}/etc/init.d/qemu-binfmt" chmod +x "${tmp}/etc/init.d/qemu-binfmt" + # qemu-binfmt doesn't include an entry for x86_64 + magic="7f454c4602010100000000000000000002003e00" + mask="fffffffffffefe00fffffffffffffffffeffffff" + arch="x86_64" + sed -i "/^FMTS=/a \\\t${magic} ${mask} ${arch}" "${tmp}/etc/init.d/qemu-binfmt" + rc_add qemu-binfmt default fi diff --git a/mkimg.lima.sh b/mkimg.lima.sh index 3d93dbd..7650d05 100755 --- a/mkimg.lima.sh +++ b/mkimg.lima.sh @@ -27,9 +27,6 @@ profile_lima() { if [ "${LIMA_INSTALL_LIMA_INIT}" == "true" ]; then apks="$apks e2fsprogs lsblk sfdisk shadow sudo udev" fi - if [ "${LIMA_INSTALL_BINFMT_MISC}" == "true" ]; then - apks="$apks qemu-aarch64" - fi if [ "${LIMA_INSTALL_K3S}" == "true" ]; then apks="$apks k3s" fi From d6281fe9976049efe54af570cb67d6a0d89d398c Mon Sep 17 00:00:00 2001 From: Jan Dubois Date: Thu, 25 Nov 2021 09:36:01 -0800 Subject: [PATCH 2/2] Add qemu license to /usr/share/doc/qemu/copyright Signed-off-by: Jan Dubois --- .gitignore | 1 + Makefile | 10 +++++++--- build.sh | 1 + genapkovl-lima.sh | 4 ++++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 103bf03..a5d71c7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /rd.yaml /std.yaml /nerdctl-* +/qemu-* diff --git a/Makefile b/Makefile index 7dda9da..55faee2 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,8 @@ ARCH_ALIAS_aarch64 = arm64 ARCH_ALIAS = $(shell echo "$(ARCH_ALIAS_$(ARCH))") NERDCTL_VERSION=0.14.0 -BINFMT_IMAGE=tonistiigi/binfmt:qemu-v6.1.0 +QEMU_VERSION=v6.1.0 +BINFMT_IMAGE=tonistiigi/binfmt:qemu-$(QEMU_VERSION) .PHONY: mkimage mkimage: @@ -31,13 +32,16 @@ mkimage: . .PHONY: iso -iso: nerdctl-$(NERDCTL_VERSION)-$(ARCH) - ALPINE_VERSION=$(ALPINE_VERSION) NERDCTL_VERSION=$(NERDCTL_VERSION) REPO_VERSION=$(REPO_VERSION) EDITION=$(EDITION) BUILD_ID=$(BUILD_ID) ARCH=$(ARCH) ARCH_ALIAS=$(ARCH_ALIAS) ./build.sh +iso: nerdctl-$(NERDCTL_VERSION)-$(ARCH) qemu-$(QEMU_VERSION)-copying + ALPINE_VERSION=$(ALPINE_VERSION) NERDCTL_VERSION=$(NERDCTL_VERSION) QEMU_VERSION=$(QEMU_VERSION) REPO_VERSION=$(REPO_VERSION) EDITION=$(EDITION) BUILD_ID=$(BUILD_ID) ARCH=$(ARCH) ARCH_ALIAS=$(ARCH_ALIAS) ./build.sh nerdctl-$(NERDCTL_VERSION)-$(ARCH): curl -o $@ -Ls https://github.com/containerd/nerdctl/releases/download/v$(NERDCTL_VERSION)/nerdctl-full-$(NERDCTL_VERSION)-linux-$(ARCH_ALIAS).tar.gz +qemu-$(QEMU_VERSION)-copying: + curl -o $@ -Ls https://raw.githubusercontent.com/qemu/qemu/$(QEMU_VERSION)/COPYING + .PHONY: lima lima: ALPINE_VERSION=$(ALPINE_VERSION) EDITION=$(EDITION) ARCH=$(ARCH) ./lima.sh diff --git a/build.sh b/build.sh index 0c16a16..da022d9 100755 --- a/build.sh +++ b/build.sh @@ -17,6 +17,7 @@ docker run --rm \ -v "${PWD}/lima-init-local.openrc:/home/build/lima-init-local.openrc:ro" \ -v "${PWD}/lima-network.awk:/home/build/lima-network.awk:ro" \ -v "${PWD}/nerdctl-${NERDCTL_VERSION}-${ARCH}:/home/build/nerdctl.tar.gz:ro" \ + -v "${PWD}/qemu-${QEMU_VERSION}-copying:/home/build/qemu-copying:ro" \ -v "${PWD}/sshd.pam:/home/build/sshd.pam:ro" \ $(env | grep ^LIMA_ | xargs -n 1 printf -- '-e %s ') \ -e "LIMA_REPO_VERSION=${REPO_VERSION}" \ diff --git a/genapkovl-lima.sh b/genapkovl-lima.sh index 38f073c..26b8f15 100755 --- a/genapkovl-lima.sh +++ b/genapkovl-lima.sh @@ -170,6 +170,10 @@ if [ "${LIMA_INSTALL_BINFMT_MISC}" == "true" ]; then mkdir -p "${tmp}/usr/bin/" cp /binfmt/qemu-${OTHERARCH} "${tmp}/usr/bin/" + # Copy QEMU license into /usr/share/doc (using Debian naming convention) + mkdir -p "${tmp}/usr/share/doc/qemu/" + cp /home/build/qemu-copying "${tmp}/usr/share/doc/qemu/copyright" + mkdir -p "${tmp}/etc/init.d/" APKBUILD=/home/build/aports/community/qemu-openrc/APKBUILD PKGVER=$(awk '/^pkgver=/ {split($1, a, "="); print a[2]}' ${APKBUILD})