USB udev rules not working

Greetings!

plugging in a USB Modem (Huawei E220) OpenSuse-42.3 recognizes 2 devces: /dev/ttyUSB0 /dev/ttyUSB1
Sometimes however the systemn assigns /dev/ttyUSB0 and /dev/ttyUSB2.

To solve issues in scripts I want to assign fixed sysmlinks for this devices:

/etc/udev/rules.d/99-local-USB.rules:
ACTION==“add”, ATTRS{idVendor}==“12d1”, ATTRS{idProduct}==“1003”, ATTRS{bInterfaceNumber}==“00”, SYMLINK+=“USB-Internet-Modem”

ACTION==“add”, ATTRS{idVendor}==“12d1”, ATTRS{idProduct}==“1003”, ATTRS{bInterfaceNumber}==“01”, SYMLINK+=“USB-SMS-Modem”

Both ‘ATTRS{bInterfaceNumber}’ are taken from then output of
udevadm info -a -n /dev/ttyUSB0 and /dev/ttyUSB0

Running ‘udevadm control --reload-rules && udevadm trigger’
it simply shows (/etc/udev/udev.conf: udev_log=“debug”)
‘calling control
calling trigger
device-enumerator: scannig /sys/bus
device-enumerator: scannig /sys/class’

A reboot also does not show the desired symlinks.

What am I doing wrong?

Thanks for reading and hints.

The first hint should come from you. You choose for OTHER VERSION. That implies a not supported version. And that makes it the more important that you tell us which version you are using.

He did Henk. It is openSUSE 42.3

You should show us the device attributes reported by ‘udevadm info…’. Are the selected attributes valid? From this writing_udev_rules reference it is important to remember…

you cannot mix-and-match attributes from multiple parent devices

Also mentioned in the ‘udevadm info…’ output…

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.

Sorry, I see now.

That’s it!

ACTION=="add", KERNELS=="1-1:1.0", SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="00" SYMLINK+="USB-Internet-Modem"
ACTION=="add", KERNELS=="1-1:1.1", SUBSYSTEMS=="usb", ATTRS{bInterfaceNumber}=="01" SYMLINK+="USB-SMS-Modem"

Works as required!

Thanks a lot and have a nice day
Wolf

Thanks for the update.

I have this:

   82.137751] kernel: scsi host6: usb-storage 2-9:1.0
   83.162407] kernel: scsi 6:0:0:0: Direct-Access     Garmin   GARMIN Flash     1.00 PQ: 0 ANSI: 5
   83.163275] kernel: scsi 6:0:0:1: Direct-Access     Garmin   GARMIN Card      1.00 PQ: 0 ANSI: 5
   83.163774] kernel: sd 6:0:0:0: Attached scsi generic sg4 type 0
   83.164160] kernel: sd 6:0:0:1: Attached scsi generic sg5 type 0
   83.165266] kernel: sd 6:0:0:0: Power-on or device reset occurred
   83.167186] kernel: sd 6:0:0:0: [sdd] 7733248 512-byte logical blocks: (3.96 GB/3.69 GiB)
   83.168761] kernel: sd 6:0:0:0: [sdd] Write Protect is off
   83.168769] kernel: sd 6:0:0:0: [sdd] Mode Sense: 23 00 00 00
   83.170247] kernel: sd 6:0:0:1: Power-on or device reset occurred
   83.172148] kernel: sd 6:0:0:1: [sde] 15353856 512-byte logical blocks: (7.86 GB/7.32 GiB)
   83.173678] kernel: sd 6:0:0:1: [sde] Write Protect is off
   83.173684] kernel: sd 6:0:0:1: [sde] Mode Sense: 23 00 00 00
   83.174700] kernel: sd 6:0:0:1: [sde] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
   83.175697] kernel: sd 6:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
   83.241528] kernel: sd 6:0:0:1: [sde] Attached SCSI removable disk
   83.242474] kernel: sd 6:0:0:0: [sdd] Attached SCSI removable disk

Rule file works as intended:

erlangen:~ # cat /etc/udev/rules.d/extrex.rules 
KERNELS=="6:0:0:0", SUBSYSTEMS=="usb", ATTRS{idVendor}=="091e", ATTRS{idProduct}=="28ca", SYMLINK+="etrex", ACTION=="add", RUN+="/usr/local/bin/usbstick-backup"
erlangen:~ # 

But is it really robust? Is KERNELS unique? Will it change?

Quite possibly. Unfortunately the OP never provided the ‘udevadm’ output requested to show the complete attribute info as requested. Sometimes this kind of thing is part of the learning. :wink:

Yes, “works as required” is not the same as “save and sound and future hard solution”. :\

What worked didn’t survive boot although the same data were assigned.:slight_smile:

I tried again:

udevadm info -a -n /dev/sdd

  looking at device '/devices/pci0000:00/0000:00:14.0/usb2/2-10/2-10:1.0/host6/target6:0:0/6:0:0:0/block/sdd':
**    KERNEL=="sdd"**
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{make-it-fail}=="0"
    ATTR{hidden}=="0"
    ATTR{inflight}=="       0        0"
    ATTR{ro}=="0"
    ATTR{removable}=="1"
    ATTR{capability}=="51"
    ATTR{stat}=="     146     7365     9562    29918        1        0        1        3        0    15744    29921        0        0        0        0        0        0"
    ATTR{events_async}==""
    ATTR{events_poll_msecs}=="-1"
    ATTR{alignment_offset}=="0"
    ATTR{range}=="16"
    ATTR{events}=="media_change"
**    ATTR{size}=="7733248"**
    ATTR{discard_alignment}=="0"
    ATTR{ext_range}=="256"
....
 looking at parent device '/devices/pci0000:00/0000:00:14.0/usb2/2-10':
    KERNELS=="2-10"
**    SUBSYSTEMS=="usb"**
    DRIVERS=="usb"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{tx_lanes}=="1"
    ATTRS{removable}=="removable"
    ATTRS{quirks}=="0x0"
    ATTRS{bNumConfigurations}=="1"
**    ATTRS{idVendor}=="091e"**
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{rx_lanes}=="1"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{busnum}=="2"
    ATTRS{maxchild}=="0"
**    ATTRS{idProduct}=="28ca"**
    ATTRS{devnum}=="7"
    ATTRS{bcdDevice}=="0509"
    ATTRS{bDeviceClass}=="00"
    ATTRS{ltm_capable}=="no"
    ATTRS{bMaxPower}=="500mA"
    ATTRS{devpath}=="10"
    ATTRS{authorized}=="1"
    ATTRS{urbnum}=="3208"
    ATTRS{version}==" 1.10"
    ATTRS{serial}=="0000eae6763f"
    ATTRS{configuration}==""
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{bmAttributes}=="80"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{speed}=="12"

erlangen:~ # cat /etc/udev/rules.d/etrex.rules 
KERNEL=="sd?", ATTR{size}=="7733248", SUBSYSTEMS=="usb", ATTRS{idVendor}=="091e", ATTRS{idProduct}=="28ca", SYMLINK+="etrex", ACTION=="add", RUN+="/usr/local/bin/usbstick-backup"
erlangen:~ # 

The file name starts with a character. Thus the rule is applied after system rules starting with a digit. The action is indeed performed for /dev/sdd only and it survived a boot.

@karl: I’m not sure why you’re directing your replies at me. I already showed the OP what was required and why you’d choose the KERNEL attribute I really don’t know. Use attributes that are truly specific to the device, and it should be generally known that the kernel device assignment numbering could change. For example, your rule didn’t require anything more than…

SUBSYSTEM=="block", ATTRS{idVendor}=="091e", ATTRS{idProduct}=="28ca", SYMLINK+="etrex", ACTION=="add", RUN+="/usr/local/bin/usbstick-backup"

Anyway, it is to the OP that I requested the ‘udevadm’ output, and then I would have assisted further. I’m done here.

That matches sde, sde and sde1. Intended sdd is selected by:

SUBSYSTEM=="block", **ATTR{size}=="7733248",** ATTRS{idVendor}=="091e", ATTRS{idProduct}=="28ca", SYMLINK+="etrex", ACTION=="add", RUN+="/usr/local/bin/usbstick-backup"

Thanks for helping!

I don’t mind helping Karl, but you were not the OP in this thread, and this can just lead to a confused thread. I didn’t even know what you’re trying to achieve (I though you were just attempting to help the OP). In any case, it is now apparent that you are trying to identify a particular partition on a Garmin? device. You could have match against unique environment variables set (when rules in 60-persistent-storage.rules are triggered). You just need to be careful with the file naming, as the rules are processed in lexicographical order, so a custom rule needs to be numbered with a larger number eg 75-custom.rules

To view environment variables pertaining to a given device or partition…

udevadm info /dev/sdd

Output preceded by and ‘E:’ refers to an environment variable that has been set. For example

~> udevadm info /dev/sde2|grep UUID
E: ID_FS_UUID=c379b54f-f310-4aba-a13f-390c421d720c
E: ID_FS_UUID_ENC=c379b54f-f310-4aba-a13f-390c421d720c
E: ID_PART_ENTRY_UUID=f5ad9b4b-2884-4d15-97c6-9e3b7dd3bc86
E: ID_PART_TABLE_UUID=5ed870fd-a9a5-415c-aec2-16444b5025f5
~> udevadm info /dev/sdb|grep UUID
E: ID_FS_UUID=7EF27FFB9B7835CC

Then you can match against UUID eg for the /dev/sdb example above, ENV{ID_FS_UUID}==“7EF27FFB9B7835CC” could be used.

Great.:slight_smile:

erlangen:~ # cat /etc/udev/rules.d/etrex.rules 
SUBSYSTEM=="block", ENV{ID_FS_UUID}=="6914-84F3", ATTRS{idVendor}=="091e", ATTRS{idProduct}=="28ca", SYMLINK+="etrex", ACTION=="add", RUN+="/usr/local/bin/usbstick-backup"
erlangen:~ # udevadm test /sys/block/sdd     
...
Reading rules file: /usr/lib/udev/rules.d/99-wakeup-from-idle.rules
Reading rules file: /etc/udev/rules.d/ant-usb-sticks.rules
**Reading rules file: /etc/udev/rules.d/etrex.rules**
Invalid inotify descriptor.
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-10/2-10:1.0/host6/target6:0:0/6:0:0:0/block/sdd
DEVNAME=/dev/sdd
DEVTYPE=disk
MAJOR=8
MINOR=48
ACTION=add
**SUBSYSTEM=block**
DONT_DEL_PART_NODES=1
ID_VENDOR=Garmin
ID_VENDOR_ENC=Garmin\x20\x20
**ID_VENDOR_ID=091e**
ID_MODEL=GARMIN_Flash
ID_MODEL_ENC=GARMIN\x20Flash\x20\x20\x20\x20
**ID_MODEL_ID=28ca**
ID_REVISION=1.00
ID_SERIAL=Garmin_GARMIN_Flash_0000eae6763f-0:0
ID_SERIAL_SHORT=0000eae6763f
ID_TYPE=disk
ID_INSTANCE=0:0
ID_BUS=usb
ID_USB_INTERFACES=:080650:
ID_USB_INTERFACE_NUM=00
ID_USB_DRIVER=usb-storage
ID_PATH=pci-0000:00:14.0-usb-0:10:1.0-scsi-0:0:0:0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_10_1_0-scsi-0_0_0_0
.SYSFS_PATH=/sys/class/scsi_device/6:0:0:0/device
SCSI_TPGS=0
SCSI_TYPE=disk
SCSI_VENDOR=Garmin
SCSI_VENDOR_ENC=Garmin\x20\x20
SCSI_MODEL=GARMIN_Flash
SCSI_MODEL_ENC=GARMIN\x20Flash\x20\x20\x20\x20
SCSI_REVISION=1.00
ID_SCSI=1
ID_SCSI_INQUIRY=1
MPATH_SBIN_PATH=/sbin
.SAVED_FM_WAIT_UNTIL=
DM_MULTIPATH_DEVICE_PATH=0
FC_TARGET_LUN=0
.IS_MQ=1
DEVLINKS=/dev/etrex /dev/disk/by-path/pci-0000:00:14.0-usb-0:10:1.0-scsi-0:0:0:0 /dev/disk/by-uuid/6914-84F3 /dev/disk/by-id/usb-Garmin_GARMIN_Flash_0000eae6763f-0:0 /dev/disk/by-label/GARMIN
ID_FS_LABEL=GARMIN
ID_FS_LABEL_ENC=GARMIN
**ID_FS_UUID=6914-84F3**
ID_FS_UUID_ENC=6914-84F3
ID_FS_VERSION=FAT32
ID_FS_TYPE=vfat
ID_FS_USAGE=filesystem
COMPAT_SYMLINK_GENERATION=2
TAGS=:systemd:
USEC_INITIALIZED=3366469905
run: '/usr/local/bin/usbstick-backup'
Unload module index
Unloaded link configuration context.
erlangen:~ #