At home, I have a server on which I run my VMs and store my content (MP3/OGG/FLAC files I have ripped from my CDs, Photos I’ve taken, etc.) and I want to record material from FreeSat to play back at home, except the server lives in my garage, and the satellite dish feeds into my Living Room. I bought a TeVii S660 USB FreeSat decoder, and tried to figure out what to do with it.
I previously stored the server near where the feed comes in, but the running fan was a bit annoying, so it got moved… but then I started thinking – what if I ran a Raspberry Pi to consume the media there.
I tried running OpenElec, and then LibreElec, and while both would see the device, and I could even occasionally get *content* out of it, I couldn’t write quick enough to the media devices attached to the RPi to actually record what I wanted to get from it. So, I resigned myself to the fact I wouldn’t be recording any of the Christmas Films… until I stumbled over usbip.
USBIP is a service which binds USB ports to a TCP port, and then lets you consume that USB port on another machine. I’ll discuss consuming the S660’s streams in another post, but the below DOES work :)
There are some caveats here. Because I’m using a Raspberry Pi, I can’t just bung on any old distribution, so I’m a bit limited here. I prefer Debian based images, so I’m going to artificially limit myself to these for now, but if I have any significant issues with these images, then I’ll have to bail on Debian based, and use something else.
- If I put on stock Raspbian Jessie, I can’t use usbip, because while ships its own kernel that has the right tools built-in (the usbip_host, usbip_core etc.), it doesn’t ship the right userland tools to manipulate it.
- If I’m using a Raspberry Pi 3, there’s no supported version of Ubuntu Server which ships for it. I can use a flavour (e.g. Ubuntu Mate), but that uses the Raspbian kernel, which, as I mentioned before, is not shipping the right userland tools.
- If I use a Raspberry Pi 2, then I can use Stock Ubuntu, which ships the right tooling. Now all I need to do is find a CAT5 cable, and some way to patch it through to my network…
Getting the Host stood up
I found most of my notes on this via a wiki entry at Github but essentially, it boils down to this:
On your host machine, (where the USB port is present), run
sudo apt-get install linux-tools-generic
sudo modprobe usbip_host
sudo usbipd -D
This confirms that your host can present the USB ports over the USBIP interface (there are caveats! I’ll cover them later!!). Late edit: 2020-05-21 I never did write up those caveats, and now, two years later, I don’t recall what they were. Apologies.
You now need to find which ports you want to serve. Run this command to list the ports on your system:
lsusb
You’ll get something like this back:
Bus 001 Device 004: ID 9022:d662 TeVii Technology Ltd.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
And then you need to find which port the device thinks it’s attached to. Run this to see how usbip sees the world:
usbip list -l
This will return:
- busid 1-1.1 (0424:ec00)
unknown vendor : unknown product (0424:ec00)
- busid 1-1.3 (9022:d662)
unknown vendor : unknown product (9022:d662)
We want to share the TeVii device, which has the ID 9022:d662, and we can see that this is present as busid 1-1.3, so we now we need to bind it to the usbip system, with this command:
usbip bind -b 1-1.3
OK, so now we’re presenting this to the system. Perhaps you might want to make it available on a reboot?
echo "usbip_host" >> /etc/modules
I also added @reboot /usr/bin/usbipd -D ; sleep 5 ; /usr/bin/usbip bind -b 1-1.3
to root’s crontab, but it should probably go into a systemd unit.
Getting the Guest stood up
All these actions are being performed as root. As before, let’s get the modules loaded in the kernel:
apt-get install linux-tools-generic
modprobe vhci-hcd
Now, we can try to attach the module over the wire. Let’s check what’s offered to us (this code example uses 192.0.2.1 but this would be the static IP of your host):
usbip list -r 192.0.2.1
This hands up back the list of offered appliances:
Exportable USB devices
======================
- 192.0.2.1
1-1.3: TeVii Technology Ltd. : unknown product (9022:d662)
: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3
: (Defined at Interface level) (00/00/00)
: 0 - Vendor Specific Class / unknown subclass / unknown protocol (ff/01/01)
So, now all we need to do is attach it:
usbip attach -r 192.0.2.1 -b 1-1.3
Now I can consume the service from that device in tvheadend on my server. However, again, I need to make this persistent. So, let’s make sure the module is loaded on boot.
echo 'vhci-hcd' >> /etc/modules
And, finally, we need to attach the port on boot. Again, I’m using crontab, but should probably wrap this into a systemd service.
@reboot /usr/bin/usbip attach -r 192.0.2.1 -b 1-1.3
And then I had an attached USB device across my network!
Unfortuately, the throughput was a bit too low (due to silly ethernet-over-power adaptors) to make it work the way I wanted… but theoretically, if I had proper patching done in this house, it’d be perfect! :)
Interestingly, the day I finished this post off (after it’d sat in drafts since December), I spotted that one of the articles in Linux Magazine is “USB over the network with USB/IP”. Just typical! :D
“there are caveats! I’ll cover them later!!”
I don’t think you covered the caveats.
Good point. Sadly, 2 years later, I don’t recall what the caveats were! I’ve updated the document to reflect that I didn’t. Thank you for pointing this out Gerry!
Hi Jon, thank you for the tutorial, I followed the instructions and it works.
I can see an USB camera connected to a Raspberry PI from another Raspberry PI in the same network.
lsusb shows the device connected to the other rasp :
pi@raspberrypi:~ $ lsusb
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 003: ID 0c45:62c0 Microdia Sonix USB 2.0 Camera <===
When trying to open the video stream from VLC with device /dev/video0 I get no video.
Any idea where the problem can be ?
Obviously if I connect the camera directly to the USB port I can see the video stream.
Hi Stefano,
Thanks for the question. I’m sorry to say that I didn’t really pursue the USBIP side of things. I was trying to ship a USB connected DVB-S2 interface from a Raspberry Pi on one side of the house, over powerline ethernet to a desktop computer on the other side of the house. This didn’t end up working the way I was hoping it would, and so I decided to abandon the project, and leave it. That said, what you’re talking about seems to be reasonably close to the issue I was having. I wonder whether the problem might be a throughput issue? Perhaps moving to a different board (i.e. moving away from the Raspberry Pi, to some other device, or perhaps using a more recent Raspberry Pi – if you’re not already using one!?) might help?
Sorry I can’t be of more help than that!