X-Git-Url: https://git.rrq.au/?a=blobdiff_plain;f=vm.sh;h=452b475209e6d86001943c9160b2eca4422ca798;hb=b94399bd48eaa7b022bf031279c9543c10487bcd;hp=74274e606fbc6839c9a64d08fae61fbc332e806d;hpb=4cacdc777c1fa8f8ddae16f3f100de6a3829cab7;p=rrq%2Ftiniest.git diff --git a/vm.sh b/vm.sh index 74274e6..452b475 100755 --- a/vm.sh +++ b/vm.sh @@ -1,19 +1,77 @@ #!/bin/bash # -# QEMU setup for trial3 VM +# QEMU setup for trial VM -if [ -n "$EFI" ] ; then - BOOT="-bios /usr/share/OVMF/OVMF_CODE.fd" +ISO=${ISO:-tiniest.iso} + +N="12345678" +if [ ${#1} = 1 ] && [ "${N#*$1}" != "$N" ] ; then + REPLY=$1 else - BOOT="-boot menu=on" + VARIANT=( + "use bootimage.raw as harddisk with legacy boot (and boot menu)" + "use bootimage.raw as harddisk with UEFI boot" + "use ${ISO} as harddisk with legacy boot (and boot menu)" + "use ${ISO} as harddisk with UEFI boot" + "use ${ISO} as cdrom with legacy boot (and boot menu)" + "use ${ISO} as cdrom with UEFI boot" + "use ${ISO} as USB disk with legacy boot (and boot menu)" + "use ${ISO} as USB disk with UEFI boot" + ) + + select V in "${VARIANT[@]}" ; do + [ -z "$V" ] || break + done fi +[ -z "$REPLY" ] && exit 0 + +FILE=bootimage.raw +[ $REPLY -ge 3 ] && FILE=${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 - -serial mon:stdio -echr 0x1c - -vga qxl + -m 2G -M pc,accel=kvm -cpu host -vga qxl + -serial mon:stdio -echr 0x1c # Using ^\ as meta character $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" qemu-system-x86_64 ${ARGS[@]} +tput reset # EFI boot messes up the terminal +