usbip

some introduction

usbip used to be a project hosted on sourceforge, but merged into kernel mainline at last, code is at drivers/staging/usbip/ directory, I found many articles I searched are out of date or misleading, and command arguments may diff between distro.

compile and install

if usbip and its driver is not included in your distro, you’ll have to do it yourself, take kernel 3.8 as example, copy codes mentioned above, do as README said:

# ./autogen.sh
# ./configure --prefix=/usr/
# make -j 10
# make install

make install may report error, looks like lack of sth. when installing man page, I didn’t notice ignoring man page option in configure, so I modified Makefile to ignore it. After running “make install” you’ll have following files:

/usr/include/usbip/
/usr/lib64/libusbip.a
/usr/lib64/libusbip.la
/usr/lib64/libusbip.so
/usr/lib64/libusbip.so.0
/usr/lib64/libusbip.so.0.0.1
/usr/sbin/usbip
/usr/sbin/usbipd

Module is in “Staging drivers”, called “USB/IP support”, after enabling it, you will see “VHCI hcd” and “Host driver” available now, please also enable. In newer kernel usbip is moved from staging driver to drivers/usb/usbip/.

usage on server side

Load usbip_host module first, then issue usbipd to start daemon process(some distro has corresponding systemd service), use usbip list -l to list current devices:

# usbip list -l
usbip: error: failed to open /usr/share/hwdata//usb.ids
Local USB devices
=================
  - busid 1-1 (8087:0024)
        1-1:1.0 -> hub
  - busid 2-1 (8087:0024)
        2-1:1.0 -> hub
  - busid 2-1.7 (12d1:1506)
        2-1.7:1.0 -> usbip-host

now let’s expose specificed device, take 1506 as example:

usbip bind --busid 2-1.7

usage on client side

Load usbip_host vhci_hcd, then list remote devices:

 # usbip list --remote 199.16.158.183
 Exportable USB devices
 ======================
  - 199.16.158.183
     2-1.7: unknown vendor : unknown product (12d1:1506)
          : /sys/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.7
          : (Defined at Interface level) (00/00/00)
          :  0 - Vendor Specific Class / unknown subclass / unknown protocol (ff/00/50)

bind remote device:

# usbip attach -r 199.16.158.183 -b 2-1.7

Tue bus id after “-b” option should be same as remote device. List binded device:

# usbip port
 Imported USB devices
 ====================
 Port 00: <Port in Use> at High Speed(480Mbps)
      unknown vendor : unknown product (12d1:1506)
      5-1 -> usbip://199.16.158.183:3240/2-1.7
          -> remote bus/dev 002/014

detach device, the port is the number after the above “Port”:

# usbip detach --port 00