[lfs-support] udev custom rules for duplicate usb devices

Ken Moffat zarniwhoop at ntlworld.com
Sat Feb 4 14:42:03 PST 2012

On Sat, Feb 04, 2012 at 05:20:48PM +0200, Thanos Baloukas wrote:
> Hi
> I'm trying to write custom udev rules to create persistent symlinks
> for my usb stick and card reader. The first pluged gets /dev/sda and
> the second /dev/sdb. I followed the instructions in
> http://www.linuxfromscratch.org/lfs/view/stable/chapter07/symlinks.html
> and tried many more (DRIVER="usb-storage",  DRIVER="ums-realtek",
> SUBSYSTEM=="block", ACTION=="add"....) with no success.
> cat /etc/udev/rules.d/83-duplicate_devs.rules
> KERNEL=="sd*", ATTRS{ID_VENDOR}=="Generic-", ATTRS{ID_MODEL}=="Multi-Card", SYMLINK+="card_reader"
> KERNEL=="sd*", ATTRS{ID_VENDOR}=="Kingston", ATTRS{ID_MODEL}=="DT_R500", SYMLINK+="usb_stick"
> I tried renaming to 11-duplicate_devs.rules
> At the moment I test booting having the devices pluged, until the symlinks
> to be created and then add ACTION=="add" rule

 Perhaps that is your problem - do they appear correctly if you boot
without them plugged in, then connect them once the system has
booted ?
> For the usb stick:
> udevadm info --query=all --path=/sys/block/sda
> P: /devices/pci0000:00/0000:00:03.3/usb1/1-3/1-3:1.0/host0/target0:0:0/0:0:0:0/block/sda
> N: sda
> S: disk/by-id/usb-Kingston_DT_R500_0018F3D97163BBB1114800E2-0:0

 FWIW, I use lowercase ATTRS variable names on my sticks and camera
(only one is ever plugged in at a time, so all my different usb
sticks can happily appear at /dev/stick).  I couldn't see
corresponding items in your udevadm output.  As of (summer) 2011,
I found the values using:

 /sbin/udevadm info --name=/dev/sdb --attribute-walk

but I'm sure the correct command will have changed since then -
backward-compatability was never a goal for udev.

 I also specify SUBSYSTEMS=="usb" on some of my rules - that should
clearly be SUBSYSTEM= so I guess that part isn't needed :)  For the
sticks (a range collected over the past few years) I variously match
ATTRS{product}=="USB Flash Memory",
ATTRS{product}=="DISK 2.0",
ATTRS{product}=="EHCI Host Controller",
and for the cameras

 I also match for KERNEL=="sd?1", NOT for the unpartitioned device
(in my case these are all formatted with FAT).

das eine Mal als Tragödie, das andere Mal als Farce

More information about the lfs-support mailing list