PVE虚拟机直通USB

在Proxmox VE(PVE)系统开启IOMMU功能实现硬件直通之前,我们要确认CPU是否支持VT-D技术;开启直通的必要条件 Intel CPU支持VT-D,同时主板要开启VT-D支持。

使用USB直通的主要原因是能够将几个具有相同ID的USB设备连接到不同的虚拟机上(device-1 to VM1, device-2 to VM2, etc)

USB硬件设备映射

从主机上查找

1
2
3
4
5
6
7
8
9
10
11
12
lsusb -t
/: Bus 05.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
|__ Port 1: Dev 4, If 0, Class=vend., Driver=usbfs, 1.5M
|__ Port 2: Dev 5, If 0, Class=vend., Driver=usbfs, 1.5M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=uhci_hcd/2p, 12M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/2p, 480M
|__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/4p, 480M
|__ Port 3: Dev 5, If 0, Class=comm., Driver=usbfs, 480M
|__ Port 3: Dev 5, If 1, Class=data, Driver=usbfs, 480M

  • Example 1: Bus 3, Port 1 => 3-1
  • Example 2: Bus 1, Port 1, Port 3 => 1-1.3

将设备添加到虚拟机中

Proxmox 2.x及以后版本

1
vi /etc/pve/qemu-server/<VM_ID>.conf

配置文件中添加语句(如上例中总线与端口)

1
2
usb0: host=3-1
usb1: host=1-1.3

Proxmox 1.x

1
2
args: -device usb-host,hostbus=3,hostport=1
args: -device usb-host,hostbus=1,hostport=1.3

停止并重新启动虚拟机

需要停止虚拟机并启动,检查USB设备是否被虚拟机看到

通过Qemu/KVM工具检验虚拟机的USB设备

1
2
3
4
5
6
7
8
9
10
11
qm monitor <VM_ID>
qm> info usbhost
Bus 3, Addr 2, Port 1.2, Speed 1.5 Mb/s
Vendor Specific: USB device 0529:0001, HASP 2.17
Bus 5, Addr 3, Port 2, Speed 12 Mb/s
Class 00: USB device 0624:0248, USB Composite Device-0
qm> info usb
Device 0.2, Port 1, Speed 12 Mb/s, Product QEMU USB Tablet
Device 0.3, Port 2, Speed 12 Mb/s, Product QEMU USB Hub
Device 1.1, Port 1, Speed 1.5 Mb/s, Product HASP 2.17
Device 1.0, Port 2, Speed 480 Mb/s, Product USB Host Device