There are some scenarios in which the software running in your Virtual Machine requires a usb device to be attached to the machine. There are different solutions for this, in software and in hardware, and the best solution depends on the details of each case.
The recipe below is an example solution, using a USBIP that allows sharing usb devices between Virtual Machines.
Disclaimer: This procedure has been adapted from USB/IP Wiki and tested in CERN CentOS 7. If you are using a different Linux flavor, please modify it accordingly.
This procedure is available for Linux machines. If you are running Windows, please contact the cloud team via opening a service desk ticket.
Configure server machine to share its usb devices
-
Install the software
-
In CentOS 7 there is no systemd unit, we can create one for this particular purpose
$ cat > /usr/lib/systemd/system/usbip-server.service <<EOF [Unit] Description=USB/IP server daemon [Service] ExecStartPre=/sbin/modprobe -qab usbip_host ExecStart=/usr/sbin/usbipd [Install] WantedBy=multi-user.target EOF $ chown root:root /usr/lib/systemd/system/usbip-server.service $ chcon -u system_u -t systemd_unit_file_t /usr/lib/systemd/system/usbip-server.service $ systemctl daemon-reload
- Enable and start the systemd unit
-
Set the firewall rules to allow the client to connect
-
To list the exportable devices, you can type
-
In order to export the device you need to bind it with the busid information such
Configure client machine to access exported usb devices
-
Install the software
-
In CentOS7 there is no systemd unit, we can create one for this particular purpose
$ cat > /usr/lib/systemd/system/usbip-client.service <<EOF [Unit] Description=USB/IP client modules [Service] Type=oneshot RemainAfterExit=true ExecStart=/sbin/modprobe -qab vhci-hcd [Install] WantedBy=multi-user.target EOF $ chown root:root /usr/lib/systemd/system/usbip-client.service $ chcon -u system_u -t systemd_unit_file_t /usr/lib/systemd/system/usbip-client.service $ systemctl daemon-reload
-
Enable and start the systemd unit
-
You can list the registered devices on the server by
$ usbip list --remote=<server IP address> Exportable USB devices ====================== - xxx.xxx.xxx.xxx 3-2: Logitech, Inc. : B525 HD Webcam (046d:0836) : /sys/devices/pci0000:00/0000:00:1d.0/0000:06:00.0/0000:07:01.0/0000:09:00.0/0000:0a:00.0/0000:0b:00.0/usb3/3-2 : Miscellaneous Device / ? / Interface Association (ef/02/01)
-
Let's attach the selected device
-
List the ports in use (attached devices)
-
Detach the device
Advanced configuration
If you need automatic rebind/reattach for usb devices to follow reconnections please use the following recipe