How to configure PCI(e) passthrough on Proxmox VE
Overview
This guide will show you how to configure PCI(e) Passthrough on Proxmox VE, version 6.3-3 at the time of writing. In this case, we’ll be using a GPU as the passthrough device.
This guide assumes that the Proxmox VE
OS was installed using ZFS RAID1
or similar, knowledge of vim
and basic Linux administration. The big difference between this type of install is that it uses Systemd-boot
instead of the typical GRUB
install. If you don’t know vim
, use nano
instead.
If you are unsure of your settings, please refer to the setup guide post here.
Hardware used in this tutorial:
- Motherboard: Supermicro X9DRL-3F/iF
- CPU: 2 x Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz (2 Sockets, 32 Cores)
- RAM: 32GB (8 x 4GB) DIMM DDR3 1333 MHz ECC Memory
- OS Disks: 2 x 500GB SSDs
- Data disks: 9 x 3TB SATA Disks
- GPU: Nvidia GTX 960 SSC
NOTE: Although it’s preferable to use a PCIe x16 slot, a PCIe x8 slot will actually work just as well. The only requirement for using a x8 is that it must be a “cut” slot, meaning that the slot is open in the rear where a larger slotted card can be used. You might notice that the motherboard I am using is this case exactly. Usually the only downside to running a GPU in this way will result in a few lost FPS, but that’s about it.
Pre-flight Checks
PCI(e) Passthrough depends on a number of requirements to work properly. Be absolutely sure that these items have been taken care of or you will waste countless hours.
Here are those strict requirements:
- A GPU that is
UEFI Boot
capable. Most cards equivalent to a Nvidia GTX 600 series or newer will work. However, I’d suggest using something newer like a GTX 900 series. AMD graphics cards will work just as well, but again, they must be a similar series. - The
BIOS/UEFI
must be set to boot into theProxmox VE
OS inUEFI
mode. PCI(e) passthrough requires this. - Virtualization flags enabled in the
BIOS/UEFI
, specificallyVT-d
andVirtualization
.
Proxmox VE Host Configuration
Official Proxmox VE PCIe Documentation
IOMMU Systemd-boot
Systemd-boot Kernel Commandline Documentation
Add the intel_iommu=on iommu=pt
settings to the Systemd-boot
command line.
Edit the /etc/kernel/cmdline
:
vim /etc/kernel/cmdline
Before modification:
root=ZFS=rpool/ROOT/pve-1 boot=zfs
After:
root=ZFS=rpool/ROOT/pve-1 boot=zfs intel_iommu=on iommu=pt
Update the Systemd-boot
scripts:
pve-efiboot-tool refresh
Kernel Modules
Add the required kernel modules:
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
Edit /etc/modules
:
vim /etc/modules
Before:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
After:
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
Refresh the initramfs
:
update-initramfs -u -k all
Reboot PVE host
reboot
Verify IOMMU/PCI(e) Passthrough
Verify loaded kernel cmdline
:
$ cat /proc/cmdline
initrd=\EFI\proxmox\5.4.73-1-pve\initrd.img-5.4.73-1-pve root=ZFS=rpool/ROOT/pve-1 boot=zfs intel_iommu=on iommu=pt
Verify that IOMMU
is enabled and Virtualization Technology for Directed I/O
:
$ dmesg | grep -e DMAR -e IOMMU -e AMD-Vi
[ 0.013784] ACPI: DMAR 0x000000007E2CAB18 000130 (v01 A M I OEMDMAR 00000001 INTL 00000001)
[ 0.155343] DMAR: IOMMU enabled
...
[ 1.474961] DMAR: Intel(R) Virtualization Technology for Directed I/O
Verify vfio
:
$ dmesg | grep -i vfio
[ 16.913623] VFIO - User Level meta-driver version: 0.3
Look for GPU:
$ lspci -nn | grep NVID
03:00.0 VGA compatible controller [0300]: NVIDIA Corporation GM206 [GeForce GTX 960] [10de:1401] (rev a1)
03:00.1 Audio device [0403]: NVIDIA Corporation GM206 High Definition Audio Controller [10de:0fba] (rev a1)
Look for IOMMU_groups
and grep
using hardware address above:
find /sys/kernel/iommu_groups/ -type l | grep 03:00
/sys/kernel/iommu_groups/25/devices/0000:03:00.0
/sys/kernel/iommu_groups/25/devices/0000:03:00.1
If you have similar output, congratulations! You have sucessfully passed through your PCI(e) devices. If for some reason you don’t show this output, go back and re-verify all the above steps.
Install Windows
Get Installer ISOs
Download the following:
Upload them to the Proxmox VE
host:
- Login to the web UI:
https://<pve-ip>:8006
- Click on hypervisor hostname on the left, then click
local (<pve-hostname>)
, thenISO Images
, then clickUpload
, browse and upload the two files above.
You should see something like this after you are done:
Create Windows VM
- Click
Create VM
in the upper right. General
- Set
VM ID:
. E.g.111
, anything above 100 will do - Set
Name:
. E.g.windows-10
- Click
Next
- Set
OS
- Select
Win10_20H2_v2_English_x64.iso
as theISO Image:
, underUse CD/DVD...
- Select
Microsoft Windows
forType:
- Select
10/2016/2019
forVersion:
- Click
Next
- Select
System
- Select
VirtIO-GPU
forGraphic card:
VirtIO SCSI
forSCSI Controller:
Qemu Agent:
, CheckedOVMF (UEFI)
forBIOS:
q35
forMachine:
Add EFI Disk:
, Checkedlocal-zfs
forStorage:
- Click
Next
- Select
Hard Disk
SCSI
forBus/Device:
Write back
forCache
.local-zfs
forStorage:
80
forDisk size (GiB):
, or any size you prefer- Check the following:
Discard
,SSD emulation:
,IO thread:
,Skip replication:
. - Click
Next
CPU
4
forCores
,1
forSockets:
Type:
, this one is the most important setting. Set this toIvyBridge
if you have this family of processors. If you don’t know, see the mast list here: Intel CPU Architechture ListEnable NUMA
, Checked.pcid
,+
in the bottom underExtra CPU Flags:
- Click
Next
Memory
8192
forMemory (MiB)
, or any size you prefer. Just multiply the number of GB by 1024. For example:8 * 1024 = 8192
.- Click
Next
Network
Intel E1000
forModel:
. This one could vary for you. However, I use this one because Microsoft has drivers for this. If you use anything else you may have to install drivers when installing Windows from the ISO.- Click
Next
You should see something like this on the Confirm
page.
Click Finish
.
Add hardware before first boot
Perform the following:
- Click on the VM ID you created, in this example
111 (windows-10)
on the left side. - Click
Hardware
- Add a secondary DVD drive, Click
Add
,CD/DVD Drive
,Bus/Device: SATA
,Storage: local
,ISO Image: virtio-win-0.1.190.iso
,Create
. - Add the GPU, Click
Add
,PCI Device
, Select the GPU you wish to pass through, E.g.0000:03:00.0
, Check all boxes butPrimary GPU
, ClickAdd
Install Windows
- Select
Console
on the left, then clickStart
in the upper right. - As soon as you see the
Press any key to boot from CD or DVD..
, HitENTER
on your keyboard. If you miss it, reboot and try again. - Once the Windows installer loads, fill out all the details until you hit
Where do you want to install Windows?
, then hitLoad driver
. - Click
Browse
, thenBrowse
again, double click on thevirtio-win-0.1.190
disk underThis PC
, then scroll down and click onvioscsi
, thenw10
, thenamd64
, then hitOK
. HitNext
until you get back to the install menu. NOTE: If you used the non-Intel network driver, the driver can be found here as well. - Now that the disk is found, select
Drive 0 Unallocated Space
and hitNext
. - Finish the Windows install.
- On first Windows boot while going through personalization settings, be sure to DISABLE all the settings on
Choose privacy settings for your device
, they love to track you…
Configure Windows and install GPU drivers
Perform the following:
- Make sure that a password is set for this user. Select Start, Settings, Accounts, Sign-in options. Under Password, select the Change button and follow the steps.
- Enable
Remote Desktop
. Select Start, Settings, System, Remote Desktop. Use the slider to enable Remote Desktop. - Connect to host using
RDP
. - Install the
Qemu Agent
. Click onWindows Explorer
,This PC
,virtio-win-0.1.190
,guest-agent
, then installqemu-ga-x86_64
. - Open
Device Manager
by right-clicking the Windows logo (start button) and selectingDevice Manager
. Once open, install all the missing drivers for theOther devices/PCI *
. Right-click each one and selectUpdate driver
, thenBrowse my computer for drivers
, ClickBrowse
then select thevirtio-win-0.1.190
disk underThis PC
and hitNext
. Install the drivers until there are no more exclamation drivers underOther devices
. It should look like this when complete: Before: After: - Download and install the Nvidia drivers. Download the drivers from this link.. Install the drivers, but don’t install the
GeForce Experience
. - Shut down the VM through Windows.
- Select
Hardware
, clickPCI Device
, then enable all check boxes, i.e.Primary GPU
. - Start up the VM.
-
Verify that the GPU is working properly. Right-click start menu, and hit
Device Manager
, if it’s working you won’t see an exclamation point on the GPU. Open up theDisplay adapters
and right-click the GPU andProperly working GPU (No
Code 43
):Check
Task Manager
too: - If everything is working properly, you can connect the GPU to an external display. You may have to reboot the VM, but once it comes up, you should see the external display show video. If you don’t, or if you only see the background, you may have to set the display to:
Duplicate these displays
. I’d also recommend setting the resolution to1920 x 1080
. You’ll get better gaming performance and will be able to have a better streaming experience. - Last, but not least, set a static IP address so that it’s easier to connect to this host. If you’re ever in a situation where you don’t know the IP, you can click on the VM on the left side, hit
Summary
and you should see the VM’s IP under theIPs
section.
If you made it this far without issues, congratulations!
Configure remote gaming
This section will likely vary depending on how you want to use this VM. Instead of repeat steps from other guides, I’ll just link them here.
Configure streaming
I’d strongly suggest you set up streaming so that this host can be used remotely. This is a great guide put together by the extremely helpful folks at serverbuilds.net
.
This guide was built for UnRAID
, which we aren’t using here, but the streaming part of this guide directly applies here. Go ahead and follow the instructions outlined here.
I’d recommend installing the following:
Configure VM as a physical host
If you plan to use this VM as a physical machine, there are a few things to consider. It might be helpful to set this VM to start on Proxmox
boot, click on the VM on the left, hit Options
, double-click Start at boot
and check the box.
In order to use this VM, you’ll need to have a way to hook up a keyboard and mouse. I’d suggest passing through an entire USB port so that you can attach a USB hub to connect a series of devices. To do this, be sure the VM is shutdown before you do anything, then click the VM on the left-hand side, click Hardware
, click Add
, then select USB Device
, click the option Use USB Port
and select a port. Once it has been attached, boot the VM. You should be able to use those newly attached devices.
If you use an external monitor, or TV, I’d recommend using an HDMI port because you’ll be able to get audio from the video card so that you don’t have to install an external audio card. You could also use a USB audio card, but it’s up to you.
More documentation for USB passthrough can be found here.
Troubleshooting
- PCI Passthrough errors/issues
- Re-check all the setup and verification steps above.
- Be absolutely sure that the system booted via
UEFI
. - Make sure that
Display
is set toVirtIO-GPU
. - Also verify that the resolution is set properly for you displays.
- GPU
(Code 43)
Error- This can be a real tough one, with an absolute TON of potential issues that would cause this, so be patient and look over your settings.
- First try all the steps in the bullet-points above.
- Try to uninstall and re-install the drivers for the GPU. Here’s some helpful resources for this option here.
- Make sure that your video is new enough to support PCI passthrough.
- Double-check your hardware for compatability.
- Re-verify that
VT-d
has been enabled in theUEFI/BIOS
. - Be absolutely sure that your kernel has loaded the
iommu
settings.
If all else fails, check out the resources below. Take your time and check off each item as you verify it. It’s truly shocking how one tiny setting being off can cause it all to fail.