The need for a USB over IP happen when your VM is hosted on a hypervisor like HyperV, VMware and so on.

For VMware you can mount USB on one node but downside is that VM will always stay on the same node. Using a USB over IP solution VM can migrate between hosts which is proffered solution.

For configuring USB over IP we have 2 options:

  • usbip project
  • VirtualHere

The first solution works fine but it has some security concerns due to the fact that is not maintainer anymore. VirtualHere is a paid solution it you have more than 1 USB and want to run client as a service.
For today we will use USBIP project but I will add also an example for VirtualHere in the future.

  • USBIP

We need to install usbip on client and server:

# apt install usbip -y

We are ready to configure our usbip client and server.

For server we need to list all usbs connected:

root@server:~# /usr/sbin/usbip list -l
 - busid 1-1.3 (0529:0620)
   Aladdin Knowledge Systems : Token JC (0529:0620)

Still on server let’s create a service to bind it:

root@server:~# cat /lib/systemd/system/usbipd.service
[Unit]
Description=usbip server daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/usbipd -D
ExecStartPost=/bin/sh -c "/usr/sbin/usbip bind --$(/usr/sbin/usbip list -p -l | grep '#usbid=0529:0620#' | cut '-d#' -f1)"
ExecStop=/bin/sh -c "/usr/sbin/usbip unbind --$(/usr/sbin/usbip list -p -l | grep '#usbid=0529:0620#' | cut '-d#' -f1); killall usbipd"

[Install]
WantedBy=multi-user.target

Then is the time to create service on the client:

root@client:~# cat /lib/systemd/system/usbipd.service
[Unit]
Description=usbip client daemon
After=network.target

[Service]
Type=forking
ExecStart=/usr/sbin/usbipd -D
ExecStartPost=/bin/sh -c "/usr/sbin/usbip attach -r server_ip -b 1-1.3"
ExecStop=/bin/sh -c "/usr/sbin/usbip detach -p 00"

[Install]
WantedBy=multi-user.target

Categories: Blog

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *