Skip to content

Commit

Permalink
Merge pull request #31 from lima-vm/qemu-binfmt
Browse files Browse the repository at this point in the history
Install qemu-* files from tonistiigi/binfmt
  • Loading branch information
AkihiroSuda authored Nov 26, 2021
2 parents bc0f3af + d6281fe commit 7ff6dc8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/rd.yaml
/std.yaml
/nerdctl-*
/qemu-*
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,30 @@ ARCH_ALIAS_aarch64 = arm64
ARCH_ALIAS = $(shell echo "$(ARCH_ALIAS_$(ARCH))")

NERDCTL_VERSION=0.14.0
QEMU_VERSION=v6.1.0
BINFMT_IMAGE=tonistiigi/binfmt:qemu-$(QEMU_VERSION)

.PHONY: mkimage
mkimage:
cd src/aports && git fetch && git checkout $(GIT_TAG)
docker build \
--tag mkimage:$(ALPINE_VERSION)-$(ARCH) \
--build-arg ALPINE_VERSION=$(ALPINE_VERSION) \
--build-arg BINFMT_IMAGE=$(BINFMT_IMAGE) \
--platform linux/$(ARCH_ALIAS) \
.

.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
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
21 changes: 20 additions & 1 deletion genapkovl-lima.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,20 @@ 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/"

# 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
Expand All @@ -168,6 +181,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

Expand Down
3 changes: 0 additions & 3 deletions mkimg.lima.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7ff6dc8

Please sign in to comment.