Disclaimer
This repository's main intention is for my own memory on how to replicate GPU passthrough. Chances are I will make this more in depth. You can use this quick summary in conjunction with the numerous guides that exist on how to replicate this process.
Getting started
This guide assumes a few things:
- You are running on Linux using QEMU/KVM and Virt Manager
- You are running KDE Plasma 6 (This is mainly for the line specified in
start.sh
) - You are running a compatible NVIDIA GPU (any NVIDIA card that supports vGPU/IOMMU)
- You have a virtual machine ready and working (Windows or otherwise). This is assuming you have
libvirtd
correctly running and the default network on autostart.
Small notes (important)
- The display/consoles will not come back after VM shutdown unless the plymouth boot screen is enabled. This could be due to GPU utilization with EFI framebuffers on boot time, and also could be due to video parameters in grub.
Installation
- Create any VM in QEMU/KVM Virt Manager
- Make sure IOMMU is on for your CPU:
- either append
amd_iommu
orintel_iommu
depending on your CPU, and then addiommu=pt
into grub linux default commands. Then make sure IOMMU is enabled in bios. - Reboot your computer, and verify IOMMU is on.
- either append
- Apply this XML in the
<features>
tag:<features> ... <kvm> <hidden state="on"/> </kvm> ... </features>
- Move the
prepare/
andrelease/
directories into the hooks folder for the VM located at/etc/libvirt/hooks/qemu.d/vm_name/
.- example for windows:
/etc/libvirt/hooks/qemu.d/win10/
- example for windows:
- Add your user to the following groups:
usermod -aG kvm,input,libvirt username
- Edit the line in
start.sh
that kills all plasma services to reflect your usernamesystemctl --user -M username@ stop plasma*
- Run
lspci
and get the PCI addresses for your GPU08:00.0 VGA compatible controller: NVIDIA Corporation GA106 [GeForce RTX 3060 Lite Hash Rate] (rev a1) 08:00.1 Audio device: NVIDIA Corporation GA106 High Definition Audio Controller (rev a1)
- Have the start and stop scripts reflect the addresses from the output of
lspci
- From
start.sh
# Detach GPU devices from host # Use your GPU and HDMI Audio PCI host device virsh nodedev-detach pci_0000_08_00_0 virsh nodedev-detach pci_0000_08_00_1
- From
stop.sh
# Attach GPU devices to host # Use your GPU and HDMI Audio PCI host device virsh nodedev-reattach pci_0000_08_00_0 virsh nodedev-reattach pci_0000_08_00_1
- From
- Connect your USB devices and PCI devices (GPU) to the VM.
- It should be good to go at this point. Make sure you have a VNC server running on the guest (and make sure you can access it) or an SSH connection to your host just in case you need to either take control or kill the VM. (VNC server is not necessary after first successful boot. Keeping an SSH connection that you can use on a spare device may prove beneficial)
- Profit :)