This is an old revision of the document!
Windows VM Tips
For using a windows VM via libvirt/KVM/qemu/virt-manager
Installation
Only packages really needed (Ubuntu Server 22.04) are libvirt
, qemu-kvm
, libvirt-daemon-system
.
Add users who will use the VM to libvirt
group.
Creating VM
If libvirtd.service
is running (it should be) then just connect and create using virt-manager
(either locally or remotely via ssh, e.g. virt-manager -c qemu+ssh://[ip]/system
)
I also needed the virtio Windows drivers to add as a disc when booting so that Windows could see the virtio hard drive. After install I ran the setup file inside which enabled some GPU stuff.
Install SPICE guest tools to allow console resizing on Window resizing, and clipboard integration.
I found that virtio video driver still has some bugs - SPICE will stop resizing after rebooting after installing spice guest tools and will never work again. QXL video works perfectly.
Install location
By default libvirt/virt-manager/something puts the disk .qcow2s in /var/lib/libvirt/images
(root access required to read).
CPU usage
Windows is a nightmare and sucks up craploads of CPU all the time because of course it does.
Useful commands to debug some of this:
# perf kvm –host top -p `pidof qemu-system-x86_64`
- Shows how often qemu is executing various functions,
[k]
for kernel space and[.]
for user space. - There is also one function used for making the switch to guest space and it accounts for all time spent there. On a 4.14 kernel with intel cpu that function is
vmx_vcpu_run
but it might differ.
# perf stat -e 'kvm:*' -a – sleep 1
- This should show the reason a VM is doing
VM_EXIT
. Values should be roughly “less than 1000”.
# perf kvm –host stat live
- This one should show what the VM is doing? Apparently most time % should be
HLT
otherwise it's not idle.
It may also be a good idea to use powercfg
to find out why the OS is waking up lots, if it is.
Enlightenments
These tell Windows it's running in a VM.
In the XML for the machine, change the <features>
and <clock>
sections to the following:
Features:
<features> <acpi/> <apic/> <pae/> <hyperv> <relaxed state='on'/> <vapic state='on'/> <spinlocks state='on' retries='8191'/> <vpindex state='on'/> <synic state='on'/> <stimer state='on'/> <reset state='on'/> <vendor_id state="on" value="KVM Hv"/> <frequencies state="on"/> </hyperv> </features>
Clock:
<clock offset="utc"> <timer name="hpet" present="no"/> <timer name="hypervclock" present="yes"/> </clock>
hpet
as yes
causes higher idle usage, so I opted for no
.
Additionally, some sources say to keep the following lines:
<timer name='rtc' tickpolicy='catchup'/> <timer name='pit' tickpolicy='delay'/>
However, some recommend removing them, which I opted for.
For me these enlightenments reduced idle CPU by 4-5x (from 45%+ to ~10-12% while running Milestone XProtect in the background, with no cams set up).