Share USB drive over network

I'm looking for a free method to share an USB device over network. I got a RaspberryPi (raspbian) which has an USB device connected. I want to be able to receive and send command to this device from my Linux server.

I tried remserial but I'm unable to connect the client to the server. i also tried VirtualHere but it crashed

Do you know some free solution to do it ?

EDIT :

Thx for this tutorial, i tried it but i got some trouble :

pi@raspberrypi /boot $ zcat /proc/config.gz |grep USBIP
CONFIG_USBIP_CORE=m
CONFIG_USBIP_VHCI_HCD=m
CONFIG_USBIP_HOST=m
# CONFIG_USBIP_DEBUG is not set
pi@raspberrypi /boot $ sudo modprobe usbip-core
pi@raspberrypi /boot $ sudo modprobe usbip-host
pi@raspberrypi /boot $ sudo usbipd -D

pi@raspberrypi /boot $ usbip list -l
Local USB devices
=================
- busid 1-1 (0424:9514)
     1-1:1.0 -> hub
- busid 1-1.1 (0424:ec00)
     1-1.1:1.0 -> smsc95xx
- busid 1-1.3 (0403:6010)
     1-1.3:1.0 -> unknown
     1-1.3:1.1 -> unknown
- busid 1-1.4 (04f2:1126)
     1-1.4:1.0 -> usbhid
- busid 1-1.5 (04f2:1125)
     1-1.5:1.0 -> usbhid
     1-1.5:1.1 -> usbhid

pi@raspberrypi /boot $ sudo usbip --debug  bind -b 1-1.3
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip.c:134:[run_command]
running command: `bind'
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip_bind.c:162:[unbind_other]
1-1.3:1.0 -> unknown
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip_bind.c:162:[unbind_other]
1-1.3:1.1 -> unknown
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/utils.c:65:[modify_match_busid]
write "add 1-1.3" to /sys/bus/usb/drivers/usbip-host/match_busid
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip_bind.c:101:[bind_usbip]
bind driver at 1-1.3:1.0 failed
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip_bind.c:101:[bind_usbip]
bind driver at 1-1.3:1.1 failed
usbip: error: could not bind device to usbip-host
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/utils.c:65:[modify_match_busid]
write "del 1-1.3" to /sys/bus/usb/drivers/usbip-host/match_busid
  pi@raspberrypi /boot $ sudo usbip --debug  bind -b 1-1.3:1.1
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip.c:134:[run_command]
  running command: `bind'
usbip: debug: /build/linux-tools-TqR1ks/linux-tools-3.2.17/drivers/staging/usbip/userspace/src/usbip_bind.c:143:[unbind_other]
  problem getting device attributes: No such file or directory
usbip: error: could not unbind driver from device on busid 1-1.3:1.1
pi@raspberrypi /boot $

what could it be ?


you can use this software usbip and this is how to setup the software and use it on both the server and client side

Notes:

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

  2. Also The account used in this tutorial is the root so if a command is not working either use the root or use sudo before the command

Installing And Using USB/IP On The Server

We can install usbip as follows:

apt-get 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:

root@server1:~# lsmod | grep usbip
usbip                  15124  0
usbip_common_mod       13605  1 usbip
root@server1:~#

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:

root@server1:~# usbipd -D
Bind usbip.ko to a usb device to be exportable!

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:

root@server1:~# 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

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

Now run

usbip_bind_driver --list
root@server1:~# usbip_bind_driver --list
List USB devices
 - busid 1-1 (0781:5151)
     1-1:1.0 -> usb-storage

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:

root@server1:~# usbip_bind_driver --usbip 1-1
** (process:765): DEBUG:  1-1:1.0       -> usb-storage
** (process:765): DEBUG: unbinding interface
** (process:765): DEBUG: write "add 1-1" to /sys/bus/usb/drivers/usbip/match_busid
** Message: bind 1-1 to usbip, complete!

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:

root@server1:~# netstat -tap
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:ssh                   *:*                     LISTEN      537/sshd
tcp        0      0 *:3240                  *:*                     LISTEN      762/usbipd
tcp        0     52 server1.example.com:ssh 192.168.0.199:4024      ESTABLISHED 667/0
tcp6       0      0 [::]:ssh                [::]:*                  LISTEN      537/sshd

Installing And Using USB/IP On The Client

We need to install usbip on the client as well:

sudo apt-get install usbip

Afterwards we load the vhci-hcd kernel module:

modprobe vhci-hcd

To check if it really got loaded, run:

root@client1:~# lsmod | grep vhci_hcd
vhci_hcd               19800  0
usbip_common_mod       13605  1 vhci_hcd

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):

root@client1:~# usbip -l 192.168.0.100
- 192.168.0.100
     1-1: SanDisk Corp. : Cruzer Micro Flash Drive (0781:5151)
        : /sys/devices/pci0000:00/0000:00:07.2/usb1/1-1
        : (Defined at Interface level) (00/00/00)
        :  0 - Mass Storage / SCSI / Bulk (Zip) (08/06/50)

To attach that device to the client, run:

root@client1:~# usbip -a 192.168.0.100 1-1
8 ports available
port 0 attached

Now run lsusb and you should find the remote USB device in the output on the client:

root@client1:~# lsusb
Bus 001 Device 002: ID 0781:5151 SanDisk Corp. Cruzer Micro 256/512MB Flash Drive
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

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.).

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:

root@client1:~# usbip --port
8 ports available

Port 00: <Port in Use> at High Speed(480Mbps)
       SanDisk Corp. : Cruzer Micro 256/512MB Flash Drive (0781:5151)
       1-1 -> usbip://192.168.0.100:3240/1-1  (remote devid 00010002 (bus/dev 001/002))
       1-1:1.0 used by usb-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
Port 01: <Port Available>
Port 02: <Port Available>
Port 03: <Port Available>
Port 04: <Port Available>
Port 05: <Port Available>
Port 06: <Port Available>
Port 07: <Port Available>

We need the port number to detach the device:

usbip -d 00

root@client1:~# usbip -d 00
8 ports available

port 0 detached

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

root@server1:~# 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!

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

client1:

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

root@client1:~# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub 

Links

http://usbip.sourceforge.net

Source of the tutorial (Server Side)

Source of the tutorial (Client Side)