usbip-utils 2.0 on Ubuntu

Ubuntu 15.10 contains usbip package too old to work with usbip v2.0 server (e.g. latest raspbian on RasPI) so you need to compile usbip tool from kernel sources.

UPDATE 19. 04. 2016:

You don’t need to go through compiling from source. You may just install package linux-tools-generic:

$ apt-get install linux-tools-generic

This will install precompiled usbip tools into /usr/lib/linux-tools/`uname -r`/:

$ /usr/lib/linux-tools/4.2.0-35-generic/usbip version
usbip (usbip-utils 2.0)

Non-working usbip installed from usbip package

$ sudo usbip -l 192.168.1.83
- 192.168.1.83
usbip err: usbip_network.c: 119 (usbip_recv_op_common) recv op_common, -1
usbip err: vhci_attach.c: 202 (query_exported_devices) recv op_common
usbip err: vhci_attach.c: 417 (show_exported_devices) query
$ usbip -v

** (process:30826): WARNING **: running non-root?
usbip 0.1.7 ($Id: vhci_attach.c 42 2007-09-07 12:07:51Z hirofuchi $)

Installing usbip v2.0 from source

Get current kernel sources

$ apt-get source linux-image-$(uname -r)
 Reading package lists... Done
 Building dependency tree
 Reading state information... Done
 Picking 'linux' as source package instead of 'linux-image-4.2.0-21-generic'
 NOTICE: 'linux' packaging is maintained in the 'Git' version control system at:
 git://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/wily
 Need to get 137 MB of source archives.
 Get:1 http://archive.ubuntu.com/ubuntu/ wily-updates/main linux 4.2.0-27.32 (dsc) [9 481 B]
 Get:2 http://archive.ubuntu.com/ubuntu/ wily-updates/main linux 4.2.0-27.32 (tar) [130 MB]
 Get:3 http://archive.ubuntu.com/ubuntu/ wily-updates/main linux 4.2.0-27.32 (diff) [6 741 kB]
 Fetched 137 MB in 8min 57s (255 kB/s)
 gpgv: Signature made Pi 22. január 2016, 05:44:57 CET using RSA key ID 105BE7F7
 gpgv: Can't check signature: public key not found
 dpkg-source: warning: failed to verify signature on ./linux_4.2.0-27.32.dsc
 dpkg-source: info: extracting linux in linux-4.2.0
 dpkg-source: info: unpacking linux_4.2.0.orig.tar.gz
 dpkg-source: info: applying linux_4.2.0-27.32.diff.gz
 dpkg-source: info: upstream files that have been modified:
 linux-4.2.0/Documentation/ABI/testing/configfs-usb-gadget-loopback
 ....
 linux-4.2.0/virt/kvm/kvm_main.c

CD to directory with usbip sources

 $ cd linux-4.2.0/tools/usb/usbip/
 /linux-4.2.0/tools/usb/usbip$ ls
 AUTHORS     cleanup.sh    COPYING  INSTALL  Makefile.am  src
 autogen.sh  configure.ac  doc      libsrc   README

Run autogen (or not)

It will fail because you need to run libtoolize first but let’s see:

 /linux-4.2.0/tools/usb/usbip$ ./autogen.sh
 + autoreconf -i -f -v
 autoreconf: Entering directory `.'
 autoreconf: configure.ac: not using Gettext
 autoreconf: running: aclocal --force
 autoreconf: configure.ac: tracing
 autoreconf: configure.ac: not using Libtool
 autoreconf: running: /usr/bin/autoconf --force
 autoreconf: running: /usr/bin/autoheader --force
 autoreconf: running: automake --add-missing --copy --force-missing
 configure.ac:24: installing './compile'
 configure.ac:15: installing './install-sh'
 configure.ac:15: installing './missing'
 libsrc/Makefile.am:5: error: Libtool library used but 'LIBTOOL' is undefined
 libsrc/Makefile.am:5:   The usual way to define 'LIBTOOL' is to add 'LT_INIT'
 libsrc/Makefile.am:5:   to 'configure.ac' and run 'aclocal' and 'autoconf' again.
 libsrc/Makefile.am:5:   If 'LT_INIT' is in 'configure.ac', make sure
 libsrc/Makefile.am:5:   its definition is in aclocal's search path.
 libsrc/Makefile.am: installing './depcomp'
 autoreconf: automake failed with exit status: 1

Run libtoolize

/linux-4.2.0/tools/usb/usbip$ libtoolize
 libtoolize: putting auxiliary files in `.'.
 libtoolize: linking file `./ltmain.sh'
 libtoolize: You should add the contents of the following files to `aclocal.m4':
 libtoolize:   `/usr/share/aclocal/libtool.m4'
 libtoolize:   `/usr/share/aclocal/ltoptions.m4'
 libtoolize:   `/usr/share/aclocal/ltversion.m4'
 libtoolize:   `/usr/share/aclocal/ltsugar.m4'
 libtoolize:   `/usr/share/aclocal/lt~obsolete.m4'
 libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
 libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
 libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.

Run autogen again

/linux-4.2.0/tools/usb/usbip$ ./autogen.sh
 + autoreconf -i -f -v
 autoreconf: Entering directory `.'
 autoreconf: configure.ac: not using Gettext
 autoreconf: running: aclocal --force
 autoreconf: configure.ac: tracing
 autoreconf: running: libtoolize --copy --force
 libtoolize: putting auxiliary files in `.'.
 libtoolize: copying file `./ltmain.sh'
 libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
 libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
 libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
 autoreconf: running: /usr/bin/autoconf --force
 autoreconf: running: /usr/bin/autoheader --force
 autoreconf: running: automake --add-missing --copy --force-missing
 configure.ac:16: installing './config.guess'
 configure.ac:16: installing './config.sub'
 autoreconf: Leaving directory `.'

Configure

 /linux-4.2.0/tools/usb/usbip$ ./configure
 checking for a BSD-compatible install... /usr/bin/install -c
 checking whether build environment is sane... yes
 checking for a thread-safe mkdir -p... /bin/mkdir -p
 checking for gawk... gawk
 checking whether make sets $(MAKE)... yes
 checking whether make supports nested variables... yes
 checking build system type... x86_64-unknown-linux-gnu
 checking host system type... x86_64-unknown-linux-gnu
 checking how to print strings... printf
 checking for style of include used by make... GNU
 checking for gcc... gcc
 checking whether the C compiler works... yes
 checking for C compiler default output file name... a.out
 checking for suffix of executables...
 checking whether we are cross compiling... no
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether gcc accepts -g... yes
 checking for gcc option to accept ISO C89... none needed
 checking whether gcc understands -c and -o together... yes
 checking dependency style of gcc... gcc3
 checking for a sed that does not truncate output... /bin/sed
 checking for grep that handles long lines and -e... /bin/grep
 checking for egrep... /bin/grep -E
 checking for fgrep... /bin/grep -F
 checking for ld used by gcc... /usr/bin/ld
 checking if the linker (/usr/bin/ld) is GNU ld... yes
 checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
 checking the name lister (/usr/bin/nm -B) interface... BSD nm
 checking whether ln -s works... yes
 checking the maximum length of command line arguments... 1572864
 checking whether the shell understands some XSI constructs... yes
 checking whether the shell understands "+="... yes
 checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
 checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
 checking for /usr/bin/ld option to reload object files... -r
 checking for objdump... objdump
 checking how to recognize dependent libraries... pass_all
 checking for dlltool... no
 checking how to associate runtime and link libraries... printf %s\n
 checking for ar... ar
 checking for archiver @FILE support... @
 checking for strip... strip
 checking for ranlib... ranlib
 checking command to parse /usr/bin/nm -B output from gcc object... ok
 checking for sysroot... no
 checking for mt... mt
 checking if mt is a manifest tool... no
 checking how to run the C preprocessor... gcc -E
 checking for ANSI C header files... yes
 checking for sys/types.h... yes
 checking for sys/stat.h... yes
 checking for stdlib.h... yes
 checking for string.h... yes
 checking for memory.h... yes
 checking for strings.h... yes
 checking for inttypes.h... yes
 checking for stdint.h... yes
 checking for unistd.h... yes
 checking for dlfcn.h... yes
 checking for objdir... .libs
 checking if gcc supports -fno-rtti -fno-exceptions... no
 checking for gcc option to produce PIC... -fPIC -DPIC
 checking if gcc PIC flag -fPIC -DPIC works... yes
 checking if gcc static flag -static works... yes
 checking if gcc supports -c -o file.o... yes
 checking if gcc supports -c -o file.o... (cached) yes
 checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
 checking whether -lc should be explicitly linked in... no
 checking dynamic linker characteristics... GNU/Linux ld.so
 checking how to hardcode library paths into programs... immediate
 checking whether stripping libraries is possible... yes
 checking if libtool supports shared libraries... yes
 checking whether to build shared libraries... yes
 checking whether to build static libraries... yes
 checking whether make supports nested variables... (cached) yes
 checking for gcc... (cached) gcc
 checking whether we are using the GNU C compiler... (cached) yes
 checking whether gcc accepts -g... (cached) yes
 checking for gcc option to accept ISO C89... (cached) none needed
 checking whether gcc understands -c and -o together... (cached) yes
 checking dependency style of gcc... (cached) gcc3
 checking whether make sets $(MAKE)... (cached) yes
 checking for dirent.h that defines DIR... yes
 checking for library containing opendir... none required
 checking for ANSI C header files... (cached) yes
 checking arpa/inet.h usability... yes
 checking arpa/inet.h presence... yes
 checking for arpa/inet.h... yes
 checking fcntl.h usability... yes
 checking fcntl.h presence... yes
 checking for fcntl.h... yes
 checking netdb.h usability... yes
 checking netdb.h presence... yes
 checking for netdb.h... yes
 checking netinet/in.h usability... yes
 checking netinet/in.h presence... yes
 checking for netinet/in.h... yes
 checking for stdint.h... (cached) yes
 checking for stdlib.h... (cached) yes
 checking for string.h... (cached) yes
 checking sys/socket.h usability... yes
 checking sys/socket.h presence... yes
 checking for sys/socket.h... yes
 checking syslog.h usability... yes
 checking syslog.h presence... yes
 checking for syslog.h... yes
 checking for unistd.h... (cached) yes
 checking for int32_t... yes
 checking for size_t... yes
 checking for ssize_t... yes
 checking for uint16_t... yes
 checking for uint32_t... yes
 checking for uint8_t... yes
 checking for stdlib.h... (cached) yes
 checking for GNU libc compatible realloc... yes
 checking for memset... yes
 checking for mkdir... yes
 checking for regcomp... yes
 checking for socket... yes
 checking for strchr... yes
 checking for strerror... yes
 checking for strstr... yes
 checking for strtoul... yes
 checking libudev.h usability... yes
 checking libudev.h presence... yes
 checking for libudev.h... yes
 checking for udev_new in -ludev... yes
 checking whether to use the libwrap (TCP wrappers) library... (default)
 checking for hosts_access in -lwrap... no
 checking whether to use fortify... default
 checking that generated files are newer than configure... done
 configure: creating ./config.status
 config.status: creating Makefile
 config.status: creating libsrc/Makefile
 config.status: creating src/Makefile
 config.status: creating config.h
 config.status: executing depfiles commands
 config.status: executing libtool commands

Make

/linux-4.2.0/tools/usb/usbip$ make
 make  all-recursive
 make[1]: Entering directory '/home/danman/linux-4.2.0/tools/usb/usbip'
 Making all in libsrc
 make[2]: Entering directory '/home/danman/linux-4.2.0/tools/usb/usbip/libsrc'
 CC       libusbip_la-names.lo
 CC       libusbip_la-usbip_host_driver.lo
 CC       libusbip_la-usbip_common.lo
 CC       libusbip_la-vhci_driver.lo
 CC       libusbip_la-sysfs_utils.lo
 CCLD     libusbip.la
 ar: `u' modifier ignored since `D' is the default (see `U')
 make[2]: Leaving directory '/home/danman/linux-4.2.0/tools/usb/usbip/libsrc'
 Making all in src
 make[2]: Entering directory '/home/danman/linux-4.2.0/tools/usb/usbip/src'
 CC       usbip.o
 CC       utils.o
 CC       usbip_network.o
 CC       usbip_attach.o
 CC       usbip_detach.o
 CC       usbip_list.o
 CC       usbip_bind.o
 CC       usbip_unbind.o
 CC       usbip_port.o
 CCLD     usbip
 CC       usbipd.o
 CCLD     usbipd
 make[2]: Leaving directory '/home/danman/linux-4.2.0/tools/usb/usbip/src'
 make[2]: Entering directory '/home/danman/linux-4.2.0/tools/usb/usbip'
 make[2]: Leaving directory '/home/danman/linux-4.2.0/tools/usb/usbip'
 make[1]: Leaving directory '/home/danman/linux-4.2.0/tools/usb/usbip'

CD to src and try to run usbip

 /linux-4.2.0/tools/usb/usbip$ cd src/
 /linux-4.2.0/tools/usb/usbip/src$ ./usbip
 usage: usbip [--debug] [--log] [--tcp-port PORT] [version]
 [help] <command> <args>
 attach     Attach a remote USB device
 detach     Detach a remote USB device
 list       List exportable or local USB devices
 bind       Bind device to usbip-host.ko
 unbind     Unbind device from usbip-host.ko
 port       Show imported USB devices
 /linux-4.2.0/tools/usb/usbip/src$ ./usbip version
 usbip (usbip-utils 2.0)

Try to connect to running usbip server (e.g. on your RPI)

/linux-4.2.0/tools/usb/usbip/src$ ./usbip list -r 192.168.1.83
 Exportable USB devices
 ======================
 - 192.168.1.83
 1-1.3: Chicony Electronics Co., Ltd : KU-9908 Keyboard (04f2:0111)
 : /sys/devices/platform/soc/20980000.usb/usb1/1-1/1-1.3
 : (Defined at Interface level) (00/00/00)

Try to attach remote device

/linux-4.2.0/tools/usb/usbip/src$ ./usbip attach -r 192.168.201.83 -b 1-1.3
 libusbip: error: udev_device_new_from_subsystem_sysname failed
 usbip: error: open vhci_driver
 usbip: error: query

Oh, we forgot to install module vhci-hcd.

Modprobe vhci-hcd

/linux-4.2.0/tools/usb/usbip/src$ sudo modprobe vhci-hcd

Try to attach again

/linux-4.2.0/tools/usb/usbip/src$ ./usbip attach -r 192.168.201.83 -b 1-1.3
 usbip: error: import device
 usbip: error: query

Ah! Try to attach with sudo again

/linux-4.2.0/tools/usb/usbip/src$ sudo ./usbip attach -r 192.168.201.83 -b 1-1.3

Now you should be able to see and use the remote USB device

/linux-4.2.0/tools/usb/usbip/src$ lsusb
 Bus 005 Device 004: ID 04f2:0111 Chicony Electronics Co., Ltd KU-9908 Keyboard

Finally, you can apt-get remove usbip and make install if you like.

6 thoughts on “usbip-utils 2.0 on Ubuntu”

  1. thank you for the post
    I have a problem, when i wrote “” sudo ./usbip attach -r 192.168.1.13 -b 1-1.3 “”
    the following error appears:
    libusbip: error: udev_device_get_sysattr_value failed
    usbip: error: open vhci_driver
    usbip: error: query

    even after wrote the following “” sudo modprobe vhci-hcd “”
    the same error still appears.

    What should i do ?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.