Why You Would Need GPU Passthrough

GPU passthrough is essential for scenarios where high-performance graphics are required within virtual machines. This technology allows a VM to leverage the full power of a physical GPU, which is crucial for tasks such as gaming, video editing, 3D rendering, and machine learning. By enabling GPU passthrough, you can achieve near-native performance for these resource-intensive applications, making your virtualized environment much more versatile and powerful.

What is GPU Passthrough

GPU passthrough is a technology that allows a virtual machine (VM) to directly access the physical GPU (Graphics Processing Unit) of the host system. This bypasses the host operating system, giving the VM exclusive access to the GPU for improved performance and efficiency.

How to Set Up GPU Passthrough

  1. Enable Virtualization in BIOS

First, you need to go into the BIOS and enable VT-d for Intel CPUs or SVM, AMD-V, or AMD virtualization for AMD CPUs. Sadly, every BIOS is different, so refer to your motherboard manual for exact steps.

  1. Check Boot Mode

Check if you have booted in UEFI mode:

ls /sys/firmware/efi

If the directory exists and contains files, your system is booted in UEFI mode. If it does not exist, your system is using Legacy BIOS mode.

  1. Configure Boot Parameters

For Legacy Systems:

Edit /etc/default/grub and change the line:

GRUB_CMDLINE_LINUX_DEFAULT="quiet"

to

GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

for Intel, or

GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on"

for AMD.

Then update grub:

update-grub

For EFI Boot Systems:

Edit /etc/kernel/cmdline and add the following:

For Intel:

intel_iommu=on

For AMD:

AMD_iommu=on

Then run:

proxmox-boot-tool refresh
  1. Load VFIO Modules at Boot

Add these lines to /etc/modules:

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
  1. Blacklist GPU Drivers

Create and edit the following files:

echo "options vfio_iommu_type1 allow_unsafe_interrupts=1" > /etc/modprobe.d/iommu_unsafe_interrupts.conf
echo "options kvm ignore_msrs=1" > /etc/modprobe.d/kvm.conf
echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf
  1. Configure GPU PCIe Passthrough Find Your GPU

Run the following command to list all PCI devices:

lspci

Find the line corresponding to your GPU. Note the hexadecimal number at the beginning of the line (e.g., 82:00.0). Enter the PCI Identifier

Get the detailed information for your GPU:

lspci  -n -s 82:00 -v

Copy the HEX values from your GPU and create a new configuration:

echo "options vfio-pci ids=####:####,####:#### disable_vga=1" > /etc/modprobe.d/vfio.conf

Update the initramfs:

update-initramfs -u -k all
  1. Reboot

Reboot your Proxmox server to apply the changes. 8. Add the GPU to the VM

Finally, add the GPU to the VM. You only need to add the main GPU device, not the audio or USB components.