Taking RTL_433 in unprivileged LXC container, with automatic device path change for inspiration, I was able to connect multiple APC and Eaton UPS USB cables to a server with the following mechanism. I forwarded the USB connections into an LXC container as I use my nut2mqtt - Communication between Network UPS Tools (NUT) and MQTT for monitoring.
The Proxmox host is configured in a standard way using the primary UPS USB connection (still yet to try).
As a USB cable is inserted, "journalctl -f" will log information similar to:
Apr 25 15:48:21 host02 kernel: usb 3-4: new full-speed USB device number 10 using xhci_hcd Apr 25 15:48:21 host02 kernel: usb 3-4: New USB device found, idVendor=051d, idProduct=0002, bcdDevice= 0.90 Apr 25 15:48:21 host02 kernel: usb 3-4: New USB device strings: Mfr=1, Product=2, SerialNumber=3 Apr 25 15:48:21 host02 kernel: usb 3-4: Product: Back-UPS XS 1300G FW:864.L6 .D USB FW:L6 Apr 25 15:48:21 host02 kernel: usb 3-4: Manufacturer: American Power Conversion Apr 25 15:48:21 host02 kernel: usb 3-4: SerialNumber: 4B12P636 Apr 25 15:48:21 host02 kernel: hid-generic 0003:051D:0002.0007: hiddev3,hidraw5: ......
Use "lsusb" to determine the bus and device assignment based upon the 'idVendor' and 'idProduct' assignments above:
# lsusb -d 051d:0002 Bus 003 Device 010: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
Thus you'll see an associated entry in /dev:
~# ls -altr /dev/bus/usb/003/010 crw-rw-rw- 1 root root 189, 265 Apr 25 15:48 /dev/bus/usb/003/010
Note the cgroup2 '189, 265' identifiers. Adding an entry to your /etc/pve/lxc/<lxc-id>.conf entry will be required:
lxc.cgroup2.devices.allow: c 189:* rwm
Whenever the USB cable is plugged in, a different device may be constructed. To pass that information to Proxmox for when it starts the container, use something like:
# cat /etc/udev/rules.d/50-ups-usb.rules
SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="051d", ENV{ID_MODEL_ID}=="0002", ENV{ID_SERIAL_SHORT}=="4B12P636", MODE="0666", RUN="/usr/sbin/pct set <lxc-id> --dev0 mode=0666,path=$devnode"
If the file is changed, it can be processed with:
# reload rules and rerun udevadm control --reload-rules udevadm trigger # optional cable test simulation udevadm test /dev/bus/usb/003/010
The ENV{ID_VENDOR_ID}, ENV{ID_MODEL_ID} & ENV{ID_SERIAL_SHORT} variable names and content can be confirmed with:
# udevadm info /dev/bus/usb/003/010 P: /devices/pci0000:80/0000:80:14.0/usb3/3-4 M: 3-4 R: 4 J: c189:265 U: usb T: usb_device D: c 189:265 N: bus/usb/003/010 L: 0 V: usb E: DEVPATH=/devices/pci0000:80/0000:80:14.0/usb3/3-4 E: DEVNAME=/dev/bus/usb/003/010 E: DEVTYPE=usb_device E: DRIVER=usb E: PRODUCT=51d/2/90 E: TYPE=0/0/0 E: BUSNUM=003 E: DEVNUM=010 E: MAJOR=189 E: MINOR=265 E: SUBSYSTEM=usb E: USEC_INITIALIZED=2435707957355 E: ID_BUS=usb E: ID_MODEL=Back-UPS_XS_1300G_FW:864.L6_.D_USB_FW:L6 E: ID_MODEL_ENC=Back-UPS\x20XS\x201300G\x20FW:864.L6\x20.D\x20USB\x20FW:L6\x20 E: ID_MODEL_ID=0002 E: ID_SERIAL=American_Power_Conversion_Back-UPS_XS_1300G_FW:864.L6_.D_USB_FW:L6_4B1233P63346 E: ID_SERIAL_SHORT=4B12P636 E: ID_VENDOR=American_Power_Conversion E: ID_VENDOR_ENC=American\x20Power\x20Conversion E: ID_VENDOR_ID=051d E: ID_REVISION=0090 E: ID_USB_MODEL=Back-UPS_XS_1300G_FW:864.L6_.D_USB_FW:L6 E: ID_USB_MODEL_ENC=Back-UPS\x20XS\x201300G\x20FW:864.L6\x20.D\x20USB\x20FW:L6\x20 E: ID_USB_MODEL_ID=0002 E: ID_USB_SERIAL=American_Power_Conversion_Back-UPS_XS_1300G_FW:864.L6_.D_USB_FW:L6_4B1233P63346 E: ID_USB_SERIAL_SHORT=4B12P636 E: ID_USB_VENDOR=American_Power_Conversion E: ID_USB_VENDOR_ENC=American\x20Power\x20Conversion E: ID_USB_VENDOR_ID=051d E: ID_USB_REVISION=0090 E: ID_USB_INTERFACES=:030000: E: ID_VENDOR_FROM_DATABASE=American Power Conversion E: ID_MODEL_FROM_DATABASE=Uninterruptible Power Supply E: ID_PATH_WITH_USB_REVISION=pci-0000:80:14.0-usbv2-0:4 E: ID_PATH=pci-0000:80:14.0-usb-0:4 E: ID_PATH_TAG=pci-0000_80_14_0-usb-0_4 E: ID_FOR_SEAT=usb-pci-0000_80_14_0-usb-0_4 E: TAGS=:seat: E: CURRENT_TAGS=:seat:
Resources:
- udev(7) — Linux manual page - Dynamic device management
- Persistent names for USB-serial devices in Linux (/dev/ttyUSBx -> /dev/custom-name) - I first looked at doing symlinks, but realized it is not required if I can perform a 'pct set' directly on the container configuration.


