Passthrough USB device to LXC keeping the path /dev/bus/usb/00x/00y

toxic

Active Member
Aug 1, 2020
56
6
28
37
Hello, I'mtrying to passthrough a USB TPU (Google Coral) to my frigate LXC.

Now the fun thing is that it sometimes it tends to change in which order it's being detected, so my config mounting /dev/bus/usb/002/002 to the lxc works fine untill for some reason the device becomes accessible under /dev/bus/usb/002/004 and then it all breaks down...

I have tried using udev to match the device ID and link the device to /dev/coral0 and like this I can sucessfully passthrough the same path /dev/coral to my LXC...

But the issue is that once in the LXC, lsusb still shows the device on bus 2 device #4 and I could not find a way to tell my frigate instance to use /dev/coral0. This is because my understanding is that the coral library will search and try to find the TPU device by itself, so I would realy need to finx a way to map /dev/bus/usb/00x/00y to the exact same x and y inside the lxc.

I have made a script to do this, it does lsusb, grabs the bus and device number and creates a symlink to /dev/coral0 on the proper /dev/bus/usb/00x/00y but seems the lib isn't following simlinks and the PU is not found by frigate...

I tried mount --bind inside the container thinking it would be like a symlink but seems it doesn-t work either...

Any idea is welcome to find a solution ;)
I would have expected there to be a way to tell pve/lxc that device by vendor&id should be mounted in the matching /dev/bus/usb/00x/00y inside the lxc, but I can't seem to find this option...

Now I have temporarly fixed it by passing the entire bus 002 hoping it will not change often, but still, I'd rather pass only the device istead of the full bus...

Thanks in advance for any kind of help on this !
 
Hi, a bit late, but if someone ventures here... You can pass through an entire port into LXC instead of a dedicated USB bus/port. You will have to edit your LXC machine config file (/etc/pve/lxc/[your guest id].conf) manually, and make sure you pick the right option for create=dir, as the majority of examples will suggest you would suggest file.

That is the bit that worked for me:
Code:
...
lxc.cgroup2.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/bus/usb/002 dev/bus/usb/002 none bind,optional,create=dir

Final checks...

Proxmox host:

Bash:
# lsusb
Bus 002 Device 002: ID 18d1:9302 Google Inc.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

LXC guest:
Bash:
$ ls -la /dev/bus/usb/002/
total 0
drwxr-xr-x 2 root root       80 Sep 20 13:46 .
drwxr-xr-x 3 root root       60 Sep 20 13:55 ..
crw-rw-r-- 1 root root 189, 128 Sep 20 13:46 001
crw-rw-r-- 1 root root 189, 129 Sep 20 13:46 002

I found this a lot better approach than trying to modify the config on reboot based on bus/port assigned on boot, as that one doesn't solve the issue with device id changing from 1a6e:089a Global Unichip Corp. to 18d1:9302 Google Inc.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!