Skip to content

Instantly share code, notes, and snippets.

@polhaghverdian
Forked from paul-vd/readme.md
Last active February 1, 2024 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save polhaghverdian/7aa763219c126bceced03b8f02359686 to your computer and use it in GitHub Desktop.
Save polhaghverdian/7aa763219c126bceced03b8f02359686 to your computer and use it in GitHub Desktop.
GPU Passthrough Fedora

Simular Guides

Usefull Commands

  • lspci -nnk list pci devices
  • sudo grub2-mkconfig -o /etc/grub2-efi.cfg updates the grub
  • sudo call-a-friend @ballas calls the best knowledge base, fuck wiki 🤣

Detach the GPU from the host


Retrieve the GPU id's

First you will have to find the GPU id's that you would like to passthrough, you can do this by running in the terminal:

# For AMD GPU's:
$ lspci -nnk | grep Navi

# For nvidia GPU's:
$ lspci -nnk | grep NVIDIA 

Example output, here we are interested in the VGA compatible controller (1002:73bf) and the Audio device (1002:ab28)

0a:00.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 XL Upstream Port of PCI Express Switch [1002:1478] (rev c1)
0b:00.0 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 XL Downstream Port of PCI Express Switch [1002:1479]
0c:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 [Radeon RX 6800/6800 XT / 6900 XT] [1002:73bf] (rev c1)
0c:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 HDMI Audio [Radeon RX 6800/6800 XT / 6900 XT] [1002:ab28]
	Subsystem: Advanced Micro Devices, Inc. [AMD/ATI] Navi 21 HDMI Audio [Radeon RX 6800/6800 XT / 6900 XT] [1002:ab28]

Blacklist id's and enable iommu

First you will have to modify the default grub file.

$ sudo gedit /etc/default/grub

We want to modify the GRUB_CMDLINE_LINUX

# `vfio-pci.ids` are equivalent to the id's found in the previous step.

# Explanation:
rd.driver.pre=vfio-pci       // This preloads the vfio-pci driver
intel_iommu=on               // Flags the IOMMU instruction set on Intel CPUs. If you have an AMD, amd_iommu=on is the equivalent for them.
modprobe.blacklist=nouveau   // Prevents modprobe from loading the nouveau drivers after initial boot.
rd.driver.blacklist=nouveau  // Blocks the nouveau drivers from being loaded in the ram drive before booting.
iommu=pt                     // Specifies to use “passthrough” mode for IOMMU, allowing the KVM hypervisor to directly use the device instead of relying on DMA for the device we’re giving to the VM
vfio-pci.ids                 // Binding vfio-pci via device ID

- GRUB_CMDLINE_LINUX="rhgb quiet"
+ GRUB_CMDLINE_LINUX="rhgb quiet rd.driver.blacklist=nouveau modprobe.blacklist=nouveau rd.driver.blacklist=nvidia modprobe.blacklist=nvidia intel_iommu=on iommu=pt rd.driver.pre=vfio-pci vfio-pci.ids=1002:73bf,1002:ab28"

Then we need to update grup

sudo grub2-mkconfig -o /etc/grub2-efi.cfg

We then need to edit the dracut config

$ sudo gedit /etc/dracut.conf.d/local.conf

// If anyone wondering: driver "vfio_virqfd" has been consolidated with the vfio driver so you don't need to append it in the dracut config anymore.

add_drivers+=" vfio vfio_iommu_type1 vfio_pci "

$ sudo dracut -f --kver $(uname -r)

Rebooot!

Attach the GPU from the guest


Install Virtual Machine

$ sudo dnf groupinstall virtualization

Then you reboot 🦸

  1. Open up Virtual Machine Manager
  2. Create new virtual machine
  3. Local install media (ISO image or CDROM) -> Select the ISO to windows10 or windows11
  4. Assign Ram & CPU
  5. Tick the Customize configuration before install

If you are running windows 11 you will need a secure boot and tpm module.

  1. Under overview add the following config
Chipset: q35
Firmware: x86_64:/usr/share/edk2/ovmf/OVMF_CODE.secboot.fd
  1. Under CPUs, untick the copy host cpu configuration then for a example use the following config for a Ryzen 5900x
Model: host-passthrough
Topology
[X] Manually set CPU topology
Sockets: 1
Cores: 6
Threads: 2
  1. Add a TPM module by clicking on Add Hardware > TPM
Model: TIS
Backend: Emulated device
Version: 2.0
  1. Then passthrough the GPU and if needed the GPU Audio under the Add Hardware > PCI HOST Device image

And then you can begin installation. Bobs your uncle 🤠

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment