我在以下位置定义了一个 USB 设备virt/usb-serial.xml
:
<serial type="dev">
<source path="/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2403534-if00"/>
<target type="usb-serial" port="1">
<model name="usb-serial"/>
</target>
<address type="usb" bus="0" port="5"/>
</serial>
我成功地附加了它,如下所示:
virsh # detach-device hass4 virt/usb-serial.xml --persistent
Device detached successfully
VM 能够完美地访问 USB 设备。但是,在重新启动主机设备后,由于此 USB 串行设备,虚拟机无法启动:
virsh # start hass4
error: Failed to start domain 'hass4'
error: internal error: process exited while connecting to monitor: 2023-06-01T20:28:52.153257Z qemu-system-x86_64: -chardev serial,id=charserial1,path=/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2403534-if00: Could not open '/dev/serial/by-id/usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2403534-if00': Permission denied
分离设备可以让虚拟机正常启动,但奇怪的是在启动后我可以再次成功连接设备:
virsh # detach-device hass4 virt/usb-serial.xml --persistent
Device detached successfully
virsh # start hass4
Domain 'hass4' started
virsh # attach-device hass4 virt/usb-serial.xml
Device attached successfully
为什么它在首次启动时失败?如何解决权限问题?对于上下文,我在中定义了这一点/lib/udev/rules.d/51-qemu-usb-passthrough.rules
:
SUBSYSTEM=="usb", ATTRS{idVendor}=="1cf1" ATTRS{idProduct}=="0030" GROUP="libvirt"
这些是该设备相应的供应商和产品 ID:
$ lsusb -d 1cf1:0030
Bus 003 Device 010: ID 1cf1:0030 Dresden Elektronik ZigBee gateway [ConBee II]
在/etc/libvirt/qemu.conf
我已经设置:
user = "henrik"
group = "libvirt"
作为henrik
我运行这些命令的用户。