main
  1#!/bin/bash
  2
  3set -e
  4
  5. ./options.sh
  6
  7if [ ! -f "$AUTOUNATTEND_XML_PATH" ]; then
  8    echo "The autounattend.xml could not be found. Bad path?"
  9    exit 1
 10fi
 11
 12if [ ! -f "$GUEST_TOOLS_ISO_PATH" ]; then
 13    echo "The guest tools ISO could not be found. Bad path?"
 14    exit 1
 15fi
 16
 17if [ ! -f $WINDOWS_ISO_PATH ]; then
 18    echo "The windows ISO could not be found. Bad path?"
 19    exit 1
 20fi
 21
 22echo "Wrapping autounattend.xml into an ISO file for easy mounting into VM."
 23mkdir -p ./iso_files
 24cp "$AUTOUNATTEND_XML_PATH" ./iso_files/autounattend.xml
 25genisoimage -o autounattend.iso -J ./iso_files
 26# without -J genisoimage truncates the filename to 8.3 format.
 27
 28
 29echo "Creating disk image."
 30if [ "$DISK_USE_QCOW2" = "true" ]; then
 31	 qemu-img create -f qcow2 -o preallocation=metadata,compat=1.1,lazy_refcounts=on ./disk.qcow2 $DISK_SIZE
 32	 DISK_FORMAT="qcow2"
 33	 DISK_NAME="disk.qcow2"
 34else
 35	 qemu-img create -f raw ./disk.img $DISK_SIZE
 36	 DISK_FORMAT="raw"
 37	 DISK_NAME="disk.img"
 38fi
 39
 40
 41
 42echo "Starting installation VM."
 43	if [ "$USE_UEFI" = "true" ]; then
 44		sudo cp /usr/share/edk2/x64/OVMF_VARS.4m.fd ./my_OVMF_VARS.4m.fd
 45
 46		sudo qemu-system-x86_64 \
 47			-cpu host \
 48			-machine type=q35,accel=kvm \
 49			-device qemu-xhci,id=usb \
 50			-device usb-tablet,bus=usb.0 \
 51			-drive file="./$DISK_NAME",format="$DISK_FORMAT" \
 52			-drive file=./autounattend.iso,index=1,media=cdrom \
 53			-drive file="$GUEST_TOOLS_ISO_PATH",index=2,media=cdrom \
 54			-drive file="$WINDOWS_ISO_PATH",index=3,media=cdrom \
 55			-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \
 56			-drive if=pflash,format=raw,file=./my_OVMF_VARS.4m.fd \
 57			-m 12G \
 58			-smp 6 \
 59			-display none \
 60			-monitor stdio \
 61			-vnc :0 \
 62			-vga std \
 63			-net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
 64
 65		echo "
 66		sudo qemu-system-x86_64 \\
 67			-cpu host \\
 68			-machine type=q35,accel=kvm \\
 69			-device qemu-xhci,id=usb \\
 70			-device usb-tablet,bus=usb.0 \\
 71			-drive file=./$DISK_NAME,format=$DISK_FORMAT \\
 72			-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \\
 73			-drive if=pflash,format=raw,file=./my_OVMF_VARS.4m.fd \\
 74			-m 8G \\
 75			-smp 4 \\
 76			-display none \\
 77			-monitor stdio \\
 78			-vnc :0 \\
 79			-vga std \\
 80			-net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
 81		" > ./run.sh
 82	else
 83		qemu-system-x86_64 \
 84			-cpu host \
 85			-accel kvm \
 86			-device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-tablet \
 87			-device usb-tablet,bus=ehci.0 \
 88			-drive file="./$DISK_NAME",format="$DISK_FORMAT" \
 89			-drive file=./autounattend.iso,index=1,media=cdrom \
 90			-drive file="$GUEST_TOOLS_ISO_PATH",index=2,media=cdrom \
 91			-drive file="$WINDOWS_ISO_PATH",index=3,media=cdrom \
 92			-m 12G \
 93			-smp 6 \
 94			-display none \
 95			-monitor stdio \
 96			-vnc :0 \
 97			-vga std \
 98			-net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
 99#			-nic none
100
101		echo "
102		qemu-system-x86_64 \\
103			-cpu host \\
104			-accel kvm \\
105			-device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-tablet \\
106			-device usb-tablet,bus=ehci.0 \\
107			-drive file=./$DISK_NAME,format=$DISK_FORMAT \\
108			-m 8G \\
109			-smp 4 \\
110			-display none \\
111			-monitor stdio \\
112			-vnc :0 \\
113			-vga std \\
114			-net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
115		" > ./run.sh
116
117	fi
118
119
120
121rm -rf ./iso_files