Run Windows in KVM with dedicated GPU
This is also known as GPU or PCIe passthrough. All notes based and tested on Debian Buster.
Activate IOMMU in /etc/default/grub. On intel platforms replace amd_iommu with intel_iommu.
| |
and apply changes with
| |
Some tutorials suggest to blacklist the graphics driver, e.g. nouveau, however if the host GPU uses the same driver this is not a viable option. Instead, use the vfio driver for the VM GPU. Run
| |
to identify the Vendor ID and Device ID of the devices for the VM. Some graphics cards use two or even more devices, usually one VGA controller, one Audio device and sometimes USB devices. Create and edit /etc/modprobe.d/vfio.conf and add the VID:DID pairs, e.g.
| |
If for any reason another driver claims the device before vfio-pci is able to, check if the module is compiled into the kernel or not, e.g. if xhci_hcd is claiming the device instead check
| |
If the module is compiled in CONFIG_USB_XHCI_HCD=y then search for a unbind/rebind solution or recompile your kernel. If not CONFIG_USB_XHCI_HCD=m then add
| |
to /etc/modprobe.d/vfio.conf
Add the following modules to /etc/initramfs-tools/modules
| |
and apply changes with
| |
Create and run iommu_info.sh (Source: https://wiki.archlinux.org/index.php/PCI_passthrough_via_OVMF)
| |
Check if the desired devices are listed in a separate IOMMU group, on most consumer grade hardware this will not be the case. If yes, skip the ACS override patch section. If no, kernel needs to be compiled with ACS override patch from https://queuecumber.gitlab.io/linux-acs-override/
See https://kernel-team.pages.debian.net/kernel-handbook/ch-common-tasks.html for some hints on how to quickly patch build a kernel on Debian.
Once the kernel with ACS override patch is installed edit /etc/default/grub
| |
and apply changes with
| |
Then add PCIe devices to Windows VM, run it and install drivers for graphics card. Nvidia drivers will refuse to start inside a VM throwing error 43 (see https://mathiashueber.com/fighting-error-43-nvidia-gpu-virtual-machine/).
Therefore it might be necessary to edit the VM config to hide KVM from guest
| |
| |
Now the GPU driver should start as expected.