Commit 1c5a609
2026-02-14 15:05:12
Changed files (3)
tools
windows-vm-instantiator
tools/windows-vm-instantiator/instantiate.sh
@@ -0,0 +1,121 @@
+#!/bin/bash
+
+set -e
+
+. ./options.sh
+
+if [ ! -f "$AUTOUNATTEND_XML_PATH" ]; then
+ echo "The autounattend.xml could not be found. Bad path?"
+ exit 1
+fi
+
+if [ ! -f "$GUEST_TOOLS_ISO_PATH" ]; then
+ echo "The guest tools ISO could not be found. Bad path?"
+ exit 1
+fi
+
+if [ ! -f $WINDOWS_ISO_PATH ]; then
+ echo "The windows ISO could not be found. Bad path?"
+ exit 1
+fi
+
+echo "Wrapping autounattend.xml into an ISO file for easy mounting into VM."
+mkdir -p ./iso_files
+cp "$AUTOUNATTEND_XML_PATH" ./iso_files/autounattend.xml
+genisoimage -o autounattend.iso -J ./iso_files
+# without -J genisoimage truncates the filename to 8.3 format.
+
+
+echo "Creating disk image."
+if [ "$DISK_USE_QCOW2" = "true" ]; then
+ qemu-img create -f qcow2 -o preallocation=metadata,compat=1.1,lazy_refcounts=on ./disk.qcow2 $DISK_SIZE
+ DISK_FORMAT="qcow2"
+ DISK_NAME="disk.qcow2"
+else
+ qemu-img create -f raw ./disk.img $DISK_SIZE
+ DISK_FORMAT="raw"
+ DISK_NAME="disk.img"
+fi
+
+
+
+echo "Starting installation VM."
+ if [ "$USE_UEFI" = "true" ]; then
+ sudo cp /usr/share/edk2/x64/OVMF_VARS.4m.fd ./my_OVMF_VARS.4m.fd
+
+ sudo qemu-system-x86_64 \
+ -cpu host \
+ -machine type=q35,accel=kvm \
+ -device qemu-xhci,id=usb \
+ -device usb-tablet,bus=usb.0 \
+ -drive file="./$DISK_NAME",format="$DISK_FORMAT" \
+ -drive file=./autounattend.iso,index=1,media=cdrom \
+ -drive file="$GUEST_TOOLS_ISO_PATH",index=2,media=cdrom \
+ -drive file="$WINDOWS_ISO_PATH",index=3,media=cdrom \
+ -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \
+ -drive if=pflash,format=raw,file=./my_OVMF_VARS.4m.fd \
+ -m 12G \
+ -smp 6 \
+ -display none \
+ -monitor stdio \
+ -vnc :0 \
+ -vga std \
+ -net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
+
+ echo "
+ sudo qemu-system-x86_64 \\
+ -cpu host \\
+ -machine type=q35,accel=kvm \\
+ -device qemu-xhci,id=usb \\
+ -device usb-tablet,bus=usb.0 \\
+ -drive file=./$DISK_NAME,format=$DISK_FORMAT \\
+ -drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2/x64/OVMF_CODE.4m.fd \\
+ -drive if=pflash,format=raw,file=./my_OVMF_VARS.4m.fd \\
+ -m 8G \\
+ -smp 4 \\
+ -display none \\
+ -monitor stdio \\
+ -vnc :0 \\
+ -vga std \\
+ -net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
+ " > ./run.sh
+ else
+ qemu-system-x86_64 \
+ -cpu host \
+ -accel kvm \
+ -device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-tablet \
+ -device usb-tablet,bus=ehci.0 \
+ -drive file="./$DISK_NAME",format="$DISK_FORMAT" \
+ -drive file=./autounattend.iso,index=1,media=cdrom \
+ -drive file="$GUEST_TOOLS_ISO_PATH",index=2,media=cdrom \
+ -drive file="$WINDOWS_ISO_PATH",index=3,media=cdrom \
+ -m 12G \
+ -smp 6 \
+ -display none \
+ -monitor stdio \
+ -vnc :0 \
+ -vga std \
+ -net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
+# -nic none
+
+ echo "
+ qemu-system-x86_64 \\
+ -cpu host \\
+ -accel kvm \\
+ -device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-tablet \\
+ -device usb-tablet,bus=ehci.0 \\
+ -drive file=./$DISK_NAME,format=$DISK_FORMAT \\
+ -m 8G \\
+ -smp 4 \\
+ -display none \\
+ -monitor stdio \\
+ -vnc :0 \\
+ -vga std \\
+ -net nic,model=virtio,macaddr="$MAC_ADDRESS" -net bridge,br=br0
+ " > ./run.sh
+
+ fi
+
+
+
+rm -rf ./iso_files
tools/windows-vm-instantiator/options.sh
@@ -0,0 +1,14 @@
+AUTOUNATTEND_XML_PATH=./autounattend.xml
+
+GUEST_TOOLS_ISO_PATH=./guest_tools.iso
+WINDOWS_ISO_PATH=./windows.iso
+
+# raw is best for maximum performance. qcow2 is usable for snapshotting, tho (in theory)
+DISK_USE_QCOW2="false"
+DISK_SIZE="64G"
+
+# Set this to true if you want to use passthrough.
+USE_UEFI="true"
+
+MAC_ADDRESS="fe:fe:00:00:00:00"
+
.gitignore
@@ -0,0 +1,2 @@
+/vms
+/artifacts