Reworked to handle architectures with specific qemu setups.
authorRalph Ronnquist <rrq@rrq.au>
Thu, 19 Sep 2024 11:51:42 +0000 (21:51 +1000)
committerRalph Ronnquist <rrq@rrq.au>
Thu, 19 Sep 2024 11:51:42 +0000 (21:51 +1000)
vm.sh

diff --git a/vm.sh b/vm.sh
index 59e937b847d80e897c770f36bec5f874f380915a..c75ff8a5308a96d9a6688cc8f424d175f71b5d82 100755 (executable)
--- a/vm.sh
+++ b/vm.sh
@@ -24,41 +24,65 @@ fi
 case "$ARCH" in
     arm64)
        QEMU=qemu-system-aarch64
-       CPU=cortex-a53
-       NET=virtio-net-device
+       ARGS=(
+           -M virt -cpu cortex-a53 -m 4G -nographic -serial stdio
+           -kernel arm64/vmlinuz -initrd arm64/initrd.gz
+           -append "console=ttyAMA0 root=/dev/vda1 roottype=ext4$APPEND"
+           -chardev socket,id=QEMU,server=on,wait=off,path=QEMU-arm64
+           -mon chardev=QEMU,mode=readline
+           -device virtio-blk-device,drive=hd
+           -drive if=none,id=hd,file=$IMG,format=raw
+           -device virtio-net-device,netdev=unet
+           -netdev vde,sock=/run/vde.ctl,id=unet
+       )
        ;;
     armhf)
        QEMU=qemu-system-arm
-       CPU=cortex-a15
-       #USB="-device qemu-xhci -device usb-host"
-       NET=virtio-net-device
+       ARGS=(
+           -M virt -cpu cortex-a15 -m 4G -nographic -serial stdio
+           -kernel armhf/vmlinuz -initrd armhf/initrd.gz
+           -append "console=ttyAMA0 root=/dev/vda1 roottype=ext4$APPEND"
+           -chardev socket,id=QEMU,server=on,wait=off,path=QEMU-armhf
+           -mon chardev=QEMU,mode=readline
+           -device virtio-blk-device,drive=hd
+           -drive if=none,id=hd,file=$IMG,format=raw
+           -device virtio-net-device,netdev=unet
+           -netdev vde,sock=/run/vde.ctl,id=unet
+       )
+       ;;
+    amd64)
+       QEMU=qemu-system-x86_64
+       ARGS=(
+           -M pc,accel=kvm -cpu qemu64 -m 4G -nographic -serial stdio
+           -kernel amd64/vmlinuz -initrd amd64/initrd.gz
+           -append "console=ttyS0 root=/dev/vda1 roottype=ext4$APPEND"
+           -chardev socket,id=QEMU,server=on,wait=off,path=QEMU-amd64
+           -mon chardev=QEMU,mode=readline
+           -device virtio-blk-pci,drive=hd
+           -drive if=none,id=hd,file=$IMG,format=raw
+           -device virtio-net-pci,netdev=unet
+           -netdev vde,sock=/run/vde.ctl,id=unet
+       )
+       ;;
+    i386)
+       QEMU=qemu-system-i386
+       ARGS=(
+           -M pc,accel=kvm -cpu qemu32 -m 4G -nographic -serial stdio
+           -kernel i386/vmlinuz -initrd i386/initrd.gz
+           -append "console=ttyS0 root=/dev/vda1 roottype=ext4$APPEND"
+           -chardev socket,id=QEMU,server=on,wait=off,path=QEMU-i386
+           -mon chardev=QEMU,mode=readline
+           -device virtio-blk-pci,drive=hd
+           -drive if=none,id=hd,file=$IMG,format=raw
+           -device virtio-net-pci,netdev=unet
+           -netdev vde,sock=/run/vde.ctl,id=unet
+       )
        ;;
     *)
-       echo "unknown $1" >&2
+       echo "unknown \$1=$1" >&2
        exit 1
        ;;
 esac
 
-ARGS=(
-    -M virt -cpu $CPU -m 4G
-    # boot setup
-    -kernel $ARCH/vmlinuz
-    $INITRD
-    -append "console=ttyAMA0 root=/dev/vda1 roottype=ext4$APPEND"
-    -serial stdio
-    # qemu monitor interface
-    -chardev socket,id=QEMU-$ARCH,server=on,wait=off,path=QEMU
-    -mon chardev=QEMU-$ARCH,mode=readline
-    # graphics setup
-    -nographic
-    # harddrive setup
-    -device virtio-blk-device,drive=hd
-    -drive if=none,id=hd,file=$IMG,format=raw
-    # USB setup
-    $USB
-    # network setup
-    -device $NET,netdev=unet
-    -netdev vde,sock=/run/vde.ctl,id=unet
-)
-
+echo $QEMU "${ARGS[@]}" | sed 's/ -/\n -/g' >&2
 exec $QEMU "${ARGS[@]}"