Simplified Qemu Linux Host, Windows 11 Guest Install
2025.04.08
I had significant problems getting Microsoft Windows 11 guest
operating system installed within a Linux Qemu host. The main
problem, likely caused by qemu needing "-machine type=q35" else
Windows 11 install would constantly complain about minimum system
requirements, when using the default computernewb.com recommended
incantation.
Ensuring TPM was a second hurdle. I have yet to successfully get
pass-through TPM working, however swtpm emulation is working.
Below are simplified instructions for installing Windows 11 within
Linux Qemu 64-bit host, along with subsequent documentation for
installing RedHat/Fedora VirtIO drivers.
=====
INITIAL INSTALL
First, install requisite additional packages for Qemu Windows 11
guest:
BIOS/EFI files: edk2-ovmf software package
TPM Emulation: swtpm software package
Create your operating system disk image:
$ qemu-img create -f qcow2 win11.img 80G
2) Copy over BIOS/EFI files:
$ cp /usr/share/edk2/x64/OVMF_CODE.secure.4m.fd ./
$ cp /usr/share/edk2/x64/OVMF_VARS.4m.fd ./
Create, mark executable and run the following script once augmented
with your file names:
#!/bin/sh
# create a swtpm socket, and will automatically exit upon
qemu exit.
mkdir /tmp/mytpm1 ; swtpm socket --tpmstate dir=/tmp/mytpm1
--tpm2 --ctrl type=unixio,path=/tmp/mytpm1/swtpm-sock &
# minimal incantation for qemu win11 guest
qemu-system-x86_64 -hda win11.img -cdrom
/mnt/win-share/microsoft/windows-11/Win11_24H2_English_x64.iso
-machine type=q35 -cpu host -smp 2 -accel kvm -m 8G -drive
if=pflash,format=raw,read-only=on,file=./OVMF_CODE.secure.4m.fd
-drive if=pflash,format=raw,file=./OVMF_VARS.4m.fd -chardev
socket,id=chrtpm,path=/tmp/mytpm1/swtpm-sock -tpmdev
emulator,id=tpm0,chardev=chrtpm -device
tpm-tis,tpmdev=tpm0,id=tpm0 -nic none -boot d
Subsequent ordinary boots will need "-boot d" changed to "-boot c"
for booting the hard disk image by default. The "-nic none" is
optional. These options appear to be the minimal required options
for installing Windows 11.
=====
WINDOWS OPERATING SYSTEM GUEST VIRTIO DRIVERS
Windows operating system guest drivers, for providing higher
resolution graphics drivers (eg. -vga virtio), the Fedora project
provides Qemu Windows operating system guest drivers (eg. man qemu
search for virtio drivers) A third party site is designated for
providing pre-compiled (eg. ISO, RPM) binaries, as the binaries
cannot be hosted on the Fedora Project website.
Creating Windows virtual machines using ... virtIO drivers
https://docs.fedoraproject.org/en-US/quick-docs/creating-windows-virtual-machines-using-virtio-drivers/index.html
virt-io scripts making ISOs/RPMs
https://github.com/virtio-win/virtio-win-pkg-scripts/blob/master/README.md
Add -cdrom ./virtio-win-0.1.271.iso to qemu start
incantation, and initiate the driver install from cdrom media.
=====
VIRTIO SCSI DRIVER
For performance migrate from the default Qemu storage driver to
using the virtio-scsi-pci driver, with the "-drive" option
supporting "discard=on" for flash media trim support,
versus using defragmentation on flash media. A good explanation of
integrating VIRTIO scsi drivers along with ID and number schemes:
How to emulate block devices with QEMUHow to emulate block devices
with QEMU
Section: virtio-scsi
https://blogs.oracle.com/linux/post/how-to-emulate-block-devices-with-qemu#virtio-scsi
In brief, virtio-scsi-pci is the newer driver, while virtio-scsi-blk
is an older driver.
-device virtio-scsi-pci,id=scsi0,num_queues=4 -device
scsi-hd,drive=drive0,bus=scsi0.0,channel=0,scsi-id=0,lun=0 -drive
file=win11.img,if=none,id=drive0,discard=on
=====
VIRTIO NET DRIVER
For performance, migrate from using the default Qemu network driver
to the virtio-net-pci driver. In brief:
-netdev user,id=network0,restrict=off -nic
user,model=virtio-net-pci,mac=00:00:00:00:00:00 -vga virtio
=====
VIRTIO VGA GL 3D Vulkan Acceleration
Supposedly the latest forwarding 3D acceleration through
Vulkan/Mesa. Work is apparently halfway completed? Vulkan works
great with open source Intel Arc/Xe graphics cards. Guessing, in the
future, keep an eye on this snippet of incantation Qemu options.
-device virtio-vga-gl,hostmem=4G,blob=true,venus=true -vga none
-display gtk,gl=on,show-cursor=on
WARNING: This seems to break the previously installed Virtio driver
install for some reason. May require uninstalling/reinstalling
Virtio drivers.
=====
TODO: Not sure if removing some of the OVMF files or swapping
emulated TPM/swtpm for pass-through TPM will work or not.
FIXME: Mouse grab on hover seems to be ignored, only allowing grab
mouse, likely due to OVMF BIOS/EFI files.
NOTE: For pass-through TPM devices, the default TPM (eg. /dev/tpm0,
/dev/tpmrm0) device file permissions are restricted to only root. An
optional UDEV rules file is needed, or explicitly changing the
default permissions using chmod. (eg. /etc/udev/rules.d/99-tpm.rules
file) Also needed, a cancel file, Ubuntu virt-manager seems to
substitute using file descriptors. (eg. /dev/fd/1)
NOTE: All other posts within the public Internet as of this date,
typically omits the above necessary information, posting parts or
older non-working incantations.
=====
REFERENCES
QEMU/Guests/Windows 11
https://computernewb.com/wiki/QEMU/Guests/Windows_11
ArchLinux Forum: Example to run a virtual machine with Qemu
https://bbs.archlinux.org/viewtopic.php?id=303884