LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   udev rule for usbstick (http://www.linuxquestions.org/questions/slackware-14/udev-rule-for-usbstick-491424/)

Steve50 10-11-2006 09:08 AM

udev rule for usbstick
 
I've been trying to create a udev rule for my usbstick so that I can add an entry to fstab. I can mount it manually without any problems once I've found out what device node it's mapped to - but this often changes because I have sata drives, card readers, and other usb devices. So I created /etc/udev/rules.d/local.rules and added this entry:

BUS="usb", SYSFS{serial}="0A315B503230C892", SYSFS{product}="disgo", KERNEL="sd?1", NAME="%k", SYMLINK="usbstick"

I wanted to create a persistent symlink to /dev/usbstick, but it doesn't work. Any ideas anyone?

marnold 10-11-2006 09:13 AM

Here's the rule I used:

BUS=="scsi", KERNEL=="sd*", SYSFS{vendor}=="OTi", SYSFS{model}=="Flash Disk", NAME="%k", SYMLINK+="usbdrive"

Note: this is with Slackware 11.0. The rule format changed quite a bit between the versions of udev that came with 10.2 and 11.0.

Alien Bob 10-11-2006 09:24 AM

Maybe (if you're running Slackware 11.0) you should look in /dev/disk where symlinks for every disk device are created by id, label, uuid and path.

My USB stick (/dev/sda) is there as follows:

Code:

$ ls -la /dev/disk/by-label/ | grep sda
lrwxrwxrwx 1 root root 10 2006-10-11 16:21 /dev/disk/by-label/ZIPSLACK -> ../../sda1

$ ls -la /dev/disk/by-id/ | grep sda
lrwxrwxrwx 1 root root  9 2006-10-11 16:21 usb-JetFlash_TS256MJF2B.2L_61103E90297C0009 -> ../../sda
lrwxrwxrwx 1 root root  10 2006-10-11 16:21 usb-JetFlash_TS256MJF2B.2L_61103E90297C0009-part1 -> ../../sda1

$ ls -la /dev/disk/by-uuid/ | grep sda
lrwxrwxrwx 1 root root  10 2006-10-11 16:21 4522-B5D2 -> ../../sda1

ll /dev/disk/by-path/ | grep sda
lrwxrwxrwx 1 root root  9 2006-10-11 16:21 pci-0000:00:02.2-usb-0:4:1.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root  10 2006-10-11 16:21 pci-0000:00:02.2-usb-0:4:1.0-scsi-0:0:0:0-part1 -> ../../sda1

One of these will allow you to create a fixed /etc/fstab entry at least.

Eric

Steve50 10-11-2006 09:50 AM

Many thanks to both of you. marnoid, I tried rewriting the udev rule but unfortunately it still didn't work, so I looked at Bob's suggestion and added this entry to fstab:

/dev/disk/by-label/disgo /mnt/usbstick vfat rw,user,noauto,umask=000 0 0

It seems to work fine, and I didn't realise you could do this. Many thanks again to both of you.

BeerIsGood 10-13-2006 05:34 AM

Steve50, I realise that you have worked around your initial problem, however if you're still interested, I think the cause of your rule falling over is syntax. Your rule:
Code:

BUS="usb", SYSFS{serial}="0A315B503230C892", SYSFS{product}="disgo", KERNEL="sd?1", NAME="%k", SYMLINK="usbstick"
The matchkey must use the equality operator (==). A single (=) is the assignment operator, except for when you assign a SYMLINK, which uses "+=".

Also, I think that the serial and product SYSFS keys (and possibly kernel key) are enough to identify your deivce. I can't see the name key doing anything, since it says, "match a device that was named by the kernel with the name that the kernel gave it".

Therefore, the rule should probably look more like:
Code:

BUS = "usb", SYSFS{serial}=="0A315B503230C892", SYSFS{product}=="disgo", KERNEL=="sd?1", SYMLINK+="usbstick"
As well as the /dev/sd?1 node, you would get /dev/usbstick, which is a consistently named symlink to your usb stick, whether it be /dev/sda1, /dev/sdb1, etc.

I've been doing a lot of reading on udev to fix a few problems lately, but am no expert, I assure you. My apologies if I lead you up the garden path, but I find it's a nice garden anyhow, if you have the time. I highly recommend Writing udev rules by Daniel Drake.
[edit: changed my mind about needing BUS = "usb"]

Steve50 10-13-2006 05:53 AM

Hi BeerIsGood. Thanks for this follow up. After creating the working fstab entry I also needed to create a udev rule for my wacom tablet, and I ended up doing a fair bit of research, including reading the reference in your post. And you're right, the syntax in my first rule was completely wrong (I believe it changed relatively recently)and after playing around with it I ended up with a working rule that looked very similar to yours. I was also able to create a symlink for my wacom that made configuring xorg.conf entries much easier. The key seems to be the use of the "==" for SYSFS and KERNEL entries and "+=" for the SYMLINK, although I'm sure there's a lot more to it. I'll keep reading.

Cheers

Steve


All times are GMT -5. The time now is 10:40 AM.