Lookup udev attributes

In a previous post (Passing serial port to unprivileged container) I needed to create an udev rule to adjust the permissions on a serial port I wanted to pass through to a container. How did I come up with the values needed in the rule?

To determine attributes to match on within an udev rule you can make use of the udevadm command. With the “info” command you can display all the attributes and determine the ones you can match on.

Example output from udevadm for the ttyS1 I needed to passthrough in the other article:

root@proxmox:/etc/udev/rules.d# udevadm info -a /dev/ttyS1

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/pnp0/00:05/tty/ttyS1':
    KERNEL=="ttyS1"
    SUBSYSTEM=="tty"
    DRIVER==""
    ATTR{port}=="0x2F8"
    ATTR{custom_divisor}=="0"
    ATTR{irq}=="3"
    ATTR{uartclk}=="1843200"
    ATTR{close_delay}=="50"
    ATTR{io_type}=="0"
    ATTR{flags}=="0x10000040"
    ATTR{iomem_reg_shift}=="0"
    ATTR{closing_wait}=="3000"
    ATTR{type}=="4"
    ATTR{xmit_fifo_size}=="16"
    ATTR{rx_trig_bytes}=="8"
    ATTR{line}=="1"
    ATTR{iomem_base}=="0x0"

  looking at parent device '/devices/pnp0/00:05':
    KERNELS=="00:05"
    SUBSYSTEMS=="pnp"
    DRIVERS=="serial"
    ATTRS{id}=="PNP0501"

  looking at parent device '/devices/pnp0':
    KERNELS=="pnp0"
    SUBSYSTEMS==""
    DRIVERS==""

As you can see udevadm lists quite nicely all it knows about the device and the parent device it is connected to. I choose to match on the name the kernel knows about it and the subsytem it is part of so that gave me:

KERNEL=="ttyS1", SUBSYSTEMS=="tty"

Very easy 😉