新增 將PCIe直通給PVE的虛擬機

2026-05-21 17:50:49 +00:00
parent 91fb9c56dc
commit e964314a56
@@ -0,0 +1,97 @@
# Step 1. 修改引導設定檔
```bash
nano /etc/default/grub
```
(找到 GRUB_CMDLINE_LINUX_DEFAULT 行,依據 CPU 類型加入參數)
- Intel CPUintel_iommu=on iommu=pt
(範例:``` GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt" ```)
- AMD CPUamd_iommu=on iommu=pt
(更新 Grub 引導並重啟速主機)
```bash
update-grub && reboot
```
(重啟後,輸入 ``` dmesg | grep -e DMAR -e IOMMU ```。若看到 ``` IOMMU enabled ``` 代表啟用成功)
# Step 2. 載入 VFIO 核心模組
```bash
nano /etc/modules
```
(在檔案末尾加上以下四行)
```
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
```
# Step 3. 尋找控制器 ID (以 Thunderbolt 為例)
找出控制器的 PCI 位址與硬體 ID
```bash
lspci -nnk | grep -i thunderbolt
```
- PCI 位址:例如 ``` 00:0d.0 ```
- 硬體 ID:例如 ``` 8086:9a1b ```
# Step 4. 阻斷宿主機驅動
為了防止 PVE 宿主機搶先佔用控制器,必須強迫它使用 ``` vfio-pci ``` 驅動
```bash
nano /etc/modprobe.d/vfio.conf
```
(寫入以下內容)
```bash
softdep thunderbolt pre: vfio-pci
options vfio-pci ids=8086:9a1b,8086:9a1d disable_vga=1
```
(更新 initramfs 核心映像並重啟速主機)
```bash
update-initramfs -u -k all && reboot
```
(重啟後,輸入 ``` lspci -nnk -s 00:0d.0 ```。若看到 ``` Kernel driver in use: vfio-pci ``` 代表隔離成功)
# Step 5. 將裝置新增至虛擬機
- 位置:硬體 > 新增 > PCI 裝置
- 原始裝置:選取控制器位址
- [v] All Functions
- [v] ROM-Bar
- [v] PCI-Express
# PVE 可能是使用 systemd-boot 而非 GRUB
```bash
nano /etc/kernel/cmdline
```
(檢查檔案內是否有以下內容,如果沒有,則直接加在原本內容的尾端)
```
intel_iommu=on iommu=pt
```
(讓核心參數生效)
```bash
proxmox-boot-tool refresh
```