USB passthrough to a container LXC?

On various Hardware and OS systems: pi / windows / routers / nas, etc

Moderator: leecollings

Post Reply
TroisSix
Posts: 92
Joined: Monday 11 January 2016 9:29
Target OS: -
Domoticz version: 2022.2
Location: France
Contact:

USB passthrough to a container LXC?

Post by TroisSix »

Hi guys,

I searched over the internet and on this forum, without finding the good way.
Sorry for this long thread, that's my first one for proxmox ;-)

Here is what I have:
- a nuc intel with proxmox and a RFXcom + Conbee ii plugged on usb 3.0 (no usb 2...)
- I have a container lxc ubuntu for my domoticz
- I cannot make the usb work inside my lxc with domoticz :-(

Here is what I have on my nuc:

Code: Select all

# lsusb
Bus 001 Device 003: ID 1cf1:0030 Dresden Elektronik ZigBee gateway [ConBee II]
Bus 001 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC

# nano /etc/udev/rules.d/49-usb-serial.rules
KERNEL=="ttyACM[0-9]*", SUBSYSTEM=="tty", ATTRS{idVendor}=="1cf1", ATTRS{idProduct}=="0030", SYMLINK="ttyConbee", OWNER="root", GROUP="dialout", MODE="0666", RUN+="/usr/bin/chmod o+rw /dev/ttyConbee"
KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK="ttyRFXcom", OWNER="root", GROUP="dialout", MODE="0666", RUN+="/usr/bin/chmod o+rw /dev/ttyRFXcom"
# is it subsystem or subsystems?

# nano /etc/pve/lxc/xxx.conf
lxc.cgroup.devices.allow: c 166:* rwm
lxc.cgroup.devices.allow: c 188:* rwm
lxc.mount.entry: /dev/ttyConbee dev/ttyConbee none bind,optional,create=file
lxc.mount.entry: /dev/ttyRFXcom dev/ttyRFXcom none bind,optional,create=file

# ls -l /dev/tty* /dev/bus/usb/001/0*
crw-rw-rw-  1 root dialout 188,     0 Dec 20 15:28 ttyUSB0
crw-rw-rw-  1 root dialout 166,     0 Dec 20 15:28 ttyACM0
lrwxrwxrwx  1 root root             7 Dec 20 15:28 ttyConbee -> ttyACM0
lrwxrwxrwx  1 root root             7 Dec 20 15:28 ttyRFXcom -> ttyUSB0

# ls -la /dev/serial/by-id/
lrwxrwxrwx 1 root root 13 Dec 20 15:28 usb-dresden_elektronik_ingenieurtechnik_GmbH_ConBee_II_DE2471148-if00 -> ../../ttyACM0
lrwxrwxrwx 1 root root 13 Dec 20 15:28 usb-RFXCOM_RFXtrx433_A1Z58RWG-if00-port0 -> ../../ttyUSB0
And here is what I have for my container lxc:

Code: Select all

$ lsusb
Bus 001 Device 003: ID 1cf1:0030 Dresden Elektronik ZigBee gateway [ConBee II]
Bus 001 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC

$ sudo ls -l /dev/
crw-rw-rw-  1 nobody nogroup 166, 0 déc.  20 15:28 ttyConbee
crw-rw-rw-  1 nobody nogroup 188, 0 déc.  20 15:28 ttyRFXcom
#==> why is it nobody / nogroup ?

$ sudo ls -la /dev/serial/by-id/
ls: cannot access '/dev/serial/by-id/': No such file or directory

$ groups xxx
xxx : xxx dialout

$ GCFFlasher_internal -l
GCFFlasher V3_17 (c) dresden elektronik ingenieurtechnik gmbh
Path             | Vendor | Product | Serial     | Type
-----------------+--------+---------+------------+-------
# I should see my both devices !?
Not enough cause I cannot see my devices in domoticz :?

I also tried:

Code: Select all

$ mkdir -p /run/udev/data/
$ cd /run/udev/data/

$ echo "E:ID_VENDOR_ID=1cf1
E:ID_MODEL_ID=0030" > c166\:0

$ echo "E:ID_VENDOR_ID=0403
E:ID_MODEL_ID=6001" > c188\:0

$ GCFFlasher_internal -l
GCFFlasher V3_17 (c) dresden elektronik ingenieurtechnik gmbh
Path             | Vendor | Product | Serial     | Type
-----------------+--------+---------+------------+-------
/dev/ttyUSB0     | 0x0403 | 0x6001  |            | Generic FTDI
/dev/ttyACM0     | 0x1CF1 | 0x0030  |            | ConBee II

$ ls -lah /dev/ttyACM0 /dev/ttyUSB0
crw-rw---- 1 nobody nogroup 166, 0 déc.  20 13:24 /dev/ttyACM0
crw-rw---- 1 nobody nogroup 188, 0 déc.  20 12:25 /dev/ttyUSB0
But I still cannot see my devices in domoticz ...


I tried a lot of stop/start of my lxc and restart of my nuc, no way...
Please help me, I think I'm mad ?
I miss something, but don't find what, sure some of you already encountered this kind of problem ^^

PS: my p3b is still working perfectly and doesn't want to be replaced by a lxc container :lol:
Thanks a lot.
VM Debian - Domoticz stable v2024.7, RFXtrx433, Aeotec Z-Stick Gen5, Two APC
- rts: dio, oregon, somfy
- zwave: fibaro fgs212, aeotec smart switch, vision ZG8101
- IO Homecontrol: Velux Connexoon
- logitech harmony hub, philips hue, Pilot app.
aardwolf2
Posts: 12
Joined: Wednesday 16 October 2013 1:01
Target OS: Linux
Domoticz version:
Contact:

Re: USB passthrough to a container LXC?

Post by aardwolf2 »

A bit late but I've just done this with an RFXtrx433 (only, no Conbee), it was a right pain to find the info to get it working so I need to put the howto somewhere so it can be found, and I found this thread, so I'm putting it here. I wrote a long list of instructions, but deleted them for simplicity as I assume anyone knowledgeable enough to set up a proxmox host knows the necessary commands/location of files etc, so this is a high level howto, rather than a direct answer to the above post

Domoticz appears to use the location "/dev/serial/by-id" to find serial devices, so we need to pass that location (or file, up to you) through to the container, I did the whole directory, just because. We also need to pass though the base /dev/ttyUSBX device as /dev/serial/by-id is simply a link to /dev/ttyUSBX (mine is /dev/USB0 reflected in the solution below, change for your serial device), and give the container permissions to access the device, finally the user and group ID of /dev/ttyUSBX within the container ends up wrong (nobody nogroup) so that needs fixing.

Add the following to the containers conf file on the host, use the instructions below to get the proper numbers you will need for the devices.allow line do not blindly copy this into your config file.

lxc.cgroup.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/serial dev/serial none bind,create=dir 0 0
lxc.mount.entry: /dev/ttyUSB0 dev/ttyUSB0 none bind,create=file 0 0

With these done (and the proper numbers from _your_ system) if you start the container and "ls -l /dev/ttyUSB0" (insert your device name) if you see the owner and group as nobody and nogroup you can chown the /dev/ttyUSB device on the _host_ using the owner id of 100000 and the group id of "100000 + the dialout group id from the container", my dialout group id in my container is 20, so I used the group id of 100020. If you "ls -l /dev/ttyUSB0" in the container now the owner should be root, and the group dialout. I had already made my user a member of the dialout group so you may need that also.

You should now be able to add the rfxtrx433 device into Domoticz in the container and have it actually communicate.


I started here for the instructions on how to pass through a USB device:-

https://medium.com/@konpat/usb-passthro ... 482674f11d

In case of link rot.

On the Proxmox host do "lsusb", you are after the Bus and Device numbers for your serial device, in my case 002 and 003.

Bus 002 Device 003: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC

Next do a "ls -al /dev/bus/usb/002/003" replacing 002/003 with your Bus and Device numbers, this gave me:-

crw-rw-r-- 1 root root 189, 130 May 13 19:43 /dev/bus/usb/002/003

You are looking for the number that appears after root root, here it is 189, you want your number, it may or may not be 189, but you want yours, this number is for this line of the conf file, replace 189 with your number, you can replace * with the second number (130 in my case) to only reference an individual device, no idea if this causes any issues as I didn't do it. SO in my case the conf file line is:-

lxc.cgroup.devices.allow: c 189:* rwm

Hope this actually works for other people.

A2
Jubbes
Posts: 33
Joined: Wednesday 24 October 2018 14:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: USB passthrough to a container LXC?

Post by Jubbes »

Hello #aardwolf2,
I can't get my RFLink to work in the Proxmox LXC container in Domoticz. Do you still have the list with the detailed commands?
I'd be grateful.

Thanks, Jubbes
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest