1

How can I execute a command in an LXC system container whenever a specific USB device is connected? Ordinarily, I'd use udev (cf. 1, 2, 3, 4, 5), but as far as I can tell, udev cannot be used inside a container.

More specifically, I have a privileged LXC system container running Ubuntu 14.04 (Trusty) on an Ubuntu 16.04 (Xenial) host system. The USB device in question (a Xilinx Platform Cable USB II) requires loading a firmware (by means of fxload).

In the configuration file for the container, I have

lxc.cgroup.devices.allow = c 189:* rwm
lxc.mount.entry = /dev/bus/usb dev/bus/usb none bind,optional,create=dir

This allows me to load the firmware manually from within the container, and subsequently to use the device. I would like to have the firmware loaded automatically when the device is connected.

As a workaround, I currently use udev on the host to load the firmware automatically with the following rule:

SUBSYSTEMS=="usb", ACTION=="add", ATTRS{idVendor}=="03fd", ATTRS{idProduct}=="0013", RUN+="/sbin/fxload -v -t fx2lp -I /opt/Xilinx/firmware/xusb_xp2.hex -D $tempnode"

However, I would like to achieve this from within the container; ideally in a way that does not require any modification to the host system (except, of course, the container configuration).

Martin
  • 125
  • 4
  • I could, of course, call lxc-attach (or ssh) from udev on the host to run a command inside the container. That way, at least the firmware loading would be performed from within the container. But that would still require modifications to the host (plus special treatment of the case where the USB device is connected before the container is started). – Martin May 12 '16 at 11:22

1 Answers1

0

you can do a cron job script to detect a conditional lsusb stdout with a particular ID in a while loop on else condition...and trigger whatever you want.

dernyn
  • 1