How To Share USB Devices Over IP Using A Raspberry Pi
In the video below, we show you how to configure a Raspberry Pi for USB over IP and how to configure a Linux computer to access its USB devices over the network
If you want to share a USB device over IP, then you can do this for free using a Raspberry Pi
Although, only one Linux computer can use a USB device at a time
This could be used to allow you to configure a VM for instance to access a USB device over the network without tying it to a specific hypervisor so that you can migrate the VM more easily
It allows you to share USB devices from a central location so that you don’t have to be physically present to transfer them between computers
It also provides an option to place USB devices such as radio controllers in areas where they can get better wireless coverage, but access them from a server in a rack for instance
Useful links:
https://derushadigital.com/other%20projects/2019/02/19/RPi-USBIP-ZWave.html
https://wiki.archlinux.org/title/USB/IP
Hardware Suggestions:
GeekPi Raspberry Pi 4 4GB
-
Raspberry Pi:
Switch to root accountInstall softwaresu -
List USB devices and note down the product/vendorapt install usbip modprobe usbip_host echo 'usbip_host' >> /etc/modules
Create start scriptusbip list -l
nano /usr/sbin/usbip_start.sh
Make this executable#!/bin/bash usb1='0781:5567' usb2='0658:0200' /usr/sbin/usbip bind --$(/usr/sbin/usbip list -p -l | grep '#usbid='$usb1'#' | cut '-d#' -f1) /usr/sbin/usbip bind --$(/usr/sbin/usbip list -p -l | grep '#usbid='$usb2'#' | cut '-d#' -f1)
Create stop scriptchmod +x /usr/sbin/usbip_start.sh
nano /usr/sbin/usbip_stop.sh
Make this executable#!/bin/bash usb1='0781:5567' usb2='0658:0200' /usr/sbin/usbip unbind --$(/usr/sbin/usbip list -p -l | grep '#usbid='$usb1'#' | cut '-d#' -f1) /usr/sbin/usbip unbind --$(/usr/sbin/usbip list -p -l | grep '#usbid='$usb2'#' | cut '-d#' -f1) killall usbipd
Create servicechmod +x /usr/sbin/usbip_stop.sh
nano /lib/systemd/system/usbipd.service
Start the service[Unit] Description=usbip host daemon After=network.target [Service] Type=forking ExecStart=/usr/sbin/usbipd -D ExecStartPost=/bin/bash -c '/usr/sbin/usbip_start.sh' ExecStop=/bin/bash -c '/usr/sbin/usbip_stop.sh' [Install] WantedBy=multi-user.target
Check what USB devices are foundsystemctl --system daemon-reload systemctl enable usbipd.service systemctl start usbipd.service
usbip list -p -l
-
Linux Client
Switch to root accountCheck USB devices attachedsu -
Install software and create a servicelsusb
Create start scriptapt install usbip hwdata usbutils -y modprobe vhci-hcd echo 'vhci-hcd' >> /etc/modules
nano /usr/sbin/usbip_start.sh
Make this executable#!/bin/bash server1='192.168.200.7' usb1='0781:5567' usb2='0658:0200' /usr/sbin/usbip attach -r $server1 -b $(/usr/sbin/usbip list -r $server1 | grep $usb1 | cut -d: -f1) /usr/sbin/usbip attach -r $server1 -b $(/usr/sbin/usbip list -r $server1 | grep $usb2 | cut -d: -f1)
Create stop scriptchmod +x /usr/sbin/usbip_start.sh
nano /usr/sbin/usbip_stop.sh
Make this executable#!/bin/bash /usr/sbin/usbip detach --port=$(/usr/sbin/usbip port | grep '<Port in Use>' | sed -E 's/^Port ([0-9][0-9]).*/\1/') /usr/sbin/usbip detach --port=$(/usr/sbin/usbip port | grep '<Port in Use>' | sed -E 's/^Port ([0-9][0-9]).*/\1/')
Create servicechmod +x /usr/sbin/usbip_stop.sh
nano /lib/systemd/system/usbip.service
Start the service[Unit] Description=usbip client After=network.target [Service] Type=oneshot RemainAfterExit=yes ExecStartPost=/bin/bash -c '/usr/sbin/usbip_start.sh' ExecStop=/bin/bash -c '/usr/sbin/usbip_stop.sh' [Install] WantedBy=multi-user.target
Check USB device is attachedsystemctl --system daemon-reload systemctl enable usbip.service systemctl start usbip.service
usbip port lsusb
Sharing is caring!