lima icon indicating copy to clipboard operation
lima copied to clipboard

POC: add Windows guest support via autounattend.xml

Open ashwat287 opened this issue 6 months ago • 6 comments

Updated with dual-arch support. Both amd64 and arm64 work end-to-end now. Ref: #4852

What's in this commit

  • WINDOWS OS type added to limatype and validation
  • Separate autounattend.xml templates for amd64 and arm64 (3-pass: windowsPE, specialize, oobeSystem)
  • Windows guests go through generateWindowsISO() which produces a Joliet-labeled ISO
  • hack/gen-autounattend-iso.go dev tool for standalone testing (pass -arch amd64 or -arch arm64)
  • Unit test for template rendering

Design choices

  • arm64 uses NVMe for the disk. WinPE ARM has stornvme.sys built-in, so there's no need for virtio-win.iso.
  • No product keys in either template. Removed per @AkihiroSuda's feedback. Edition selection is handled by image index.
  • OpenSSH server is installed and started during OOBE so Lima's host-agent can connect.

Testing

Tested both architectures on macOS.

amd64 (x86_64)

Windows 10 consumer ISO from microsoft.com, version 22H2 multi-edition. Pro is image index 6.

go run hack/gen-autounattend-iso.go -arch amd64 -o autounattend.iso
qemu-img create -f qcow2 disk.qcow2 64G
cp /opt/homebrew/share/qemu/edk2-i386-vars.fd ovmf_vars.fd

qemu-system-x86_64 -m 4G -smp 2 -machine q35 \
  -drive if=pflash,format=raw,readonly=on,file=/opt/homebrew/share/qemu/edk2-x86_64-code.fd \
  -drive if=pflash,format=raw,file=ovmf_vars.fd \
  -cdrom /path/to/Win10_22H2_English_x64v1.iso \
  -drive file=autounattend.iso,media=cdrom,index=3 \
  -drive file=disk.qcow2,index=0,media=disk,format=qcow2 \
  -nic user,hostfwd=tcp::2222-:22

This runs under emulation on Apple Silicon so it's slow, but completes successfully.

Screenshot 2026-05-15 at 2 35 07 AM

arm64 (aarch64)

Windows 11 ARM64 25H2 ISO. Pro is image index 3. Runs natively via HVF.

go run hack/gen-autounattend-iso.go -arch arm64 -o autounattend.iso
qemu-img create -f qcow2 disk.qcow2 64G
dd if=/dev/zero of=ovmf_vars.fd bs=1M count=64

qemu-system-aarch64 \
  -machine virt,accel=hvf \
  -cpu host \
  -m 4G -smp 4 \
  -drive if=pflash,format=raw,readonly=on,file=/opt/homebrew/share/qemu/edk2-aarch64-code.fd \
  -drive if=pflash,format=raw,file=ovmf_vars.fd \
  -drive file=disk.qcow2,if=none,id=hd0,format=qcow2 \
  -device nvme,serial=lima0,drive=hd0 \
  -device qemu-xhci \
  -device usb-kbd \
  -device usb-tablet \
  -drive file=/path/to/Win11_25H2_English_Arm64.iso,if=none,id=cdrom0,media=cdrom,readonly=on \
  -device usb-storage,drive=cdrom0 \
  -drive file=autounattend.iso,if=none,id=unattend,media=cdrom,readonly=on \
  -device usb-storage,drive=unattend \
  -device ramfb \
  -nic user,hostfwd=tcp::2222-:22

The arm64 command is longer because the virt machine has no built-in controllers (no SATA, no IDE, no VGA), so each device needs to be added explicitly. On amd64, q35 provides all of that.

Screenshot 2026-05-16 at 6 16 57 AM

Result

Both architectures install fully unattended: partitioning, image extraction, OOBE, and OpenSSH server all complete without manual interaction.

After install completes: ssh -p 2222 User@localhost

Notes

  • arm64 requires -cpu host, not -cpu max. Using max with HVF causes page faults.
  • UEFI variable store needs to be 64MB on arm64 (4MB on x86).
  • usb-kbd/usb-tablet are needed on arm64 for UEFI console initialization.

Changes since last review

  • Removed product key from both templates
  • Added arm64 template with NVMe disk (no virtio-win.iso needed)
  • Dropped -boot d from amd64 (OVMF ignores it)

ashwat287 avatar May 15 '26 06:05 ashwat287

Can you share info about your testing environment?

unsuman avatar May 15 '26 10:05 unsuman

Host Machine:

  • CPU: Apple M5 (arm64)
  • RAM: 16GB
  • OS: macOS Tahoe
  • Architecture: Apple Silicon

QEMU Setup:

  • Binary: qemu-system-x86_64 (emulates x86_64 guest on arm64 host)
  • Acceleration: HVF (Apple's Hypervisor.framework), but since guest arch != host arch, CPU instructions are emulated
  • Machine type: q35 (modern Intel chipset with PCIe, AHCI, ICH9)
  • RAM: 4GB (-m 4G)
  • vCPUs: 2 (-smp 2)
  • Install source: Homebrew QEMU package (brew install qemu)

Guest:

  • ISO: Windows 10 64-bit (x86_64), version 22H2 multi-edition
  • Source: https://www.microsoft.com/en-in/software-download/windows10ISO
  • Edition: Pro (selected via /IMAGE/INDEX 6 in autounattend.xml)

ashwat287 avatar May 15 '26 11:05 ashwat287

Also tried to test in WSL2 before switching to macOS. But it failed probably because of nested virtualization.

The ideal way to test would be to test it in x86_64 linux machine to avoid additional performance baggage which comes with emulation. This I haven't tried yet.

ashwat287 avatar May 15 '26 11:05 ashwat287

since guest arch != host arch, CPU instructions are emulated

Can we support the ARM version of Windows?

AkihiroSuda avatar May 15 '26 14:05 AkihiroSuda

since guest arch != host arch, CPU instructions are emulated

Can we support the ARM version of Windows?

Absolutely! I have included the testing section for ARM version in the description. It's much faster, takes 5-10 mins for the boot process to complete. (emulation overhead got dropped + hvf acceleration)

ashwat287 avatar May 16 '26 14:05 ashwat287

AI code review: https://jandubois.github.io/lima/20260519-100641-pr-4985.html

jandubois avatar May 19 '26 21:05 jandubois

Thanks, we have merged this one:

  • https://github.com/lima-vm/lima/pull/5138

AkihiroSuda avatar Jul 02 '26 07:07 AkihiroSuda