lxc-device add seems broken

generalproxuser

Active Member
Mar 14, 2021
107
34
33
44
I just got through an adventure of a (seemingly) simple task of passing through a usb serial device to an lxc.

All my research pointed to the fact that I should have been able to (at least) passthrough the device to a running container in real time with the lxc-device add command.

Unfortunately that was not the case. I had to add the lxc.mount.entry lines into the container config file in order for the device to be passed through correctly and be usable.

The problem I see with this is that the usb device will change its location ( /dev/bus/usb/XXX/XXX ) even when it stays in the same usb port. On every connect/disconnect this has to be accounted for in order to capture the final device path even with a udev rule creating a symlink.

I had to resort to using a udev rule to create a symlink, set permissions (owner,group,mode), run a script to process the device, then the script gathers all the information needed to write the new lxc.mount.entry lines into the container config file and then start the container.

The only way (so far) to successfully passthrough a usb serial device to a container is to insure that the lxc.mount.entry lines exist in the config and they are correct.

If lxc-device add is indeed broken (since the lxc-device man page says that only "add" is supported right now) is proxmox pct able to do something similar or is it worth adding in the future? I looked at the pct man page and there does not seem to be an "add" like function with pct.

Right now I am successfully passing through upwards of 6 usb serial devices to their respective containers (grbl laser, grbl mill, 4 3d printers) and the reason this is a wanted feature is because sometimes not all 4 3d printers will be on and running at the same time. I may power 1 printer on and start using it through my print server container but if the container is already started I can't just add another printer I powered up. Even though my script processes the devices and gets all the information it can't add the lxc.mount.entry line to the config and have it be effective until the next container reboot.

I also can't add the lxc.mount.entry lines to the container config if they aren't powered up because the script checks for those devices first before changing the container config file.
 
Has anyone else had success adding devices to a running container using the lxc-device add command?

I have tried both privileged and unprivileged containers and I cannot for the life of me get a running container to have a device added while running.

Everything works when adding the device via the lxc.mount.entry lines in the conf file of the container.
 
I just got through an adventure of a (seemingly) simple task of passing through a usb serial device to an lxc.

I am also trying to get this issue somehow solved here. I also do have a USB dongle key which on each PVE host node reboot seem to randomly change its /dev/bus/usb/XXX/XXX device node, thus the static lxc.mount.entry in the lxc conf file does not match anymore. And I was also on the search to solve this issue or at least find a way to share the whole /dev/bus/usb/XXX directory tree to the lxc container so that the container can access all of them. However, I was not able to find such a solution. Did you identify any solution yet?

The problem I see with this is that the usb device will change its location ( /dev/bus/usb/XXX/XXX ) even when it stays in the same usb port. On every connect/disconnect this has to be accounted for in order to capture the final device path even with a udev rule creating a symlink.

Would you be so kind in sharing this workaround/solution with us here? As I am facing the same problem here ATM I am quite interested in this kind of script/udev-based solution at least which could help me in not having to manually fix this issue on each PVE host reboot or in case the USB dongle is reconnecting.

The only way (so far) to successfully passthrough a usb serial device to a container is to insure that the lxc.mount.entry lines exist in the config and they are correct.

This is indeed also my observation. I could not find another solution yet to do this dynamically or even try to use the lxc-device command as you are asking here yourself. But perhaps someone (or even you) do have a solution at hand yet? Or perhaps the proxmox developers themselves have some solution or idea how to solve this issue without having to manually approach it.
 
I am also trying to get this issue somehow solved here. I also do have a USB dongle key which on each PVE host node reboot seem to randomly change its /dev/bus/usb/XXX/XXX device node, thus the static lxc.mount.entry in the lxc conf file does not match anymore. And I was also on the search to solve this issue or at least find a way to share the whole /dev/bus/usb/XXX directory tree to the lxc container so that the container can access all of them. However, I was not able to find such a solution.
Usually people use udev rules to make stable names or paths for devices. Here is an example.
 
Usually people use udev rules to make stable names or paths for devices. Here is an example.
Sure, but these udev rules commonly generate symlinks and I am not sure if the lxc.mount.entry can simply point to a symlink but actually probably must point to the concrete /dev/bus/usb/XXX/XXX path instead (probably the case). So I would prefer to see a specific proxmox-related example here rather than a general stackoverflow udev example.
 
Sure, but these udev rules commonly generate symlinks and I am not sure if the lxc.mount.entry can simply point to a symlink but actually probably must point to the concrete /dev/bus/usb/XXX/XXX path instead (probably the case).
Symlinks work fine, for example when using /dev/disk/by-id/ which are symlinks.
So I would prefer to see a specific proxmox-related example here rather than a general stackoverflow udev example.
I'm sorry that I cannot provide a Proxmox-specific example.
 
I managed to get the usb device passthrough working with symlinks in the config files. The symlinks get generated "dynamically" using udev rules. I haven't messed with this project in a while due to life, but my most outstanding issue was still the usb hotplug scenario for a running container. It works in other lxc/lxd environments (usb hot plug) but for some reason it doesn't work with proxmox and its lxc environment.
 

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!