Post

Setting up Proxmox GPU Passthrough

Setting up Proxmox GPU Passthrough

Welcome to this quick guide on how to set up GPU passthrough on a server running Proxmox. In my specific case, I used an Nvidia GPU with an Intel CPU; however, this guide should also work for other major vendors like AMD with minor adjustments.

Prerequisites

  • Make sure your hardware supports IOMMU by either looking up the specification or running the following command in your target Proxmox node shell:
1
2
# if you get a match, then you have support (vmx - Intel, svm - AMD)
cat /proc/cpuinfo | grep -g "vmx|svm"
  • Make sure IOMMU / VT-d are enabled in BIOS.

Guide

1. Go to the Shell on your Proxmox node

2. Enable IOMMU in Proxmox

1
2
3
4
5
nano /etc/default/grub

# find the following line: GRUB_CMDLINE_LINUX_DEFAULT="quiet".
# replace with this (for Intel):
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"

3. Save the file and update GRUB

1
update-grub 

4. Reboot the server

1
reboot

5. After restarting, make sure IOMMU is enabled successfully

1
2
# expected match should look something like this: DMAR: IOMMU enabled
dmesg | grep -i "IOMMU enable"

6. Identify your GPU and it’s associated devices (make sure to note all the vendor ids for later)

1
2
3
# vendor ids should be at the end of each line, looking like this: [xxxx:xxxx]
lspci -nn | grep -i vga
lspci -nn | grep -i audio

7. Add required VFIO modules

1
2
3
4
5
6
7
nano /etc/modules

# add these to the file:
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

8. Adjust VFIO and KVM settings to improve virtualization compatibility

1
2
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

9. Blacklist default nvidia drivers, since they are known to cause issues with Proxmox

1
echo "blacklist nvidia" >> /etc/modprobe.d/blacklist.conf 

10. Add your hardware vendor ids to the VFIO file

1
2
# replace 'xxxx:xxxx' with your ids, your number of ids might be different
echo "options vfio-pci ids=xxxx:xxxx, xxxx:xxxx, xxxx:xxxx disable_vga=1" > /etc/modprobe.d/vfio.conf

11. Update initramfs

1
update-initramfs -u

12. Reboot

1
reboot

13. Additional steps

To connect your GPU to a VM, go to Hardware, click Add > PCI > Raw device, then select your GPU.

If you plan to use your GPU for AI tasks and workloads, installing CUDA drivers in your VM can enhance performance. Follow the instructions on the official NVIDIA website.

Verify that the drivers were installed correctly:

1
2
# should display details about your GPU
nvidia-smi 
This post is licensed under CC BY 4.0 by the author.