For the virtual machine (VM) to work with external USB devices, configure port redirection on the cluster node:
- Connect the USB device to the cluster node where the VM is located.
- Connect to the cluster node via SSH.
-
Define the full name of the VM (Name column):
virsh list --all
Example outputId Name State --------------------------- 145 115_name1 running 159 2218_name2 running 223 1736_name3 running 523 2117_name4 running
-
Determine the type of controllers added to the VM: get the xml description of the VM and filter by USB controllers:
virsh dumpxml <vm_name> | grep -i -E 'uhci|ehci|xhci'
Example output<controller type='usb' index='0' model='piix3-uhci'> <controller type='usb' index='0' model='ehci'> <controller type='usb' index='1' model='nec-xhci'>
Comments -
Get the bus_id and device_id of your USB device by getting a list of connected USB devices:
lsusb -v
Example outputBus <bus_ID> Device <device_ID>: ID 0cd2:1402 Netac Technology Co., Ltd OnlyDisk
-
Create a file /root/usb_device.xml with the following contents:
<hostdev mode='subsystem' type='usb'> <source> <address bus='<bus_ID>' device='<device_ID>'/> </source> <address type='usb' bus='1' port='0'/> </hostdev>
Comments -
Enable port forwarding:
virsh attach-device <vm_name> --file /root/usb_device.xml --config --persistent
Comments