summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/debvm-run67
1 files changed, 45 insertions, 22 deletions
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" "$@"