Accessing a USB device in Toolbox via udev rule

My device (connected to USB-A port on a laptop):
/dev/ttyACM0

more info about device (it’s a self build drone for a hobby project):
udevadm info -a -n /dev/serial/by-id/usb-ArduPilot_FlywooF745_220026000851323232393431-if00

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/tty/ttyACM0':
    KERNEL=="ttyACM0"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0':
(etc)

I followed this recommendation to create a udev rule, to allow access to the device via a Toolbox container:

/etc/udev/rules.d/50-usb-serial.rules:

SUBSYSTEM=="ttyACM0", SUBSYSTEMS=="tty", OWNER="${USER}"
EOF

On the host, the device user/group now looks like:
ls -l /dev/ttyACM0:

crw-rw----. 1 root dialout 166, 0  5 aug 16:16 /dev/ttyACM0

Inside the container:

crw-rw----. 1 nobody nobody 166, 0 Aug  5 16:16 /dev/ttyACM0

Still I do not seem to have access.

In the guide, instead of nobody/nobody, it shows nobody/dialout for the container. The guide may be outdated.

This post says you have to do one more thing. But that first command to get the ID from within the container, does not work for me.

sg dialout -c 'sleep 1000'
Password: 
sg: failed to crypt password with previous salt: Invalid argument

I feel like I am really close… (as a bit of a noob) but just not there yet… Any help would be greatly appreciated!

1 Like

I’d probably take the “easy” (but perhaps a little less secure) route in this case. I’d try using MODE="0666" instead of OWNER="${USER}".

Also, shouldn’t you be using KERNEL=="ttyACM0" (or perhaps KERNEL=="ttyACM*" if you have multiple of these devices) instead of SUBSYSTEM=="ttyACM0"?

I tried this rule now:

subsystem=="tty",subsystems=="usb", MODE="0666"
EOF

Because this was the full output:

looking at device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/tty/ttyACM0':
    KERNEL=="ttyACM0"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{power/control}=="auto"
    ATTR{power/runtime_active_time}=="0"
    ATTR{power/runtime_status}=="unsupported"
    ATTR{power/runtime_suspended_time}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0':
    KERNELS=="3-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="cdc_acm"
    ATTRS{authorized}=="1"
(...)

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3/3-1':
    KERNELS=="3-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{authorized}=="1"
    ATTRS{avoid_reset_quirk}=="0"
   (...)

  looking at parent device '/devices/pci0000:00/0000:00:14.0/usb3':
    KERNELS=="usb3"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
(...)

  looking at parent device '/devices/pci0000:00/0000:00:14.0':
    KERNELS=="0000:00:14.0"
    SUBSYSTEMS=="pci"
    DRIVERS=="xhci_hcd"
(...)

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""
    ATTRS{power/control}=="auto"
    ATTRS{power/runtime_active_time}=="0"
    ATTRS{power/runtime_status}=="unsupported"
    ATTRS{power/runtime_suspended_time}=="0"
    ATTRS{waiting_for_supplier}=="0"

And I read this recommendation (at the bottom): writing udev rule for USB device - Ask Ubuntu

It makes sense, to now capture all parts of this device.

However, my python script that requires access still says Cannot connect to server socket err = No such file or directory I probably still need to do something, or something else is causing this.

It might be case-sensitive. Many things in Unix/Linux are. I never tried using lower-case key names in a udev rule.

I’d probably just try KERNEL=="ttyACM0", MODE="0666" and see if that works.

Thanks, even with that it didn’t work. I’m going a few steps back: see if it works on my host. Just have to install all the modules/dependencies for the script. If it works, then at least I know it’s just an issue of getting access from the container to USB. Will report back!

Added atomic-desktops, podman, toolbx, udev-rules