Ryzen GPU Passthrough for Proxmox VE

repository·main·Indexed 22 days ago

https://github.com/isc30/ryzen-gpu-passthrough-proxmox

A comprehensive guide for achieving GPU passthrough on Proxmox VE using Ryzen 7000 series processors with AMD Radeon integrated graphics (680M/780M) or RDNA2/RDNA3 GPUs. Includes instructions for Proxmox VE installation, IOMMU and VFIO configuration, Windows VM setup, VBIOS extraction, and resolving Error 43 when using OVMF (UEFI). Provides tools for extracting BIOS BIN files from EXE, extracting Audio device EFI, and converting EFI GOP drivers to ROM files.

Tokens
2.2K
Snippets
7
Records
11
Agent score
79%

What's inside ryzen-gpu-passthrough-proxmox

  1. Install Proxmox VE

    main

    Follow these steps to install Proxmox VE on your hardware. If you are using Proxmox 7.4, there is a known issue where the graphical installer may crash. Use the workaround provided below.

    Standard Installation

    1. Download the Proxmox ISO and create an installation USB (e.g., using rufus).
    2. Boot from the USB and run the installer.
    3. For an IPv4 static IP, use the format 192.168.1.XXX/24.
    4. Once finished, access the web interface at https://<THE_IP_YOU_CONFIGURED>:8006/.
    5. Connect via SSH: ssh root@<THE_IP_YOU_CONFIGURED>.

    Fix Proxmox 7.4 Graphical Installer Crash

    If the installer crashes after displaying Starting the installer GUI:

    1. Press CTRL + ALT + F3.
    2. Run the following commands:
      Xorg -configure
      cp /root/xorg.conf.new /etc/X11/xorg.conf
      sed -i 's/amdgpu/fbdev/g' /etc/X11/xorg.conf
    3. Press CTRL + ALT + F1 and run startx.

    Post-Installation Setup

    Switch to non-subscription repositories and install CPU microcode using these community scripts:

    # Switch to non-subscription repositories
    bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/post-pve-install.sh)"
    
    # Install CPU Microcode
    bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/tools/pve/microcode.sh)"
    ssh root@<THE_IP_YOU_CONFIGURED>
  2. Configure the GPU for passthrough

    main

    To perform GPU passthrough, you must prevent the host from loading GPU drivers and ensure the PCI connection is passed to the VM.

    1. Identify GPU PCI IDs

    Run the following command to find your AMD/ATI device IDs:

    lspci -nn | grep -e 'AMD/ATI'

    Note the PCI addresses (e.g., 0000:34:00.0) and the Vendor:Device IDs (e.g., 1002:1681).

    2. Enable IOMMU

    Edit /etc/default/grub to enable IOMMU:

    sed -i 's/GRUB_CMDLINE_LINUX_DEFAULT="quiet"/GRUB_CMDLINE_LINUX_DEFAULT="quiet iommu=pt"/g' /etc/default/grub
    update-grub

    3. Configure VFIO Modules

    Add the necessary kernel modules to /etc/modules:

    echo "vfio" >> /etc/modules
    echo "vfio_iommu_type1" >> /etc/modules
    echo "vfio_pci" >> /etc/modules
    echo "vfio_virqfd" >> /etc/modules

    Tell vfio which devices to virtualize by creating /etc/modprobe.d/vfio.conf. Replace the IDs below with your specific GPU and Audio IDs:

    echo "options vfio-pci ids=1002:1681,1002:1640" >> /etc/modprobe.d/vfio.conf

    To ensure vfio-pci loads before the host drivers, add soft dependencies to /etc/modprobe.d/vfio.conf. Check your current drivers using lspci -nnk and update these lines if necessary:

    echo "softdep radeon pre: vfio-pci" >> /etc/modprobe.d/vfio.conf
    echo "softdep amdgpu pre: vfio-pci" >> /etc/modprobe.d/vfio.conf
    echo "softdep snd_hda_intel pre: vfio-pci" >> /etc/modprobe.d/vfio.conf

    4. Apply Changes

    Update the initramfs and reboot:

    update-initramfs -u -k all
    shutdown -r now

    5. Verify

    After reboot, confirm the Kernel driver in Use is vfio-pci:

    lspci -nnk
    lspci -nn | grep -e 'AMD/ATI'
  3. Use the GPU as the Primary GPU in a VM

    main

    To use the passed-through GPU as the main display output for the VM:

    1. Enable Remote Desktop within the Windows VM.
    2. Change the Windows PC name to match the Proxmox VM name (for easier remote connection).
    3. Shut down the VM.
    4. In Proxmox, edit the VM Hardware:
      • Set display to none.
      • Set the GPU PCI device to Primary GPU: ON.
    5. Start the VM and connect via Remote Desktop or a physical monitor.
  4. Create a Windows VM for GPU Passthrough

    main

    Follow these steps to set up a Windows VM optimized for GPU passthrough:

    1. Upload ISO: In the Proxmox Web UI, go to local storage -> ISO Images -> Upload and upload a Windows 10 installation ISO.
    2. VM Configuration: Create a new VM with these specific settings:
      • ISO Image: The uploaded Windows ISO
      • Type: Microsoft Windows
      • Version: 10/2016/2019
      • Machine: q35
      • Bios: SeaBIOS (Note: The guide mentions UEFI/OVMF in headings, but specifies SeaBIOS here for the initial creation)
      • Qemu Agent: ON
      • Disk: At least 64GB, Discard ON, SSD emulation ON
      • CPU Type: host
      • RAM: At least 12GB
    3. Installation: Run the VM and perform a custom Windows installation.
    4. Finalize: Once Windows is installed, stop the VM before proceeding to GPU configuration.
  5. Extract GPU VBIOS from Proxmox host

    main

    To pass an AMD GPU to a Windows VM properly, you must provide the GPU's VBIOS. You can extract it from the host by compiling and running a C program that reads the VFCT ACPI table.

    1. Create a vbios.c file on your Proxmox host with the provided source code.
    2. Compile and run the extractor:
      gcc vbios.c -o vbios
      ./vbios
    3. This will generate files named vbios_<vendor>_<device>.bin. Move the resulting file to /usr/share/kvm/ with a descriptive name (e.g., vbios_7xxx.bin).
    #include <stdint.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    // ... (rest of the C code provided in the README)
  6. Configure GPU Passthrough in Windows VM

    main

    After extracting the VBIOS, follow these steps to configure the Windows VM in Proxmox:

    1. Add PCI Devices via Proxmox Web UI:

      • GPU: Add PCI Device using the identified PCI ID (e.g., 0000:34:00.0). Set All Functions: OFF, Primary GPU: OFF, and PCI-Express: ON.
      • Audio: Add the corresponding Audio PCI device (e.g., 0000:34:00.1).
    2. Configure VM Configuration File: Edit /etc/pve/qemu-server/<VM_ID>.conf to hide virtualization and attach the VBIOS file:

      • Add args: -cpu 'host,-hypervisor,kvm=off' to hide the hypervisor from the guest.
      • Update the hostpci0 line to include the romfile parameter.
    3. Install Drivers and Fixes:

      • Install VirtIO drivers (virtio-win-guest-tools.exe).
      • Install official AMD GPU drivers using the OFFLINE installer (the online installer may fail due to hardware detection).
      • Install the RadeonResetBugFix service to mitigate the 'AMD Reset Bug'.
    # Example /etc/pve/qemu-server/<VM_ID>.conf modification
    args: -cpu 'host,-hypervisor,kvm=off'
    ...
    hostpci0: 0000:34:00.0,pcie=1,romfile=vbios_7xxx.bin
    hostpci1: 0000:34:00.1,pcie=1
  7. Fix GPU Error 43 when using OVMF (UEFI)

    main

    If you are using bios: ovmf instead of seabios and encounter 'Error 43', you must configure a UEFI ROM for the audio device.

    1. Download AMDGopDriver.rom from this repository.
    2. Copy it to the Proxmox host at /usr/share/kvm/AMDGopDriver.rom.
    3. Edit /etc/pve/qemu-server/<VM_ID>.conf and append ,romfile=AMDGopDriver.rom to the Audio Device hostpci line.

    Example Configuration:

    -hostpci1: 0000:34:00.1,pcie=1
    +hostpci1: 0000:34:00.1,pcie=1,romfile=AMDGopDriver.rom
    # Example /etc/pve/qemu-server/<VM_ID>.conf for UEFI
    args: -cpu 'host,-hypervisor,kvm=off'
    bios: ovmf
    hostpci0: 0000:34:00.0,pcie=1,romfile=vbios_7xxx.bin
    hostpci1: 0000:34:00.1,pcie=1,romfile=AMDGopDriver.rom