UP | HOME
Sachin Patil

Sachin Patil

Free Software Developer | GNU Emacs Hacker

[Notes] USB device sharing over IP
Published on Sep 13, 2020 by Sachin.

Introduction

Since its introduction in the Linux kernel in v3.17, I’m not sure why this feature is not so popular(or is it only me who was not aware of it until now). Anyways, I decided to test the USB device sharing over IP. This feature will share the USB devices which are attached to a remote system over the network as if the device is locally attached to the system. To test this functionality, I’ve attached my 2TB Seagate drive to the Raspberry Pi(Server) and I want it available on my Fedora system(Client) as if the drive is locally attached.

Here’s the output of the lsusb command,

1: Bus 001 Device 004: ID 0bc2:ab21 Seagate RSS LLC Backup Plus Slim
2: Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
3: Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
4: Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

layout.png

Figure 1: Layout.

Server

On the server side, update the kernel version to 3.17 or later, install usbip package and enable the usbip-core and usbip-host kernel modules.

1: sudo apt-get install usbip
2: sudo modprobe usbip-core
3: sudo modprobe usbip-host

Or add the modules in /etc/module if you want the modules to be available after reboot.

1: cat /etc/modules
2: # /etc/modules: kernel modules to load at boot time.
3: #
4: # This file contains the names of kernel modules that should be loaded
5: # at boot time, one per line. Lines beginning with "#" are ignored.
6: 
7: usbip_core
8: usbip_host

Start the USBIP Daemon process,

1: sudo usbipd -D --debug

Create a systemd service(Optional)

File: /lib/systemd/system/usbipd.service

 1: [Unit]
 2: Description=usbip host daemon
 3: After=network.target
 4: 
 5: [Service]
 6: Type=forking
 7: ExecStart=/usr/sbin/usbipd -D --debug
 8: 
 9: [Install]
10: WantedBy=multi-user.target

Enable & start the service,

 1: sudo systemctl enable usbipd
 2: Created symlink /etc/systemd/system/multi-user.target.wants/usbipd.service → /lib/systemd/system/usbipd.service.
 3: 
 4: sudo systemctl start usbipd
 5: sudo systemctl status usbipd
 6: ● usbipd.service - usbip host daemon
 7:    Loaded: loaded (/lib/systemd/system/usbipd.service; disabled; vendor preset: enabled)
 8:    Active: active (running) since Sun 2020-09-06 20:35:01 IST; 1s ago
 9:   Process: 1237 ExecStart=/usr/sbin/usbipd -D --debug (code=exited, status=0/SUCCESS)
10:  Main PID: 1238 (usbipd)
11:     Tasks: 1 (limit: 1942)
12:    CGroup: /system.slice/usbipd.service
13:            └─1238 /usr/sbin/usbipd -D --debug
14: 
15: Sep 06 20:35:01 raspberrypi systemd[1]: Starting usbip host daemon...
16: Sep 06 20:35:01 raspberrypi usbipd[1238]: usbipd: info: starting usbipd (usbip-utils 2.0)
17: Sep 06 20:35:01 raspberrypi usbipd[1238]: usbipd: info: listening on 0.0.0.0:3240
18: Sep 06 20:35:01 raspberrypi systemd[1]: Started usbip host daemon.
19: Sep 06 20:35:01 raspberrypi usbipd[1238]: usbipd: info: listening on :::3240

Now list all the available devices using,

sudo usbip list -l
 - busid 1-1.1 (0424:ec00)
   Standard Microsystems Corp. : SMSC9512/9514 Fast Ethernet Adapter (0424:ec00)

 - busid 1-1.2 (0bc2:ab21)
   Seagate RSS LLC : Backup Plus Slim (0bc2:ab21)

Finally bind the USB device you want to share over the network,

1: # Syntax: usbip bind <BUS_ID>
2: sudo usbip bind -b 1-1.2
3: usbip: info: bind device on busid 1-1.2: complete

You can unbind using: usbip unbind <BUSID>.

The following are the logs from the server,

 1: [63476.847596] sd 0:0:0:0: [sda] Synchronizing SCSI cache
 2: [63647.986250] usbip-host 1-1.2: 1-1.2 is not in match_busid table... skip!
 3: [63647.986370] usbcore: registered new device driver usbip-host
 4: [63655.533552] usbip-host 1-1.2: usbip-host: register new device (bus 1 dev 4)
 5: [64026.471984] usbip-host 1-1.2: stub up
 6: [64026.474776] usbip-host 1-1.2: recv a header, 0
 7: [64026.573752] usbip-host 1-1.2: reset high-speed USB device number 4 using dwc_otg
 8: [64026.705758] usbip-host 1-1.2: device reset
 9: [64038.086388] usbip-host 1-1.2: stub up
10: [64038.342024] usbip-host 1-1.2: usb_set_interface done: inf 0 alt 1

Client

On the client, also install usbip and enable usbip-core and vhci-hcd kernel modules.

1: sudo dnf install usbip
2: sudo modprobe usbip-core
3: sudo modprobe vhci-hcd

List the devices offered by the the server(Raspberry Pi in my case),

1: usbip list --remote=192.168.0.162
2: Exportable USB devices
3: ======================
4:  - 192.168.0.162
5:       1-1.2: Seagate RSS LLC : Backup Plus Slim (0bc2:ab21)
6:            : /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2
7:            : (Defined at Interface level) (00/00/00)

Attach the device,

 1: # Syntax: usbip attach --remote/-r <SERVER_IP_ADDRESS> -b <BUS_ID>
 2: sudo usbip attach -r 192.168.0.162 -b 1-1.2
 3: 
 4: lsusb
 5: # Output
 6: Bus 006 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
 7: Bus 005 Device 003: ID 0bc2:ab21 Seagate RSS LLC Backup Plus Slim
 8: Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 9: Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
10: Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
11: Bus 002 Device 029: ID 17ef:3082 Lenovo USB3.1 Hub
12: Bus 002 Device 028: ID 17ef:307f Lenovo
13: Bus 002 Device 027: ID 17ef:307f Lenovo USB3.1 Hub
14: Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
15: Bus 001 Device 002: ID 13d3:56bc IMC Networks Integrated Camera
16: Bus 001 Device 095: ID 046d:c534 Logitech, Inc. Unifying Receiver
17: Bus 001 Device 092: ID 2109:8818 VIA Labs, Inc.
18: Bus 001 Device 089: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
19: Bus 001 Device 094: ID 2109:8818 VIA Labs, Inc.
20: Bus 001 Device 093: ID 17ef:3083 Lenovo USB2.0 Hub
21: Bus 001 Device 090: ID 17ef:3081 Lenovo
22: Bus 001 Device 088: ID 17ef:3080 Lenovo
23: Bus 001 Device 087: ID 17ef:3080 Lenovo USB2.0 Hub
24: Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

file_manager.png

Figure 2: Notice the Seagate Drive available in the Gnome File Manager.

Use the device’s port number to detach the device,

1: sudo usbip port
2: Imported USB devices
3: ====================
4: Port 00: <Port in Use> at High Speed(480Mbps)
5:        Seagate RSS LLC : Backup Plus Slim (0bc2:ab21)
6:        5-1 -> usbip://192.168.0.162:3240/1-1.2
7:            -> remote bus/dev 001/004

Detach

1: # Syntax: usbip detach --port/-p <PORT_NUMBER>
2: sudo usbip detach -p 00
3: usbip: info: Port 0 is now detached!