本文记录了将AMD R5-4650GE直通给PVE内Linux虚拟机的操作过程

启用IOMMU直通,ACS分组

vim /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="quiet iommu=pt pcie_acs_override=downstream,multifunction textonly"

update-grub

屏蔽驱动,避免被宿主机占用

vim /etc/modprobe.d/pve-blacklist.conf

blacklist nvidiafb

# AMD
# blacklist amdgpu
blacklist radeon

# Intel UHD
blacklist snd_hda_codec_hdmi
blacklist snd_hda_intel
blacklist snd_hda_codec
blacklist snd_hda_core

vim /etc/modules

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd

update-initramfs -u -k all

提取vBIOS固件

1
2
3
4
5
cd /sys/bus/pci/devices/0000\:07\:00.0/
echo 1> rom
cp rom > /usr/share/kvm/4650ge-vbios.bin
echo 0> rom
chmod  +r /usr/share/kvm/4650ge-vbios.bin

直通显卡给虚拟机 使用命令行设置

qm set VMID -hostpci0 0000:07:00.0,pcie=1,rombar=1,romfile=4650ge-vbios.bin

或者编辑配置文件

vim /etc/pve/qemu-server/100.conf

hostpci0: 0000:07:00.0,pcie=1,rombar=1,romfile=4650ge-vbios.bin

虚拟机完整配置 启动虚拟机前执行

1
2
echo 1 > /sys/bus/pci/devices/0000\:06\:00.0/remove  
echo 1 > /sys/bus/pci/rescan

下面在虚拟机内操作

apt install firmware-linux firmware-amd-graphics

进入虚拟机验证

1
2
dmesg | grep amdgpu
lspci -nnk
01:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Renoir [1002:1636] (rev dc)
        Subsystem: ASUSTeK Computer Inc. Renoir [1043:87e1]
        Kernel driver in use: amdgpu
        Kernel modules: amdgpu

ls -al /dev/dri

drwxr-xr-x  3 root root        120 Mar  4 11:21 .
drwxr-xr-x 18 root root       3240 Mar  4 11:21 ..
drwxr-xr-x  2 root root        100 Mar  4 11:21 by-path
crw-rw----  1 root video  226,   0 Mar  4 11:21 card0
crw-rw----  1 root video  226,   1 Mar  4 11:21 card1
crw-rw----  1 root render 226, 128 Mar  4 11:21 renderD128

出现renderD128说明直通成功

参考资料

https://pve.proxmox.com/wiki/Pci_passthrough

AMD Ryzen 7 “Renoir” 4750G APU and iGPU pass-thru (to Windows 10 guest)? | Page 4 | Proxmox Support Forum