Page:
將PCIe直通給PVE的虛擬機
Pages
修改成台北時區
將PCIe直通給PVE的虛擬機
延展系統硬碟
憑證 x509 問題
進入 busybox 問題
53 埠被占用
Claude:ccstatusline
Database:PostgreSQL
Database:SQLServer
Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block
Service:ASP.NET
Service:Coder
Service:Docker
Service:ElasticSearch
Service:Emby
Service:Gitea
Service:GiteaRunner
Service:Gitlab
Service:MeTube
Service:OpenClaw
Service:OpenCode
Service:PicoClaw
Service:Redis
Service:Traefik
Service:VS Code
Service:Vaultwarden
Service:ezBookkeeping
Service:k3d
Service:netplan
Tool:C# SDK
Tool:Node JS
Tool:Oh My Posh
Clone
This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
簡介
PCIe 直通(Passthrough)可讓 PVE 上的虛擬機直接獨佔某個 PCIe 裝置(例如顯示卡、Thunderbolt 控制器)。重點是先在主機啟用 IOMMU,再以 vfio-pci 驅動接管裝置、阻止宿主機使用它,最後將裝置指派給虛擬機。本文以 Thunderbolt 控制器為例。
Step 1. 修改引導設定檔
啟用 IOMMU 需在核心開機參數加入對應設定。
nano /etc/default/grub
找到 GRUB_CMDLINE_LINUX_DEFAULT 行,依據 CPU 類型加入參數:
- Intel CPU:
intel_iommu=on iommu=pt - AMD CPU:
amd_iommu=on iommu=pt
(Intel 範例)
GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on iommu=pt"
更新 GRUB 引導並重啟主機。
update-grub && reboot
重啟後執行下列指令驗證,若看到 IOMMU enabled 代表啟用成功。
dmesg | grep -e DMAR -e IOMMU
Step 2. 載入 VFIO 核心模組
讓系統開機時自動載入 VFIO 相關模組。
nano /etc/modules
在檔案末尾加上以下四行:
vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd
Step 3. 尋找控制器 ID (以 Thunderbolt 為例)
找出要直通裝置的 PCI 位址與硬體 ID。
lspci -nnk | grep -i thunderbolt
- PCI 位址:例如
00:0d.0 - 硬體 ID:例如
8086:9a1b
Step 4. 阻斷宿主機驅動
為了防止 PVE 宿主機搶先佔用控制器,必須強制它改用 vfio-pci 驅動。
nano /etc/modprobe.d/vfio.conf
寫入以下內容(ids= 後填入 Step 3 取得的硬體 ID):
softdep thunderbolt pre: vfio-pci
options vfio-pci ids=8086:9a1b,8086:9a1d disable_vga=1
更新 initramfs 核心映像並重啟主機。
update-initramfs -u -k all && reboot
重啟後執行下列指令驗證,若看到 Kernel driver in use: vfio-pci 代表隔離成功。
lspci -nnk -s 00:0d.0
Step 5. 將裝置新增至虛擬機
在 PVE 介面為虛擬機加入 PCI 裝置:
- 位置:硬體 > 新增 > PCI 裝置
- 原始裝置:選取控制器位址
- [v] All Functions
- [v] ROM-Bar
- [v] PCI-Express
補充:PVE 可能使用 systemd-boot 而非 GRUB
較新的 PVE 安裝可能以 systemd-boot 開機,此時 Step 1 改 GRUB 不會生效,需改設定核心命令列。
nano /etc/kernel/cmdline
檢查檔案內是否有以下內容,如果沒有,則直接加在原本內容的尾端。
intel_iommu=on iommu=pt
讓核心參數生效。
proxmox-boot-tool refresh