- auto-export on host when a defined usb-device has been plugged
- auto-attachment on client when a disappeared remote-device is available, again.
README.md
usbip-export@.service
usbip-attach@.service
- usbip
- lsusb (pre-installed on most distributions)
install the systemd-files as root.
usb-host:
install -m 644 -o root -g root -t /lib/systemd/system/ /your/filepath/usbip-export@.service
usb-client:
install -m 644 -o root -g root -t /lib/systemd/system/ /your/filepath/usbip-attach@.service
execute on both sides:
systemctl daemon-reload
To export a pysical usb-device you have to determine the vendor and product id of your device with
lsusb
the format is [idVendor]:[idProduct] like: 301b:56f1
Now, you're able to export/provide your usb-device.
Syntax:
usbip-export@[idVendor]:[idProduct].service e.g:
systemctl start usbip-export@301b:56f1
At last, you're able to attach the usb-device from the remote IP on a client.
Syntax:
usbip-attach@.service@[host]_[idVendor]:[idProduct].service e.g.:
systemctl start usbip-attach@192.168.0.10_301b:56f1
usbip-export human readable relevant code parts:
starting:
# bind
dev=%i
statePrev=1
state=$(/usr/bin/lsusb|grep -q $dev; echo $?)
while true; do
if [ $state -ne $statePrev ]; then
/usr/sbin/usbip bind --busid=$(/usr/sbin/usbip list -p -l | grep "$dev" | cut '-d#' -f1 | cut '-d=' -f2 | tr -d '[:space:]')
fi
sleep 1
statePrev=$state
state=$(/usr/bin/lsusb|grep -q $dev; echo $?)
done
stopping:
# unbind
/usr/sbin/usbip unbind --busid=$(/usr/sbin/usbip list -p -l | grep "%i" | cut '-d#' -f1 | cut '-d=' -f2 | tr -d '[:space:]')
killall usbipd
usbip-attach human readable relevant code parts:
starting:
# attach
host=$(echo %i|cut '-d_' -f1|tr -d '[:space:]')
dev=$(echo %i|cut '-d_' -f2|tr -d '[:space:]')
while true; do
/usr/bin/lsusb | grep -q $dev
if [ $? -ne 0 ]; then
busid=$(/usr/sbin/usbip list -p -r $host | grep $dev | cut '-d:' -f1 | xargs echo -n)
/usr/sbin/usbip port|grep -q $dev
if [ $? -ne 0 ]; then
/usr/sbin//usr/sbin/usbip attach --remote=$host --busid=$busid
fi
fi
sleep 1
done
stopping:
# detach
dev=$(echo %i|cut '-d_' -f2|tr -d '[:space:]')
/usr/sbin/usbip port | while read i; do
echo $i | grep -q $dev
if [ $? -eq 0 ]; then
/usr/sbin/usbip detach --port=$port
fi
echo $i | grep -q Port
if [ $? -eq 0 ]; then
port=$(echo $i | cut '-d ' -f2 | cut '-d:' -f1 | tr -d '[:space:]')
fi
done
Tags: usb
usbip
tcp
teleport
gateway
ip
network
systemd
service
remote
deploy
export
Certainly, depending on your distri, kernel modules might be not loaded automatically by installation.
Refer your distribution how to load additional modules on boot.
Ubuntu and most other distries are using entries in /etc/modues