Linux Magazine #1 2023: Deel je USB-apparaten over het netwerk met USB/IP
- March 14, 2023
- 0
Kernmodule van usbip automatisch laden:
server $ echo 'usbip-host' | sudo tee /etc/modules-load.d/usbip.conf
Via de client opvragen welke apparaten de server deelt
client $ usbip list --remote=192.168.0.237 Exportable USB devices ====================== - usbip.local 1-1.1: Realtek Semiconductor Corp. : RTL2838 DVB-T (0bda:2838) : /sys/devices/platform/soc/20980000.usb/usb1/1-1/1-1.1 : (Defined at Interface level) (00/00/00)
Opvragen welke door usbip gedeelde apparaten lokaal in gebruik zijn
client $ sudo usbip port Imported USB devices ==================== Port 00: at High Speed(480Mbps) Realtek Semiconductor Corp. : RTL2838 DVB-T (0bda:2838) 3-1 -> usbip://192.168.0.237:3240/1-1.1 -> remote bus/dev 001/003
Stoppen met een apparaat delen
server $ sudo usbip unbind --busid=1-1.1 usbip: info: unbind device on busid 1-1.1: complete
Systemd-service in /etc/systemd/system/usbipd.service
[Unit] Description=USB/IP server After=network-online.target [Service] ExecStart=/usr/sbin/usbipd [Install] WantedBy=multi-user.target
systemd-script in /etc/systemd/system/usbip-bind@.service
[Unit] Description=USB-IP binding to device on bus id %I After=network-online.target usbipd.service Wants=network-online.target Requires=usbipd.service [Service] Type=simple ExecStart=/usr/sbin/usbip bind -b %i RemainAfterExit=yes ExecStop=/usr/sbin/usbip unbind -b %i Restart=on-failure [Install] WantedBy=multi-user.target
Aanpassen ExecStart en ExecStop
ExecStart=/bin/sh -c "/usr/sbin/usbip bind --$(/usr/sbin/usbip list -p -l | grep '#usbid=%i#' | cut '-d#' -f1)" ExecStop=/bin/sh -c "/usr/sbin/usbip unbind --$(/usr/sbin/usbip list -p -l | grep '#usbid=%i#' | cut '-d#' -f1)"
Script in /etc/systemd/system/usbip-client@.service
[Unit] Description=USB/IP client After=network-online.target [Service] Type=oneshot RemainAfterExit=yes ExecStart=/bin/sh -c "/usr/bin/usbip attach -r 192.168.0.237 -b $(/usr/bin/usbip list -r 192.168.0.237 | grep '%i' | cut -d: -f1)" ExecStop=/bin/sh -c "/usr/bin/usbip detach --port=$(/usr/bin/usbip port | grep '' | sed -E 's/^Port ([0-9][0-9]).*/\1/')" [Install] WantedBy=multi-user.target