1 3 3 7 4 2 0 6 6 6 1 3 3 7 4 2 0 6 9 6 6 6 1 3 3 7 4 2 0 6 6 6 4 2 0 1 3 3 7 6 9 6 6 6 4 2 0 1 3 3 7 6 9 6 6 6 4 2 0 6 9 1 3 3 7 6 6 6 4 2 0 6 9 1 3 3 7 6 6 6 4 2 0 6 9 6 6 6 1 3 3 7 4 2 0 6 9 6 6 6 1 3 3 7 4 2 0 6 9 1 3 3 7 6 6 6 4 2 0 6 9 1 3 3 7 6 6 6 4 2 0 6 9 1 3 3 7 6 6 6 6 9 4 2 0 1 3 3 7 6 6 6 6 9 4 2 0 1 3 3 7 6 6 6 4 2 0 1 3 3 7 6 6 6 6 9 4 2 0 1 3 3 7 6 6 6 6 9 4 2 0 6 9 1 3 3 7 4 2 0 6 6 6 6 9 1 3 3 7 4 2 0 6 6 6 6 9 1 3 3 7 6 6 6 6 9 4 2 0 1 3 3 7 6 6 6 6 9 4 2 0 1 3 3 7 6 6 6 4 2 0 6 9 1 3 3 7 6 6 6 4 2 0 6 9 1 3 3 7 6 6 6
TUTORIALS / VIRTUALIZATION

GPU PASSTHROUGH VM

DIFFICULTY: EXTREME UPDATED: 2 DAYS AGO

INTRODUCTION

Running a virtual machine usually means sacrificing graphics performance. GPU Passthrough (VFIO) solves this by giving the VM direct access to a physical GPU, allowing for near-native performance. This is the holy grail for Linux users who need to run Windows games or Adobe software without dual-booting.

With proper configuration, you can achieve 95-99% of bare metal performance, run anti-cheat enabled games, and maintain your secure Linux host environment.

VFIO Architecture Diagram

PREREQUISITES

  • CPU with VT-d (Intel) or AMD-Vi (AMD) support - Check your processor specs
  • Motherboard with IOMMU support - Usually any modern board supports this
  • Two GPUs OR single-GPU passthrough - Dual GPU is easier for beginners
  • Linux Host - Arch Linux recommended (best documentation), Ubuntu/Fedora also work
  • Minimum 16GB RAM - You'll need to allocate 8GB+ to the VM

⚠️ WARNING

Incorrect BIOS modifications can brick your motherboard. Always have a backup plan and read the full guide before proceeding.

STEP-BY-STEP INSTRUCTIONS

Step 1: Enable IOMMU in BIOS/UEFI

Reboot into your BIOS (usually DEL or F2 during boot). Navigate to the Advanced or CPU Configuration section.

Look for and enable:

  • Intel VT-d (Intel CPUs) or AMD-Vi / IOMMU (AMD CPUs)
  • Intel Virtualization Technology / SVM Mode
  • Disable CSM/Legacy Boot (use UEFI only)
IOMMU Groups Diagram

Step 2: Enable IOMMU in Kernel Parameters

Edit your bootloader config to enable IOMMU at the kernel level. For GRUB, edit /etc/default/grub:

# For Intel CPUs:
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"

# For AMD CPUs:
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt"

Then update GRUB and reboot:

sudo grub-mkconfig -o /boot/grub/grub.cfg
sudo reboot

Step 3: Verify IOMMU Groups

After reboot, check your IOMMU groups to ensure devices are properly isolated:

#!/bin/bash
shopt -s nullglob
for g in $(find /sys/kernel/iommu_groups/* -maxdepth 0 -type d | sort -V); do
    echo "IOMMU Group ${g##*/}:"
    for d in $g/devices/*; do
        echo -e "\t$(lspci -nns ${d##*/})"
    done;
done;

Your GPU and its audio controller should ideally be in their own IOMMU group, or at minimum in a group with no critical devices.

Step 4: Isolate the GPU with VFIO

Find your GPU's PCI IDs using lspci -nnk. Look for your GPU and note the IDs in brackets (e.g., [10de:1b80]).

Create /etc/modprobe.d/vfio.conf:

# Replace with your GPU's vendor:device IDs
options vfio-pci ids=10de:1b80,10de:10f0

# Load vfio-pci before graphics drivers
softdep nvidia pre: vfio-pci
softdep amdgpu pre: vfio-pci

Update initramfs and reboot:

sudo mkinitcpio -P # Arch Linux
sudo update-initramfs -u # Ubuntu/Debian

Step 5: Install Virtualization Software

# Arch Linux
sudo pacman -S qemu libvirt virt-manager ovmf

# Ubuntu/Debian
sudo apt install qemu-kvm libvirt-daemon-system virt-manager ovmf

Enable and start libvirt:

sudo systemctl enable --now libvirtd
sudo usermod -aG libvirt $USER

Step 6: Create the VM in Virt-Manager

  1. Open Virt-Manager and click "Create a new virtual machine"
  2. Choose "Local install media" and select your Windows ISO
  3. Allocate at least 8GB RAM and 4 CPU cores
  4. Important: Select "Customize configuration before install"
  5. In Overview, set Firmware to "UEFI x86_64: /usr/share/OVMF/OVMF_CODE.fd"
  6. In CPUs, check "Copy host CPU configuration"
  7. Remove the default video adapter (Spice/QXL)
  8. Click "Add Hardware" → "PCI Host Device" → Select your GPU
  9. Add Hardware again and select the GPU's audio controller

Step 7: Optional - Looking Glass Setup

For low-latency frame relay from guest to host without a second monitor:

# Install Looking Glass
yay -S looking-glass # Arch AUR

# Add IVSHMEM device to VM XML
virsh edit [VM_NAME]

# Add before \u003c/devices\u003e:
\u003cshmem name='looking-glass'\u003e
  \u003cmodel type='ivshmem-plain'/\u003e
  \u003csize unit='M'\u003e32\u003c/size\u003e
\u003c/shmem\u003e

CONCLUSION & TROUBLESHOOTING

If successful, you now have a Windows VM that performs within 95-99% of bare metal. You can play most games with Anti-Cheat enabled and use CUDA acceleration.

Common Issues:

  • Code 43 Error: Add vendor_id to hide VM from Nvidia drivers
  • Black Screen: Try different OVMF firmware versions or add video=efifb:off to kernel params
  • VM Won't Start: Check IOMMU groups and ensure GPU isn't in use by host