How To Set Up A USB-Over-IP Server And Client With Ubuntu 10.04

https://www.howtoforge.com/how-to-set-up-a-usb-over-ip-server-and-client-with-ubuntu-10.04

Version 1.0
Author: Falko Timme
Follow me on Twitter

This tutorial shows how to set up a USB-over-IP server with Ubuntu 10.04 as well as a USB-over-IP client (also running Ubuntu 10.04). The USB/IP Project aims to develop a general USB device sharing system over IP network. To share USB devices between computers with their full functionality, USB/IP encapsulates “USB I/O messages” into TCP/IP payloads and transmits them between computers. USB-over-IP can be useful for virtual machines, for example, that don’t have access to the host system’s hardware – USB-over-IP allows virtual machines to use remote USB devices.

I do not issue any guarantee that this will work for you!

1 Preliminary Note

This tutorial is based onAliRezaTaleghani’s tutorial How To Modify Your Gnu/Linux Box To Serve As A USB Over IP Server, but I’ve adjusted it for Ubuntu 10.04 (server and client). If you want to use a Windows client, please take a look at AliRezaTaleghani’s tutorial – that part is still the same.

In this tutorial I use the server server1.example.com with the IP address 192.168.0.100 and the client client1.example.com with the IP address 192.168.0.101, both running Ubuntu 10.04. These settings might differ for you, so you have to replace them where appropriate.

2 Installing And Using USB/IP On The Server

server1:

We can install usbip as follows:

aptitude install usbip

Afterwards we load the usbip kernel modules:

modprobe usbip
modprobe usbip_common_mod

To check if they really got loaded, run:

lsmod | grep usbip

The output should be similar to this one:

[email protected]:~#lsmod|grepusbip
usbip151240
usbip_common_mod136051usbip
[email protected]:~#

To make sure that both modules get loaded automatically whenever you boot the system, you can add them to /etc/modules:

vi /etc/modules

[...]
usbip
usbip_common_mod

Now we can start the usbip daemon:

usbipd -D

[email protected]:~# usbipd -D
Bind usbip.ko to a usb device to be exportable!
[email protected]:~#

Now attach a USB device that you want to export to the server – I’m using a SanDisk USB flash drive here.

Execute the command

lsusb

to find the corresponding Vendor/Device ID which is in the form of:

Bus XXX Device YYY: ID VendorID:DeviceID

The output on my server is as follows:

[email protected]:~# lsusb
Bus 001 Device 002: ID 0781:5151 SanDisk Corp. Cruzer Micro Flash Drive
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
[email protected]:~#

The Vendor/Device ID of my SanDisk USB flash drive is 0781:5151.

Now run

usbip_bind_driver –list

The output on my server is as follows:

[email protected]:~#usbip_bind_driver–list
ListUSBdevices
-busid1-1(0781:5151)
1-1:1.0->usb-storage

[email protected]:~#

As you see, the Vendor/Device ID of my SanDisk USB flash drive (0781:5151) corresponds to the BUSID 1-1. We need this BUSID to attach the USB device to the server:

usbip_bind_driver –usbip 1-1

[email protected]:~#usbip_bind_driver–usbip1-1
**(process:765):DEBUG:1-1:1.0->usb-storage
**(process:765):DEBUG:unbindinginterface
**(process:765):DEBUG:write”add1-1″to/sys/bus/usb/drivers/usbip/match_busid
**Message:bind1-1tousbip,complete!
[email protected]:~#

That’s it, we can now use the SanDisk USB flash drive on a remote usbip client.

BTW, if you run…

netstat -tap

… you should see that the usbip daemon is listening on port 3240 so please make sure that this port isn’t blocked by your firewall:

[email protected]:~#netstat-tap
ActiveInternetconnections(serversandestablished)
ProtoRecv-QSend-QLocalAddressForeignAddressStatePID/Programname
tcp00*:ssh*:*LISTEN537/sshd
tcp00*:3240*:*LISTEN762/usbipd
tcp052server1.example.com:ssh192.168.0.199:4024ESTABLISHED667/0
tcp600[::]:ssh[::]:*LISTEN537/sshd
[email protected]:~#

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

https://www.howtoforge.com/how-to-set-up-a-usb-over-ip-server-and-client-with-ubuntu-10.04-p2

3 Installing And Using USB/IP On The Client

client1:

We must install usbip on the client as well:

aptitude install usbip

Afterwards we load the vhci-hcd kernel module:

modprobe vhci-hcd

To check if it really got loaded, run:

lsmod | grep vhci_hcd

The output should be similar to this one:

[email protected]:~#lsmod|grepvhci_hcd
vhci_hcd198000
usbip_common_mod136051vhci_hcd
[email protected]:~#

To make sure that the module gets loaded automatically whenever you boot the system, you can add it to /etc/modules:

vi /etc/modules

[...]
vhci-hcd

Now connect to the usbip server and get a list of available USB devices:

usbip -l 192.168.0.100

(192.168.0.100 is the IP address of the usbip server.)

You should find the SanDisk USB flash drive in the output (BUSID 1-1):

[email protected]:~#usbip-l192.168.0.100
-192.168.0.100
1-1:SanDiskCorp.:CruzerMicroFlashDrive(0781:5151)
:/sys/devices/pci0000:00/0000:00:07.2/usb1/1-1
:(DefinedatInterfacelevel)(00/00/00)
:0-MassStorage/SCSI/Bulk(Zip)(08/06/50)

[email protected]:~#

To attach that device to the client, run:

usbip -a 192.168.0.100 1-1

[email protected]:~# usbip -a 192.168.0.100 1-1
8 ports available

port 0 attached
[email protected]:~#

Now run…

lsusb

… and you should find the remote USB device in the output on the client:

[email protected]:~#lsusb
Bus001Device002:ID0781:5151SanDiskCorp.CruzerMicro256/512MBFlashDrive
Bus001Device001:ID1d6b:0002LinuxFoundation2.0roothub
[email protected]:~#

You can now use the remote USB device as if it was a local USB device (e.g. mount it, format it, write to it, read form it, etc.).

4 Detaching A Remote USB Device

A remote USB device can be detached as follows:

client1:

Run…

usbip –port

… to find out the port that the remote USB device uses on the client – in this case it’s port 00:

[email protected]:~#usbip–port
8portsavailable

Port00:<PortinUse>atHighSpeed(480Mbps)
SanDiskCorp.:CruzerMicro256/512MBFlashDrive(0781:5151)
1-1->usbip://192.168.0.100:3240/1-1(remotedevid00010002(bus/dev001/002))
1-1:1.0usedbyusb-storage
/sys/class/bsg/1:0:0:0/device
/sys/class/scsi_device/1:0:0:0/device
/sys/class/scsi_disk/1:0:0:0/device
/sys/class/scsi_host/host1/device
/sys/class/usb_endpoint/usbdev1.4_ep02/device
/sys/class/usb_endpoint/usbdev1.4_ep81/device
/sys/block/sdb/device
Port01:<PortAvailable>
Port02:<PortAvailable>
Port03:<PortAvailable>
Port04:<PortAvailable>
Port05:<PortAvailable>
Port06:<PortAvailable>
Port07:<PortAvailable>
[email protected]:~#

We need the port number to detach the device:

usbip -d 00

[email protected]:~# usbip -d 00
8 ports available

port 0 detached
[email protected]:~#

On the server, we use the BUSID (1-1) to bind the USB device to the local system (the –other switch binds the device to the local system so that it is not available over the network anymore):

server1:

usbip_bind_driver –other 1-1

[email protected]:~# usbip_bind_driver –other 1-1
** (process:7333): DEBUG: write “del 1-1” to /sys/bus/usb/drivers/usbip/match_busid
** Message: bind 1-1 to other drivers than usbip, complete!
[email protected]:~#

Now go back to the client and check if the remote USB device is still available:

client1:

lsusb

If all goes well, it shouldn’t be listed anymore:

[email protected]:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
[email protected]:~#

5 Links

USB/IP Project: http://usbip.sourceforge.net/

Ubuntu: http://www.ubuntu.com/

Similar Posts: