Skip to content

Instantly share code, notes, and snippets.

@surajRathi
Created November 27, 2022 16:53
Show Gist options
  • Select an option

  • Save surajRathi/275fe3f0fb2816dda91219be3bd93489 to your computer and use it in GitHub Desktop.

Select an option

Save surajRathi/275fe3f0fb2816dda91219be3bd93489 to your computer and use it in GitHub Desktop.

From the USB/IP site:

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. Goes without saying, make sure host and client are on the same network.

Host Setup
  • Install usbip package
sudo apt install linux-tools-generic linux-tools-$(uname -r)
  • Load kernel modules
sudo modprobe usbip-core
sudo modprobe usbip-host
  • Start server
sudo usbipd

By starting the server like this, you will be able to see what it is doing. Your computer will display the machines that try to connect and show whether they are successful. This will help you troubleshoot during the first few runs. Once you are confident everything works as it should, you may want to run the server with the -D flag alternative to interactive shell.

sudo usbipd -D
  • List devices

Run this command before and after connecting the device and find the bus-id of the device.

usbip list -l

Example:

$ usbip list -l
- busid 1-1 (0474:025f)
  Sanyo Electric Co., Ltd : unknown product (0474:025f)
- busid 1-2 (04f9:01eb)
  Brother Industries, Ltd : MFC-7320 (04f9:01eb)
- busid 1-4 (8087:0a2a)
  Intel Corp. : unknown product (8087:0a2a)
  • Bind with device
sudo usbip bind -b <bus-id>

Example:

sudo usbip bind -b 1-1
Client Setup
  • Install usbip package
sudo apt install linux-tools-generic linux-tools-$(uname -r)
  • Load Kernel modules
sudo modprobe usbip-core
sudo modprobe vhci-hcd
  • Query host and list available devices
subo usbip list -r <server-ip>

Example:

$ sudo usbip list -r 10.42.234.182
Exportable USB devices
======================
 - 10.42.234.182
        1-3: unknown vendor : unknown product (046d:0825)
           : /sys/devices/pci0000:00/0000:00:14.0/usb1/1-3
           : unknown class / unknown subclass / unknown protocol (ef/02/01)
Detaching from Client
To detach a device, first you need to know to which virtual port each device is attached.
  • List connected ports
sudo usbip port

Example:

$ sudo usbip port
Imported USB devices
====================
Port 00: <Port in Use> at High Speed(480Mbps)
  unknown vendor : unknown product (0474:025f)
  8-1 -> usbip://192.168.1.24:3240/1-1
    -> remote bus/dev 001/002
Port 01: <Port in Use> at Full Speed(12Mbps)
  unknown vendor : unknown product (04f9:01eb)
  8-2 -> usbip://192.168.1.24:3240/1-2
    -> remote bus/dev 001/004

Armed with the port number, you can detach a device with:

sudo usbip detach -p <port-number>

Example:

sudo usbip detach -p 00
Detaching from Host
To stop sharing a device, you should use the unbind command. The command:
sudo usbip unbind -b <bus-id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment