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

Thanos Baloukas baloukasthan at sch.gr
Sat Feb 4 17:48:06 PST 2012


On 04/02/2012 05:20 ??, 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
*Ken Moffat wrote:
*

Perhaps that is your problem - do they appear correctly if you boot
without them plugged in, then connect them once the system has
booted ?

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
on
ATTRS{product}=="USB Flash Memory",
ATTRS{product}=="DISK 2.0",
ATTRS{product}=="EHCI Host Controller",
and for the cameras
ATTRS{manufacturer}=="OLYMPUS",

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

Thanos Baloukas wrote:

Thank you Ken, for the response. I tried many times to boot and then plug
having the ACTION=="add" option. I tried with lower/upper case also.
KERNEL=="sd?1" is more strict than KERNEL=="sd*",
but  the solution was elsewere. I have to be more carefull
when I read man pages. The option --attribute-walk
helped to find correct rules. I used rules from the same device
as per command's output: SUBSYSTEMS=="scsi", ATTRS{vendor}=="Kingston"
and SUBSYSTEMS=="scsi",ATTRS{vendor}=="Generic-"

The full lines:

ACTION=="add", KERNEL=="sd*", SUBSYSTEMS=="scsi", 
ATTRS{vendor}=="Kingston", SYMLINK+="usb_stick", RUN+="/bin/mount 
/dev/usb_stick"
ACTION=="add", KERNEL=="sd*", SUBSYSTEMS=="scsi", 
ATTRS{vendor}=="Generic-", SYMLINK+="card_reader", RUN+="/bin/mount 
/dev/card_reader"

and have them mounted.

Thank you very much for the help. I spent a lot of time trying
and had got stuck.

Thanos

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfromscratch.org/pipermail/lfs-support/attachments/20120205/d7f63847/attachment.html>


More information about the lfs-support mailing list