Elementary OS 5.0 / Ubuntu 18.XX - VFIO PCIe passthrough guide / tutorial

** FOLLOW THIS STEP ONLY OF YOUR GPUs HAVE DIFFERENT PCI IDs **

otherwise use workaround from this guide: https://forum.level1techs.com/t/vfio-in-2019-pop-os-how-to-general-guide-though-draft/142287


Assigning VFIO driver to a GPU

We are ready to setup our devices to be used inside a virtual machine.

To do this, we must bind the vfio-pci driver to the device(s) we want to pass through to the virtual machine, and this is most easily done by PCI device ID.

In my case PCI device IDs of my Nvidia 450 and its audio interface are:

[10de:0dc4] and [10de:0be9]

To get around system using its own Nvidia (or AMD) driver. Wendell wrote us yet again nice tiny guide.

But first, you have to check, which driver is used for your GPU:

run:

lspci -nnv |less

and finda GPU you want to pass in the list:

Notice the Kernel driver in use is nvidia. Thats what you have to use while editing following config file

sudo nano /etc/initramfs-tools/modules

and add following lines at the end of file.

Replace nvidia on first and last line, if your kernel driver in use is different. Replace your PCI IDs with the GPU and its audio interface you want to use for virtual machine. Example:

softdep nvidia pre: vfio vfio_pci

vfio
vfio_iommu_type1
vfio_virqfd
options vfio_pci ids=10de:0dc4,10de:0be9
vfio_pci ids=10de:0dc4,10de:0be9
vfio_pci
nvidia

save and exit.

Now edit:

sudo nano /etc/modules

and add following and don’t forget to change IDs again

vfio
vfio_iommu_type1
vfio_pci ids=10de:0dc4,10de:0be9

save and exit


We will also create explicit configurations for the modules in /etc/modprobe.d

A) for AMD GPU:

sudo nano /etc/modprobe.d/amdgpu.conf 

and add following:

softdep amdgpu pre: vfio vfio_pci

B) for NVIDIA GPU

sudo nano /etc/modprobe.d/nvidiagpu.conf 

and add following:

softdep nvidia pre: vfio vfio_pci

even more configs to edit!

sudo nano /etc/modprobe.d/vfio_pci.conf

and add following: REPLACE IDS, AGAIN

options vfio_pci ids=10de:0dc4,10de:0be9

then run:

sudo grub-mkconfig; sudo update-grub; sudo update-initramfs -k all -c

REBOOT AND PRAY

image

1 Like