1. 安装pve
2.打开shell
lspci
2.1 结果
root@pve:~# lspci
00:00.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne Root Complex
00:00.2 IOMMU: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne IOMMU
00:01.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:02.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:02.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:02.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne PCIe GPP Bridge
00:08.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Renoir PCIe Dummy Host Bridge
00:08.1 PCI bridge: Advanced Micro Devices, Inc. [AMD] Renoir Internal PCIe GPP Bridge to Bus
00:14.0 SMBus: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller (rev 51)
00:14.3 ISA bridge: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge (rev 51)
00:18.0 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 0
00:18.1 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 1
00:18.2 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 2
00:18.3 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 3
00:18.4 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 4
00:18.5 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 5
00:18.6 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 6
00:18.7 Host bridge: Advanced Micro Devices, Inc. [AMD] Cezanne Data Fabric; Function 7
16:00.0 USB controller: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset USB 3.1 XHCI Controller
16:00.1 SATA controller: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset SATA Controller
16:00.2 PCI bridge: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset Switch Upstream Port
20:09.0 PCI bridge: Advanced Micro Devices, Inc. [AMD] Device 43ea
2a:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8125 2.5GbE Controller (rev 04)
2b:00.0 Non-Volatile memory controller: Samsung Electronics Co Ltd NVMe SSD Controller SM961/PM961/SM963
30:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Cezanne [Radeon Vega Series / Radeon Vega Mobile Series] (rev c9)
30:00.1 Audio device: Advanced Micro Devices, Inc. [AMD/ATI] Renoir Radeon High Definition Audio Controller
30:00.2 Encryption controller: Advanced Micro Devices, Inc. [AMD] Family 17h (Models 10h-1fh) Platform Security Processor
30:00.3 USB controller: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1
30:00.4 USB controller: Advanced Micro Devices, Inc. [AMD] Renoir/Cezanne USB 3.1
30:00.6 Audio device: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller
2.2 其中 16:00.1 SATA controller: Advanced Micro Devices, Inc. [AMD] 500 Series Chipset SATA Controller 是sata控制器
2.3 查看硬盘所属硬盘控制器
ls -la /sys/dev/block/|grep -v loop |grep -v dm
root@pve:~# ls -la /sys/dev/block/|grep -v loop |grep -v dm
total 0
drwxr-xr-x 2 root root 0 Nov 25 13:51 .
drwxr-xr-x 4 root root 0 Nov 25 13:51 ..
lrwxrwxrwx 1 root root 0 Nov 25 13:51 259:0 -> ../../devices/pci0000:00/0000:00:02.2/0000:2b:00.0/nvme/nvme0/nvme0n1
lrwxrwxrwx 1 root root 0 Nov 25 13:51 259:1 -> ../../devices/pci0000:00/0000:00:02.2/0000:2b:00.0/nvme/nvme0/nvme0n1/nvme0n1p1
lrwxrwxrwx 1 root root 0 Nov 25 13:51 259:2 -> ../../devices/pci0000:00/0000:00:02.2/0000:2b:00.0/nvme/nvme0/nvme0n1/nvme0n1p2
lrwxrwxrwx 1 root root 0 Nov 25 13:51 259:3 -> ../../devices/pci0000:00/0000:00:02.2/0000:2b:00.0/nvme/nvme0/nvme0n1/nvme0n1p3
lrwxrwxrwx 1 root root 0 Nov 25 13:51 8:0 -> ../../devices/pci0000:00/0000:00:02.1/0000:16:00.1/ata3/host2/target2:0:0/2:0:0:0/block/sda
lrwxrwxrwx 1 root root 0 Nov 25 13:51 8:1 -> ../../devices/pci0000:00/0000:00:02.1/0000:16:00.1/ata3/host2/target2:0:0/2:0:0:0/block/sda/sda1
lrwxrwxrwx 1 root root 0 Nov 25 13:51 8:16 -> ../../devices/pci0000:00/0000:00:02.1/0000:16:00.1/ata4/host3/target3:0:0/3:0:0:0/block/sdb
lrwxrwxrwx 1 root root 0 Nov 25 13:51 8:17 -> ../../devices/pci0000:00/0000:00:02.1/0000:16:00.1/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb1
3.1开启iommu
#编辑grub,请不要盲目改。根据自己的环境,选择设置
nano /etc/default/grub
#在里面找到:
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
#然后修改为:
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt pcie_acs_override=downstream,multifunction"
#如果是amd cpu请改为(pcie_acs_override后面为了让不同设备有不同的iommu号,如果有相同号不能直通):
GRUB_CMDLINE_LINUX_DEFAULT="quiet amd_iommu=on iommu=pt pcie_acs_override=downstream,multifunction"
3.2直接更新grub
update-grub
3.3加载相应的内核模块
echo vfio >> /etc/modules
echo vfio_iommu_type1 >> /etc/modules
echo vfio_pci >> /etc/modules
echo vfio_virqfd >> /etc/modules
3.4命令更新内核参数,重启主机
update-initramfs -k all -u
reboot
3.验证是否开启iommu
dmesg | grep iommu
[ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.8.4-2-pve root=/dev/mapper/pve-root ro quiet amd_iommu=on iommu=pt pcie_acs_override=downstream,multifunction
[ 0.040394] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.8.4-2-pve root=/dev/mapper/pve-root ro quiet amd_iommu=on iommu=pt pcie_acs_override=downstream,multifunction
[ 0.324800] iommu: Default domain type: Passthrough (set via kernel command line)
[ 0.355194] pci 0000:00:01.0: Adding to iommu group 0
[ 0.355217] pci 0000:00:02.0: Adding to iommu group 1
[ 0.355233] pci 0000:00:02.1: Adding to iommu group 2
[ 0.355248] pci 0000:00:02.2: Adding to iommu group 3
[ 0.355271] pci 0000:00:08.0: Adding to iommu group 4
[ 0.355286] pci 0000:00:08.1: Adding to iommu group 5
[ 0.355311] pci 0000:00:14.0: Adding to iommu group 6
[ 0.355324] pci 0000:00:14.3: Adding to iommu group 6
[ 0.355383] pci 0000:00:18.0: Adding to iommu group 7
[ 0.355397] pci 0000:00:18.1: Adding to iommu group 7
.......
4. 添加直通硬件
截屏2024-11-25 14.10.40.png