USB-IP

Contents

[ hide ]

    1 Preliminary Note

    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 blackPanther OS v9-10.x These settings might differ for you, so you have to replace them where appropriate.

    2 Installing And Using USB/IP On The Server

    installing usbip-client usbip-server

    (if not in installing database then check on ftp.blackpanther.hu Devel or Seeker sources)

    server1:

    First we load the usbip kernel module:

    modprobe usbip

    To check if it really got loaded, run:

    lsmod | grep usbip

    The output should be similar to this one:

    [1]# lsmod | grep usbip
    usbip                  17988  0
    usbip_common_mod       22168  1 usbip
    usbcore               219188  2 usbip
    [2]#

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

    mcedit /etc/modprobe.preload

    [3]
    usbip

    Now we can start the usbip daemon:

    usbipd -D

    src# usbipd -D
    Bind usbip.ko to a usb device to be exportable!
    src#

    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:

    src# lsusb
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 002: ID 058f:6362 Alcor Micro Corp. Hi-Speed 21-in-1 Flash Card Reader/Writer (Internal/External)
    Bus 001 Device 003: ID 0781:5151 SanDisk Corp. Cruzer Micro Flash Drive
    Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
    src#

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

    Now run

    bind_driver –list

    The output on my server is as follows:

    [4]# bind_driver –list
    List USB devices
    – busid 1-4 (058f:6362)
    1-4:1.0 -> usb-storage

    – busid 1-5 (0781:5151)
    1-5:1.0 -> usb-storage

    [5]#

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

    bind_driver –usbip 1-5

    [6]# bind_driver –usbip 1-5

      •  (process:5807): DEBUG:  1-5:1.0      -> usb-storage
      •  (process:5807): DEBUG: unbinding interface
      •  (process:5807): DEBUG: write “add 1-5” to /sys/bus/usb/drivers/usbip/match_busid
      •  Message: bind 1-5 to usbip, complete!

    [7]#

    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:

    [8]# netstat -tap
    Active Internet connections (servers and established)
    Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
    tcp        0      0 *:nfs                       *:*                         LISTEN      –
    tcp        0      0 *:41286                     *:*                         LISTEN      2258/rpc.mountd
    tcp        0      0 *:3240                      *:*                         LISTEN      5780/usbipd
    tcp        0      0 server1.example.com:10026   *:*                         LISTEN      2309/master
    tcp        0      0 server1.example.com:11211   *:*                         LISTEN      1843/memcached
    tcp        0      0 *:59887                     *:*                         LISTEN      1865/rpc.statd
    tcp        0      0 *:sunrpc                    *:*                         LISTEN      1828/rpcbind
    tcp        0      0 *:5555                      *:*                         LISTEN      1867/dc_server
    tcp        0      0 *:ftp                       *:*                         LISTEN      2315/proftpd: (acce
    tcp        0      0 *:44725                     *:*                         LISTEN      –
    tcp        0      0 *:ssh                       *:*                         LISTEN      2185/sshd
    tcp        0      0 server1.example.com:smtp    *:*                         LISTEN      2309/master
    tcp        0      0 *:https                     *:*                         LISTEN      2321/httpd
    tcp        0    596 192.168.0.101:ssh           192.168.0.26:4758           ESTABLISHED 2364/sshd: administ
    tcp        0      0 *:netbios-ssn               *:*                         LISTEN      2164/smbd
    tcp        0      0 *:sunrpc                    *:*                         LISTEN      1828/rpcbind
    tcp        0      0 *:http                      *:*                         LISTEN      2321/httpd
    tcp        0      0 *:48117                     *:*                         LISTEN      –
    tcp        0      0 *:ssh                       *:*                         LISTEN      2185/sshd
    tcp        0      0 *:microsoft-ds              *:*                         LISTEN      2164/smbd
    [9]#

    3 Installing And Using USB/IP On The Client

    client1:

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

    [10]# lsmod | grep vhci_hcd
    vhci_hcd               22840  0
    usbip_common_mod       22168  1 vhci_hcd
    usbcore               219188  2 vhci_hcd
    [11]#

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

    vi /etc/modprobe.preload

    [12]
    vhci-hcd

    Now we must install usbip on the client. The steps are the same as on the server:

    urpmi wget flex gcc gcc-c++ libsysfs-devel libglib2.0-devel

    cd /tmp
    wget http://downloads.sourceforge.net/project/usbip/usbip/0.1.7/usbip-0.1.7.tar.gz?use_mirror=kent
    tar xvfz usbip-0.1.7.tar.gz
    cd usbip-0.1.7/src/
    ./autogen.sh
    ./configure
    make
    make install

    usbip expects the file containing the list of known USB devices (usb.ids) in the directory /usr/share/hwdata, but on blackPanther OS it’s located in /usr/share/usb.ids – therefore we create a symlink:

    mkdir /usr/share/hwdata
    ln -sf /usr/share/usb.ids /usr/share/hwdata/

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

    [13]# usbip -l 192.168.0.100
    – 192.168.0.100
    1-5: SanDisk Corp. : Cruzer Micro Flash Drive (0781:5151)

     /sys/devices/pci0000:00/0000:00:02.1/usb1/1-5
     (Defined at Interface level) (00/00/00)
      0 – Mass Storage / SCSI / Bulk (Zip) (08/06/50)

    [14]#


    To attach that device to the client, run:

    usbip -a 192.168.0.100 1-5

    src# usbip -a 192.168.0.100 1-5
    8 ports available

    port 0 attached
    src#

    Now run…

    lsusb

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

    src# lsusb
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 001 Device 023: ID 0781:5151 SanDisk Corp. Cruzer Micro Flash Drive
    src#

    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:

    [15]# usbip –port
    8 ports available

    Port 00: <Port in Use> at High Speed(480Mbps)
    SanDisk Corp. : Cruzer Micro Flash Drive (0781:5151)
    1-1 -> usbip://192.168.0.100:3240/1-5  (remote devid 00010003 (bus/dev 001/003))
    1-1:1.0 used by usb-storage
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/target5:0:0/5:0:0:0/block/sdb/device
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/target5:0:0/5:0:0:0/bsg/5:0:0:0/device
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/target5:0:0/5:0:0:0/scsi_device/5:0:0:0/device
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/target5:0:0/5:0:0:0/scsi_disk/5:0:0:0/device
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/target5:0:0/5:0:0:0/scsi_generic/sg2/device
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/scsi_host/host5/device
    /sys/devices/platform/vhci_hcd/usb1/1-1/1-1:1.0/host5/target5:0:0/5:0:0:0/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>
    [16]#

    We need the port number to detach the device:

    usbip -d 00

    src# usbip -d 00
    8 ports available

    port 0 detached
    src#

    On the server, we use the BUSID (1-5) 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:

    bind_driver –other 1-5

    [17]# bind_driver –other 1-5

      •  (process:3484): DEBUG: write “del 1-5” to /sys/bus/usb/drivers/usbip/match_busid
      •  Message: bind 1-5 to other drivers than usbip, complete!

    [18]#

    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:

    src# lsusb
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    src#

    This page is a Wiki! Log in or register an account to edit.
    admin

    About admin