usbip client

michalrentka

Cadet
Joined
Jul 20, 2022
Messages
7
Is it possible to have usbip client running on TrueNAS Scale? I have an app which needs some hardware to be physically connected over USB but my server running TrueNAS is in different room. Would it be possible to connect them through usbip?
 

SitelabsNL

Cadet
Joined
Aug 22, 2022
Messages
2
Did you manage to get usbip to work? I got as far as "modprobe vhci-hcd" but usbip command remains not found. I have exactly the same use-case.
 

Beerden

Cadet
Joined
Jun 14, 2022
Messages
1
I am using usbip on TrueNAS-SCALE-22.12.3.3 (Bluefin [release]) to make a remote USB device available to a virtual machine - in my case, SkyConnect for Home Assistant in a VM running HA OS which does not have usbip installed.

Usbip is not installed in TrueNAS SCALE at the moment, these steps must be performed after any TrueNAS SCALE system update (maybe it could be an automated script to run one-time only after an update):

Add this line to end of /etc/apt/sources.list:

sudo echo "deb http://deb.debian.org/debian-security/ bullseye-security main" >> /etc/apt/sources.list

Enable apt commands that will be used:

sudo chmod 744 /bin/apt sudo chmod 744 /bin/apt-get sudo apt -o APT::Sandbox::User=root update

Then update apt sources and install usbip tools:

sudo apt update sudo chmod 744 /bin/apt-config sudo chmod 744 /bin/apt-extracttemplates sudo chmod 744 /bin/apt-ftparchive sudo chmod 744 /bin/apt-sortpkgs sudo chmod 744 /bin/dpkg sudo apt-get install usbip

After this, succeeds, restore permissions on all the apt commands:

sudo chmod 644 /bin/apt sudo chmod 644 /bin/apt-*

Follow instructions to connect to remote usb devices: (note: in my case it's a DD-WRT WiFi router with SkyConnect, attached to USB with it's short cable. It should already have the device made available over USBIP - which is a separate set of steps I have added to a startup script on the router):

The following steps could be added to a TrueNAS startup script that runs after the system is booted and all virtual machines and apps are started running:

sudo modprobe vhci_hcd

Attach the remote device:

sudo usbip attach -r 192.168.0.1 -b 2-2

Confirm the USB device is attached

TrueNAS SCALE doesn't include the lsub command, so you may have to do this instead to find it by product name or vendor ID:

sudo cat /sys/kernel/debug/usb/devices

Optional additional steps for exposing to a virtual machine

In my case, the remote device needs to be exposed to the VM, which does not have usbip installed, so these steps may help others:

After the usbip device is remotely attached, add the USB device to the virtual machine.

Create a virsh device configuration XML file:

echo "<hostdev mode='subsystem' type='usb' managed='yes'> \ <source> \ <vendor id='0x10c4'/> \ <product id='0xea60'/> \ </source> \ </hostdev>" > ~/SkyConnect_device.xml

Create a symbolic link for the virsh command to work correctly (this only needs to be done once after a a TrueNAS system upgrade):

sudo ln -s /run/truenas_libvirt/libvirt-sock /var/run/libvirt/libvirt-sock

Expose the remote USB device to the virtual machine:

sudo virsh attach-device 2 --file SkyConnect_device.xml

Then check to see if the remote USB device shows up on the Home Assistant VM:

ssh hassio@home-assistant.local
lsusb
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 0627:0001
Bus 004 Device 001: ID 1d6b:0003
Bus 002 Device 001: ID 1d6b:0003
Bus 001 Device 003: ID 10c4:ea60

Pitfalls:
If the remote device hosting the USB device reboots or the USB device is unplugged or restarted, it will detach from TrueNAS SCALE, so the steps starting from "Attach the remote device", above, must be repeated. This could also be automated with a CRON job that confirms the remote device is attached.
 

michalrentka

Cadet
Joined
Jul 20, 2022
Messages
7
I am using usbip on TrueNAS-SCALE-22.12.3.3 (Bluefin [release]) to make a remote USB device available to a virtual machine - in my case, SkyConnect for Home Assistant in a VM running HA OS which does not have usbip installed.

Usbip is not installed in TrueNAS SCALE at the moment, these steps must be performed after any TrueNAS SCALE system update (maybe it could be an automated script to run one-time only after an update):

Add this line to end of /etc/apt/sources.list:

sudo echo "deb http://deb.debian.org/debian-security/ bullseye-security main" >> /etc/apt/sources.list

Enable apt commands that will be used:

sudo chmod 744 /bin/apt sudo chmod 744 /bin/apt-get sudo apt -o APT::Sandbox::User=root update

Then update apt sources and install usbip tools:

sudo apt update sudo chmod 744 /bin/apt-config sudo chmod 744 /bin/apt-extracttemplates sudo chmod 744 /bin/apt-ftparchive sudo chmod 744 /bin/apt-sortpkgs sudo chmod 744 /bin/dpkg sudo apt-get install usbip

After this, succeeds, restore permissions on all the apt commands:

sudo chmod 644 /bin/apt sudo chmod 644 /bin/apt-*

Follow instructions to connect to remote usb devices: (note: in my case it's a DD-WRT WiFi router with SkyConnect, attached to USB with it's short cable. It should already have the device made available over USBIP - which is a separate set of steps I have added to a startup script on the router):

The following steps could be added to a TrueNAS startup script that runs after the system is booted and all virtual machines and apps are started running:

sudo modprobe vhci_hcd

Attach the remote device:

sudo usbip attach -r 192.168.0.1 -b 2-2

Confirm the USB device is attached

TrueNAS SCALE doesn't include the lsub command, so you may have to do this instead to find it by product name or vendor ID:

sudo cat /sys/kernel/debug/usb/devices

Optional additional steps for exposing to a virtual machine

In my case, the remote device needs to be exposed to the VM, which does not have usbip installed, so these steps may help others:

After the usbip device is remotely attached, add the USB device to the virtual machine.

Create a virsh device configuration XML file:

echo "<hostdev mode='subsystem' type='usb' managed='yes'> \ <source> \ <vendor id='0x10c4'/> \ <product id='0xea60'/> \ </source> \ </hostdev>" > ~/SkyConnect_device.xml

Create a symbolic link for the virsh command to work correctly (this only needs to be done once after a a TrueNAS system upgrade):

sudo ln -s /run/truenas_libvirt/libvirt-sock /var/run/libvirt/libvirt-sock

Expose the remote USB device to the virtual machine:

sudo virsh attach-device 2 --file SkyConnect_device.xml

Then check to see if the remote USB device shows up on the Home Assistant VM:

ssh hassio@home-assistant.local
lsusb
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 0627:0001
Bus 004 Device 001: ID 1d6b:0003
Bus 002 Device 001: ID 1d6b:0003
Bus 001 Device 003: ID 10c4:ea60

Pitfalls:
If the remote device hosting the USB device reboots or the USB device is unplugged or restarted, it will detach from TrueNAS SCALE, so the steps starting from "Attach the remote device", above, must be repeated. This could also be automated with a CRON job that confirms the remote device is attached.
Wow, thank you for this! I'll test this out when I have some spare time.
 
Top