Skip to content
Snippets Groups Projects
Name Last commit Last update
prepare/begin
release/end
README.md

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:

  1. You are running on Linux using QEMU/KVM and Virt Manager
  2. You are running KDE Plasma 6 (This is mainly for the line specified in start.sh)
  3. You are running a compatible NVIDIA GPU (any NVIDIA card that supports vGPU/IOMMU)
  4. 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

  1. Create any VM in QEMU/KVM Virt Manager
  2. Make sure IOMMU is on for your CPU:
    • either append amd_iommu or intel_iommu depending on your CPU, and then add iommu=pt into grub linux default commands. Then make sure IOMMU is enabled in bios.
    • Reboot your computer, and verify IOMMU is on.
  3. Apply this XML in the <features> tag:
    <features>
     ...
       <kvm>
           <hidden state="on"/>
       </kvm>
     ...
    </features> 
  4. Move the prepare/ and release/ 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/
  5. Add your user to the following groups: usermod -aG kvm,input,libvirt username
  6. Edit the line in start.sh that kills all plasma services to reflect your username
    systemctl --user -M username@ stop plasma*
  7. Run lspci and get the PCI addresses for your GPU
    08: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)
  8. 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
  9. Connect your USB devices and PCI devices (GPU) to the VM.
  10. 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)
  11. Profit :)