Using GPU passthrough in KVM/QEMU and displaying it in a window on the host OS involves configuring your virtual machine (VM) to leverage the dedicated GPU for better performance, while also ensuring you can interact with the VM from a window on your host system. Here’s a guide on how to achieve this:
Step-by-Step Guide to Use GPU Passthrough in KVM/QEMU:
Prerequisites:
- Compatible Hardware:
- A CPU that supports VT-d (Intel) or AMD-Vi (AMD) for IOMMU (Input-Output Memory Management Unit).
- A compatible motherboard with IOMMU support (ensure it’s enabled in the BIOS/UEFI).
- A dedicated GPU for passthrough and another GPU for your host system display.
- Virtualization software: KVM/QEMU with libvirt.
2. Install Required Packages:
- Install the necessary packages for virtualization:
bash sudo dnf install qemu-kvm libvirt virt-manager virt-viewer
3. Enable IOMMU in the BIOS/UEFI:
- Reboot your computer and enter the BIOS/UEFI settings.
- Look for Intel VT-d or AMD IOMMU and enable it.
- Save changes and restart.
4. Enable IOMMU in the Kernel:
- Edit the GRUB configuration:
bash sudo nano /etc/default/grub
- Add
intel_iommu=on
(for Intel) oramd_iommu=on
(for AMD) to theGRUB_CMDLINE_LINUX
line:bash GRUB_CMDLINE_LINUX="... intel_iommu=on"
- Update the GRUB configuration:
bash sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg # For UEFI systems sudo grub2-mkconfig -o /boot/grub2/grub.cfg # For BIOS systems
- Reboot your system.
5. Check IOMMU Groups:
- Check if the GPU and its associated devices (like audio) are in separate IOMMU groups:
bash find /sys/kernel/iommu_groups/ -type l
- Each GPU component should be in its own IOMMU group.
6. Bind the GPU to VFIO-PCI Driver:
- Identify the PCI IDs of your GPU and its associated audio device using:
bash lspci -nn | grep VGA lspci -nn | grep Audio
- Create a configuration file for the VFIO driver:
bash sudo nano /etc/modprobe.d/vfio.conf
- Add the GPU PCI IDs to the file:
bash options vfio-pci ids=1002:67df,1002:aaf0
- Replace
1002:67df
and1002:aaf0
with your GPU’s PCI IDs. - Regenerate the initial RAM filesystem to include the VFIO modules:
bash sudo dracut -f --kver `uname -r`
- Reboot the system.
7. Configure the Virtual Machine for GPU Passthrough:
- Open Virt-Manager (
virt-manager
) and create or edit a VM. - Go to Add Hardware > PCI Host Device and select your GPU and its audio device.
- Ensure PCIe is selected, and the ROM bar is enabled if needed.
8. Install the Necessary Drivers in the Guest OS:
- If you’re using Windows as the guest OS, install the GPU drivers for your specific hardware after booting the VM.
9. Configure Spice and QXL Display for Host Output:
- Go to the VM’s configuration in Virt-Manager.
- In the Video section, add a QXL display device.
- Set the primary display to QXL.
- Enable Spice Server or VNC Server for the display in a window on the host.
- Install the Spice Guest Tools or Virtio drivers in the guest OS to ensure seamless integration and input handling.
10. Launch the VM with Passthrough and Windowed Display:
- Start the VM from Virt-Manager.
- You should see a window on your host that shows the VM’s display output via the Spice/VNC server, while the GPU passthrough works for hardware acceleration in the guest.
Additional Tips:
- Monitor Performance: Use tools like
virt-top
orhtop
to monitor the resource usage and ensure the GPU is properly utilized by the guest. - Troubleshoot Errors: If you encounter errors related to device access or driver conflicts, check the
dmesg
logs for kernel messages. - Security Note: Using GPU passthrough can expose your hardware directly to the guest OS. Make sure you trust the guest OS or run it in a secure environment.
Conclusion
Using GPU passthrough, especially in KVM/QEMU, and also showing it in a window of the host OS involves arranging your virtual machine (VM) to use the best dedicated GPU server for robust performance, while also making sure that you can easily interact with the machine from a window on your main system. The above-mentioned steps help you to understand this easily.