X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vm.sh;h=5d8b79c98fdb1b7b762fe6317971dd1b22fcf8e3;hb=44364c01c3173388a1dd0617a08839fb9c2a9b78;hp=d3f535dbb6eb03ec316d4eddae9a5b38cfd051c8;hpb=52b051d78ead51fe4ab0513543dbfc619fd6a337;p=rrq%2Ftiniest.git diff --git a/vm.sh b/vm.sh index d3f535d..5d8b79c 100755 --- a/vm.sh +++ b/vm.sh @@ -2,19 +2,72 @@ # # QEMU setup for trial VM -BOOT="-boot menu=on" -[ -z "$EFI" ] || BOOT="-bios /usr/share/OVMF/OVMF_CODE.fd" +N="12345678" +if [ ${#1} = 1 ] && [ "${N#*$1}" != "$N" ] ; then + REPLY=$1 +else + VARIANT=( + "use bootimage.raw as harddisk with legacy boot (and boot menu)" + "use bootimage.raw as harddisk with UEFI boot" + "use tiniest.iso as harddisk with legacy boot (and boot menu)" + "use tiniest.iso as harddisk with UEFI boot" + "use tiniest.iso as cdrom with legacy boot (and boot menu)" + "use tiniest.iso as cdrom with UEFI boot" + "use tiniest.iso as USB disk with legacy boot (and boot menu)" + "use tiniest.iso as USB disk with UEFI boot" + ) -[ -d disk.raw ] || dd if=/dev/zero of=disk.raw bs=1G count=0 seek=8 - + select V in "${VARIANT[@]}" ; do + [ -z "$V" ] || break + done +fi +[ -z "$REPLY" ] && exit 0 + +FILE=bootimage.raw +[ $REPLY -ge 3 ] && FILE=tiniest.iso +MEDIA=disk +[ $REPLY -ge 5 ] && MEDIA=cdrom +[ $REPLY -ge 7 ] && MEDIA=usb + +case "$MEDIA" in + disk) + DISK2="-drive index=1,format=raw,media=$MEDIA,file=$FILE" + ;; + usb) + USB=" + -device qemu-xhci,id=xhci + -drive if=none,id=stick,format=raw,media=disk,file=${FILE} + -device usb-storage,bus=xhci.0,port=1,drive=stick + " + ;; + cdrom*) + DISK2="-drive index=1,format=raw,media=$MEDIA,file=$FILE" + ;; +esac + +BOOT="-boot menu=on,splash=boot.jpg,splash-time=60000" +[ $(( $REPLY % 2 )) -eq 0 ] && BOOT="-bios /usr/share/OVMF/OVMF_CODE.fd" + +case "$NET" in + vde) + NET="-net nic,model=e1000 -net vde,sock=/run/vde.ctl" + ;; + *) + NET= + ;; +esac + +[ -e disk.raw ] || dd if=/dev/zero of=disk.raw bs=1G count=0 seek=8 ARGS=( - -m 2G -M pc,accel=kvm -cpu host + -m 2G -M pc,accel=kvm -cpu host -vga qxl -serial mon:stdio -echr 0x1c # Using ^\ as meta character - -vga qxl $BOOT -drive index=0,id=disk,media=disk,format=raw,file=disk.raw - -drive index=1,id=boot,media=disk,format=raw,file=bootimage.raw + $DISK2 + $USB + $NET ) +echo "${ARGS[*]}" | sed "s/ -/\n -/g" exec qemu-system-x86_64 ${ARGS[@]}