Hello,
I've been working on trying to automate the building of windows VM's in proxmox but I keep running into the same issue when I do it with a bash script.
When I attempt to start the VM after using this bash script I get the following error:
I've been working on trying to automate the building of windows VM's in proxmox but I keep running into the same issue when I do it with a bash script.
Code:
#!/bin/bash
# Configuration variables
NODE="pve"
VMID="1022" # Change this to your desired VM ID
VM_NAME="win11-test" # Change this to your desired VM name
VM_MEMORY="4096" # Memory in MB
VM_CORES="2" # Number of CPU cores
VM_SOCKET="1" # Number of CPU sockets
STORAGE="local-lvm" # Storage location
DISK_SIZE="130G" # Disk size
ISO_STORAGE="/mnt/pve/nfs/template/iso" # Storage location for ISOs
WIN_ISO="Win11_23H2_x64v2_auto.iso" # Windows ISO filename
VIRTIO_ISO="virtio-win-0.1.240.iso" # VirtIO drivers ISO filename
OS_TYPE="win11" # Options: win11, win10, win8, win7, w2k22, w2k19, w2k16, w2k12, w2k8
# Function to check if VM ID already exists
check_vmid() {
if qm status $VMID &>/dev/null; then
echo "Error: VM ID $VMID already exists"
exit 1
fi
}
# Function to check storage availability
check_storage() {
if ! pvesm status | grep -q "^$STORAGE"; then
echo "Error: Storage '$STORAGE' not found"
exit 1
fi
}
# Function to check ISO files
check_isos() {
if [ ! -f "/mnt/pve/nfs/template/iso/$WIN_ISO" ]; then
echo "Warning: Windows ISO not found at /var/lib/vz/template/iso/$WIN_ISO"
fi
if [ ! -f "/mnt/pve/nfs/template/iso/$VIRTIO_ISO" ]; then
echo "Warning: VirtIO ISO not found at /var/lib/vz/template/iso/$VIRTIO_ISO"
fi
}
# Run checks
check_vmid
check_storage
check_isos
# Create and add main disk using VirtIO Block
echo "Creating disk with size $DISK_SIZE..."
pvesm alloc $STORAGE $VMID vm-$VMID-disk-2 $DISK_SIZE || {
echo "Error: Failed to create disk"
qm destroy $VMID
exit 1
}
# Create VM
echo "Creating VM with ID $VMID..."
qm create $VMID --name $VM_NAME --memory $VM_MEMORY --cores $VM_CORES --sockets $VM_SOCKET --net0 virtio,bridge=vmbr0
qm set $VMID --ostype "$OS_TYPE"
qm set $VMID --virtio0 $STORAGE:vm-$VMID-disk-2
# Add Windows installation media
qm set $VMID --ide2 nfs:iso/$WIN_ISO,media=cdrom
# Add VirtIO drivers
qm set $VMID --ide3 nfs:iso/$VIRTIO_ISO,media=cdrom
# Configure boot order (CD-ROM first, then disk)
#qm set $VMID --boot c --bootdisk virtio0
#qm set $VMID --boot order='ide2;ide3;virtio0'
# Enable QEMU Guest Agent
qm set $VMID --agent enabled=1,fstrim_cloned_disks=1
#create TPM
pvesm alloc local-lvm 1022 vm-1022-disk-1.raw 4M
#create EFI Disk
pvesm alloc local-lvm 1022 vm-1022-disk-0.qcow2 4M
# Add TPM support (required for Windows 11)
echo "Configuring Windows 11 specific settings (TPM, UEFI)..."
qm set $VMID --tpmstate0 local-lvm:vm-1022-disk-1.raw,size=4M,version=v2.0
qm set $VMID --machine q35
qm set $VMID --bios ovmf
qm set 1022 --efidisk0 local-lvm:vm-1022-disk-0.qcow2,size=528K,efitype=4m,pre-enrolled-keys=1
# Configure boot order (CD-ROM first, then disk)
qm set $VMID --boot c --bootdisk virtio0
qm set $VMID --boot order='ide2;ide3;virtio0'
# Configure CPU type for better performance
qm set 1022 --cpu cputype=host
# Add tablet device for better mouse handling
qm set 1022 --tablet 1
echo "VM $VMID created successfully. Before starting the VM, ensure:"
echo "1. Windows ISO ($WIN_ISO) is present in $ISO_STORAGE:iso/"
echo "2. VirtIO drivers ISO ($VIRTIO_ISO) is present in $ISO_STORAGE:iso/"
echo ""
echo "During Windows installation, when prompted for drivers, browse the VirtIO ISO (IDE3) and select:"
echo "- For storage: /viostor/w10/amd64/"
echo ""
echo "To download the latest VirtIO drivers:"
echo "wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso -O /var/lib/vz/template/iso/virtio-win.iso"
echo ""
echo "To start the VM:"
echo "qm start $VMID"
When I attempt to start the VM after using this bash script I get the following error:
Any suggestions on what I'm doing wrong?guest has not initialized the the display (yet)