In a world were virtualization is slowly creeping in everywhere the demand for virtual USB cables are growing, luckily the USBIP protocol are implemented in the Linux kernel – and the userland tools are partly implemented in Debian, at least enough for us to mount it manually. If you want to automate it I made another post for that.
On both client and server:
Install the package:
root@system:~# apt-get install usbip
Load the main module and make it persistent:
root@system:~# modprobe usbip_core
root@system:~# echo usbip_core >> /etc/modules
Setting up the server:
The server needs an aditional kernel module:
root@server:~# modprobe usbip_host
root@server:~# echo usbip_host >> /etc/modules
Now you can share the usb device, I plugged in a USB stick into my server:
root@server:~# usbip list -l
- busid 3-3 (054c:05b9)
Sony Corp. : unknown product (054c:05b9)
This server only have one usb device attached making the output pretty simple, in this case the busid is “3-3”, but on your system it may have a different format depending on your hardware.
Bind this device to usbip:
root@server:~# usbip bind --busid=3-3
usbip: info: bind device on busid 3-3: complete
And finally start the deamon:
root@server:~# usbipd
usbipd: info: starting usbipd (usbip-utils 2.0)
usbipd: info: listening on 0.0.0.0:3240
usbipd: info: listening on :::3240
This is still a very manual process, later I will create an additional post with an example on how to automate this on Debian 12.
Setting up the client
The client also need a module:
root@client:~# modprobe vhci-hcd
root@client:~# echo vhci-hcd >> /etc/modules
And now you can connect to the remote server and list available devices:
root@client:~# usbip list -r server
Exportable USB devices
======================
- backup1
3-3: Sony Corp. : unknown product (054c:05b9)
: /sys/devices/pci0000:00/0000:00:10.0/usb3/3-3
: (Defined at Interface level) (00/00/00)
… and attach it:
root@client:~# usbip attach -r server -b 3-3
Which will cause it pop up in dmesg:
root@client:~# dmesg | tail -n10
[3425534.758312] usb-storage 5-1:1.0: USB Mass Storage device detected
[3425534.758672] scsi host9: usb-storage 5-1:1.0
[3425535.790312] scsi 9:0:0:0: Direct-Access Sony Storage Media PMAP PQ: 0 ANSI: 6
[3425535.790979] sd 9:0:0:0: Attached scsi generic sg5 type 0
[3425535.792699] sd 9:0:0:0: [sde] 30375936 512-byte logical blocks: (15.6 GB/14.5 GiB)
[3425535.793509] sd 9:0:0:0: [sde] Write Protect is off
[3425535.793521] sd 9:0:0:0: [sde] Mode Sense: 45 00 00 00
[3425535.794265] sd 9:0:0:0: [sde] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[3425535.801659] sde:
[3425535.801757] sd 9:0:0:0: [sde] Attached SCSI removable disk
Now you can mount the device:
root@client:~# mount /dev/sde /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.
root@backup2:~# ls /mnt
boot client_install EFI EULA install.img LICENSES Packages repodata RPM-GPG-KEY-CH-8 RPM-GPG-KEY-CH-8-LCM RPM-GPG-KEY-Platform-V1
And now your Debian Install USB stick from “server” is mounted on “client”, I have not yet done any kind of methodical testing so I don’t really know how the performance is, but right now I was more concerned with getting it to work, than what kind of performance it would deliver, it is probably “good enough” for anything except for maybe high latency gaming and huge data transfers.
But I still made a quick benchmark using:
root@system:~# hdparm -t /dev/sde
On both systems where i got around 200MB/sec on the local system and 85MB/sec on the remote client. But my current use-case is to connect printers and scanners, and the occasional USB Stick to transfer small amounts of files.
For any kind of serious ingestion of video materials I would not recommend this solution.
Detaching USB Device
root@client:~# umount /mnt
root@client:~# usbip port
Imported USB devices
====================
Port 15: <Port in Use> at Super Speed(5000Mbps)
Sony Corp. : unknown product (054c:05b9)
5-1 -> usbip://backup1:3240/3-3
-> remote bus/dev 003/002
root@client:~# usbip detach -p 15
usbip: info: Port 15 is now detached!
Next task is to automate this.