Files
dotfiles/tools/windows-vm/answer/firstboot.ps1
T
ziadarafat 79125a841b windows-vm: template-first, Packer for rebuilds
Testing a USB device under Windows meant driving a Windows install by hand, and
that turned out to have one genuinely hostile step. The installation media shows
'Press any key to boot from CD or DVD......' for about five seconds; miss it and
the firmware falls through to the empty disk with 'BdsDxe: No bootable option'.
qm sendkey cannot be relied on for it: it injects PS/2 events while a q35 VM has
only a USB keyboard, and the event must land inside that window. In practice the
keys reached the firmware boot menu but never the media prompt.

Two ways out, in the order they are worth the effort:

  template + clone   install once, sysprep /generalize, qm template; every later
                     VM is a clone that boots in about a minute
  Packer             win11.pkr.hcl builds the template unattended. boot_command
                     sends real keystrokes over VNC and repeats the spacebar
                     across the whole prompt window, which is the fix: one press
                     is a race, ten presses is not

The answer file rides on a floppy so Windows finds it at A:\ instead of guessing
which CD-ROM letter it got, and virtio-win is installed so disks and network are
paravirtualised rather than emulated.
2026-11-28 18:11:22 -07:00

17 lines
786 B
PowerShell

# Runs once on first logon in a freshly installed guest, before Packer's
# provisioners take over over WinRM. Keep it short: everything heavier is a
# Packer provisioner so it is visible in the build log.
$ErrorActionPreference = 'SilentlyContinue'
Set-Content -Path 'C:\firstboot.txt' -Value "firstboot $([DateTime]::UtcNow.ToString('s'))"
# WinRM is how Packer drives the rest of the build.
Enable-PSRemoting -Force -SkipNetworkProfileCheck
Set-Item WSMan:\localhost\Service\Auth\Basic -Value $true
Set-Service WinRM -StartupType Automatic
Start-Service WinRM
Set-NetFirewallRule -DisplayGroup 'Windows Remote Management' -Enabled True
# A test guest that sleeps, never hibernates, and has no lock screen.
powercfg /change standby-timeout-ac 0
powercfg /change monitor-timeout-ac 0