diff options
author | Helmut Grohne <helmutg@debian.org> | 2023-01-25 13:02:58 +0000 |
---|---|---|
committer | Helmut Grohne <helmutg@debian.org> | 2023-01-25 13:02:58 +0000 |
commit | 8fc38d0ebfaf6f9b01baa3f5d659d1d7175c21ec (patch) | |
tree | 3e64576bd26c6a24b974742d2b5a04c02cbe0ae9 | |
parent | 06b842b6184c62e706515601b974245498c09a66 (diff) | |
parent | caa848fa49aee9cd6962c171ae2e2cad5cb47b0b (diff) | |
download | debvm-8fc38d0ebfaf6f9b01baa3f5d659d1d7175c21ec.tar.gz |
Merge branch 'multiarch' into 'main'
install and use multiarch kernels for sibling architectures
See merge request helmutg/debvm!28
-rw-r--r-- | .gitlab-ci.yml | 3 | ||||
-rwxr-xr-x | bin/debvm-run | 67 | ||||
-rw-r--r-- | debian/control | 1 | ||||
-rwxr-xr-x | share/customize-kernel.sh | 16 | ||||
-rwxr-xr-x | tests/create-and-run.sh | 9 |
5 files changed, 69 insertions, 27 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4604045..baea94c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,6 +35,7 @@ arch_test: matrix: - ARCHITECTURE: - arm64 + - armel - armhf - i386 - mips64el @@ -45,5 +46,5 @@ arch_test: - test -e /proc/sys/fs/binfmt_misc/status || mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc - apt-get update - apt-get dist-upgrade --yes - - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-system binfmt-support arch-test qemu-user-static + - apt-get --no-install-recommends --yes install e2fsprogs genext2fs mmdebstrap openssh-client qemu-system binfmt-support arch-test qemu-user-static file - PATH=$(pwd)/bin:$PATH ./tests/create-and-run.sh "$ARCHITECTURE" sid diff --git a/bin/debvm-run b/bin/debvm-run index e07ce48..1ac2360 100755 --- a/bin/debvm-run +++ b/bin/debvm-run @@ -104,6 +104,14 @@ die() { echo "$*" 1>&2 exit 1 } +with_set_ex() { + echo "+ $*" 1>&2 + with_set_ex_ret=0 + "$@" || with_set_ex_ret=$? + if test "$with_set_ex_ret" != 0; then + die "failed with exit code $with_set_ex_ret" + fi +} usage() { die "usage: $0 [-g] [-i image] [-s sshport] [-- qemu options]" } @@ -203,6 +211,23 @@ INITRDNAME=$(/sbin/debugfs "$IMAGE" -R "stat ${BOOTDIR}initrd.img" | sed 's/Fast test -n "$INITRDNAME" || die "failed to discover initrd image" test "${INITRDNAME#/}" = "$INITRDNAME" && INITRDNAME="$BOOTDIR$INITRDNAME" +with_set_ex /sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" +with_set_ex /sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" + +# Guess the kernel architecture. +KERNELARCH=$VMARCH +if command -v file >/dev/null 2>&1; then + case "$VMARCH:$(file -b "$KERNELTMP")" in + "arm:Linux kernel ARM64 boot executable Image"*) KERNELARCH=arm64 ;; + "armel:Linux kernel ARM64 boot executable Image"*) KERNELARCH=arm64 ;; + "armhf:Linux kernel ARM64 boot executable Image"*) KERNELARCH=arm64 ;; + # The boot stub looks the same on i386 and amd64, so we + # actually inspect the kernel version here, which happens to + # include amd64 for Debian kernels. + "i386:Linux kernel x86 boot executable bzImage, version "*"-amd64 "*) KERNELARCH=amd64 ;; + esac +fi + KERNEL_CMDLINE="root=LABEL=debvm rw" NETDEV="user,id=net0" @@ -216,33 +241,27 @@ set -- \ -object rng-random,filename=/dev/urandom,id=rng0 \ "$@" -QEMU="qemu-system-$VMARCH" +QEMU="qemu-system-$KERNELARCH" CPU= MACHINE= MAX_SMP= NIC_DEV=virtio-net-pci,netdev=net0 RNG_DEV=virtio-rng-pci,rng=rng0 -case "$VMARCH" in +case "$KERNELARCH" in amd64) QEMU=qemu-system-x86_64 MACHINE="type=q35" ;; - arm|armel) + arm|armel|armhf) CPU=max MACHINE="type=virt" MAX_SMP=8 - RNG_DEV= ;; arm64) QEMU=qemu-system-aarch64 CPU=max - MACHINE="type=virt" - ;; - armhf) - CPU=max - MACHINE="type=virt" - MAX_SMP=8 + MACHINE="type=virt,gic-version=max" ;; m68k) MACHINE="type=virt" @@ -273,7 +292,19 @@ case "$VMARCH" in ;; esac -if test "$ARCHITECTURE" = "$VMARCH"; then +ENABLE_KVM=no +if test "$ARCHITECTURE" = "$KERNELARCH"; then + ENABLE_KVM=yes + case "$VMARCH:$KERNELARCH" in + arm:arm64|armel:arm64|armhf:arm64) + if ! linux32 true >/dev/null 2>&1; then + # This arm64 cannot run 32bit arm, so don't try KVM. + ENABLE_KVM=no + fi + ;; + esac +fi +if test "$ENABLE_KVM" = yes; then if ! command -v "$QEMU" >/dev/null 2>&1; then # Fall back to kvm in case we badly guessed qemu. QEMU=kvm @@ -284,9 +315,6 @@ if test "$ARCHITECTURE" = "$VMARCH"; then if test -w /dev/kvm; then CPU=host fi - if test "$VMARCH" = arm64; then - MACHINE="$MACHINE,gic-version=max" - fi fi if test -n "$MACHINE"; then @@ -308,7 +336,7 @@ fi if test -z "$GRAPHICAL"; then set -- -nographic "$@" - case "$VMARCH" in + case "$KERNELARCH" in amd64|i386) KERNEL_CMDLINE="$KERNEL_CMDLINE console=ttyS0" ;; @@ -317,7 +345,7 @@ if test -z "$GRAPHICAL"; then KERNEL_CMDLINE="$KERNEL_CMDLINE TERM=$TERM" fi else - case "$VMARCH" in + case "$KERNELARCH" in amd64|i386) set -- -vga virtio "$@" ;; @@ -337,9 +365,4 @@ set -- \ -device "$NIC_DEV" \ "$@" -set -ex - -/sbin/debugfs "$IMAGE" -R "cat $KERNELNAME" > "$KERNELTMP" -/sbin/debugfs "$IMAGE" -R "cat $INITRDNAME" > "$INITRDTMP" - -"$QEMU" "$@" +with_set_ex "$QEMU" "$@" diff --git a/debian/control b/debian/control index 0c1b3cf..59cde28 100644 --- a/debian/control +++ b/debian/control @@ -21,6 +21,7 @@ Depends: ipxe-qemu, Recommends: arch-test, + file, systemd | binfmt-support, openssh-client, qemu-system, diff --git a/share/customize-kernel.sh b/share/customize-kernel.sh index 23c2cd0..aef9fa7 100755 --- a/share/customize-kernel.sh +++ b/share/customize-kernel.sh @@ -14,21 +14,31 @@ if dpkg-query --root="$TARGET" --showformat='${db:Status-Status}\n' --show 'linu exit 0 fi -ARCHITECTURE=$(head -n1 "$TARGET/var/lib/dpkg/arch") +ARCHITECTURES=$(xargs < "$TARGET/var/lib/dpkg/arch") -KERNEL_ARCH="$ARCHITECTURE" -case "$ARCHITECTURE" in +KERNEL_ARCH="${ARCHITECTURES%% *}" +case "$KERNEL_ARCH" in armel) KERNEL_ARCH=rpi + case "$ARCHITECTURES " in + *" arm64 "*) KERNEL_ARCH=arm64:arm64 ;; + *" armhf "*) KERNEL_ARCH=armmp:armhf ;; + esac ;; armhf) KERNEL_ARCH=armmp + case "$ARCHITECTURES " in + *" arm64 "*) KERNEL_ARCH=arm64:arm64 ;; + esac ;; hppa) KERNEL_ARCH=parisc ;; i386) KERNEL_ARCH=686-pae + case "$ARCHITECTURES " in + *" amd64 "*) KERNEL_ARCH=amd64:amd64 ;; + esac ;; mips64el) KERNEL_ARCH=5kc-malta diff --git a/tests/create-and-run.sh b/tests/create-and-run.sh index 58c4822..c8efa3e 100755 --- a/tests/create-and-run.sh +++ b/tests/create-and-run.sh @@ -20,7 +20,14 @@ cleanup() { trap cleanup EXIT INT TERM QUIT ssh-keygen -f "$SSH_KEYPATH" -N '' -debvm-create -k "$SSH_KEYPATH.pub" -o "$IMAGE" -a "$ARCHITECTURE" -r "$RELEASE" +set -- +case "$ARCHITECTURE" in + # Booting an armel kernel on qemu is next to impossible. + armel) set -- -- --architecture armhf ;; + # Broken kernel #1029270. + i386) set -- -- --architecture amd64 ;; +esac +debvm-create -k "$SSH_KEYPATH.pub" -o "$IMAGE" -a "$ARCHITECTURE" -r "$RELEASE" "$@" SSH_PORT=2222 timeout 300s debvm-run -s "$SSH_PORT" -i "$IMAGE" & |