Windows 11 VM in Linux

#Windows #Linux #KVM #Libvirt

This procedure has been tested in Arch Linux. Other distributions may have slightly different package requirements or naming conventions.

Required packages

ISO images needed

Extract Windows OEM product key from host system

If the system was shipped with a pre-installed Windows OS, it has the Windows licencing information in BIOS

$ sudo strings /sys/firmware/acpi/tables/MSDM
MSDMU
TLENOVOTP-N32  p
PTEC
AAAA1-AAAAA-AAAA1-1A1AA-11AA1 ← not my real product key

The last line is the product key

Create a new VM


4 GB of RAM and 2 vCPUs are the minumum requirements for Windows 11


Windows 11 requires a minimum of 64 GB of disk space


Make sure you check the box “Customize configuration before install” and hit “Finish”

Change the “Firmware” setup to UEFI x86_64: /usr/share/edk2-ovmf/x64/OVMF_CODE_secboot.fd

You can now hit “Begin Installation” and proceed with the Windows 11 installation and initial setup

Install Windows 11

OS installation

Make sure you select the same OS edition as the one for which you have an OEM licence (e.g.: Windows 11 Professional).

Initial setup

If you don't want to enrol a Microsoft Live account, answer that you want to use a Work or Active Directory account (Windows 11 Professional and up): this will take you to the local account creation screens.

Paravirtualized drivers

VirtIO drivers provide better performance and should be used when possible. The Spice video drivers also allow for seamless mouse cursor movement, dynamic resolution changes as well as drag-and-drop operations from Gnome to the Windows desktop (one way only)

VirtIO drivers installation

Change system disk (SATA→VirtIO)

The default system disk is created as a SATA drive. Changing it to VirtIO immediately will not work because Windows has to load the VirtIO disk drivers at least once before it is able to boot from a VirtIO system disk. We need to created dummy VirtIO disk first.

Initial disk configuration:

<disk type="file" device="disk">
  <driver name="qemu" type="qcow2"/>
  <source file="/var/lib/libvirt/images/Windows11.qcow2"/>
  <target dev="sda" bus="sata"/>
</disk>

Modified disk configuration:

<disk type="file" device="disk">
  <driver name="qemu" type="qcow2"/>
  <source file="/var/lib/libvirt/images/Windows11.qcow2"/>
  <target dev="vda" bus="virtio"/>
  <address type="pci" domain="0x0000" bus="0x05" slot="0x00" function="0x0"/>
</disk>

Other devices

Now that the VirtIO drivers have been installed in Windows, you can change the NIC type from Intel e1000e to VirtIO via the virt-manager GUI

Activate Windows

Use the product key extracted from BIOS information (see above)

You can now proceed witht he system updates and start using the Windows VM.