You are not logged in.

#1 2005-11-25 23:04:10

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

udev to map multiple entries to *few* *partitioned* devices

Having read then followed wiki's Using udev to map multiple entries to a device, I cannot yet adapt it for my externel 160GB partitioned HDD.

Here is what I have :
- plugged the HDD to my laptop with no other external storage
- Found its supposed SYSFS{serial} :

# udevinfo -a -p `udevinfo -q path -n /dev/sda` | grep SYSFS{serial}
    SYSFS{serial}=="DEF1091BE9A1"
    SYSFS{serial}=="0000:00:05.2"

- Created /etc/udev/rules.d/00.rules with those lines :

# DD usb
BUS="usb", SYSFS{serial}="DEF1091BE9A1", KERNEL="sd?", NAME="%k", SYMLINK="ddusb", GROUP="storage"
BUS="usb", SYSFS{serial}="0000:00:05.2", KERNEL="sd?1", NAME="%k", SYMLINK="ddusb", GROUP="storage

- Edited /etc/fstab with

# DD usb
/dev/ddusb1     /media/ddusb1   ext3    user,exec,noauto 0 0
/dev/ddusb5     /media/ddusb5   vfat    noauto,user,noexec,nodev,nosuid 0 0
/dev/ddusb6     /media/ddusb6   vfat    noauto,user,noexec,nodev,nosuid 0 0

- checked /etc/group for "usbstorage" which was here with "hal" user, on which I added my main user.
- Restarted udev.

Now I found

 /dev/ddusb -> sda1

, +

# ls -l /dev/sd*   
brw-rw----  1 root disk    8, 0 2005-11-25 23:48 /dev/sda
brw-rw----  1 root disk    8, 1 2005-11-25 23:48 /dev/sda1
brw-rw----  1 root storage 8, 2 2005-11-25 23:48 /dev/sda2
(...)

It seems I haven't finished with Using udev to map multiple entries to a *partitioned* device :?

Please Archies do you have any ideas or links  :?:


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#2 2005-11-26 01:08:51

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: udev to map multiple entries to *few* *partitioned* devices

You know, everything about that wiki page is correct - except the title. Follow that page, and you get persistent dev naming for multiple devices e.g. you camera will always be /dev/camera, your usb key /dev/key, etc.

Having said that, you're very close. I have three partitions on my usb drive, and my rule looks like this:

BUS=="usb", SYSFS{idProduct}=="8813", KERNEL=="sd?", NAME="%k", SYMLINK+="blaze"
BUS=="usb", SYSFS{idProduct}=="8813", KERNEL=="sd?[1-9]", NAME="%k", SYMLINK+="blaze%n"

The essential details are the number range [1-9] for kernel and the %n for SYMLINK -  I'm also using a different SYSFS tag, but the effect is the same.

You'll also notice == and += in various places. This syntax was introduced since the wiki page was written. Have a look at man udev for full details.

Offline

#3 2005-11-26 10:12:05

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: udev to map multiple entries to *few* *partitioned* devices

I've now added the above to the wiki.

Offline

#4 2005-11-26 18:17:55

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

tomk > again, thank you for your help big_smile

it works fine with

# DD usb
BUS="usb", SYSFS{serial}="DEF1091BE9A1", KERNEL="sd?", NAME="%k", SYMLINK+="ddusb", GROUP="storage"
BUS="usb", SYSFS{serial}="0000:00:05.2", KERNEL="sd?[1-9]", NAME="%k", SYMLINK+="ddusb%n", GROUP="storage"

Also, /dev/sdaN are still created by udev in parallel with /dev/ddusbN.

optional question :
what's the difference between (into /etc/udev/rules.d/00.rules for Arch) :

SYMLINK="_NAME_"

&

SYMLINK+="_NAME_"

?

Note that

/etc/./start_udev

was sufficient to restart udev.


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#5 2005-11-26 19:25:11

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: udev to map multiple entries to *few* *partitioned* devices

Again, glad it was what you needed.

kozaki wrote:

Also, /dev/sdaN are still created by udev in parallel with /dev/ddusbN.

Yeah, the kernel only knows about sda - what udev has done is create persistent symlinks with user-friendly names - ddusb in your case.

kozaki wrote:

what's the difference between (into /etc/udev/rules.d/00.rules for Arch) :

SYMLINK="_NAME_"

&

SYMLINK+="_NAME_"

?

Like I said above, there was a syntax change a few versions ago. Check the wiki page again for an updated multi-partition example, and have a look at man udev for full details.

Offline

#6 2005-11-26 22:36:03

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

I have a few other examples in my custom udev rules:
http://www.archlinux.org/pipermail/arch … 06162.html
Besides creating multiple dev symlinks the rules also create subdirectories in /mnt and /media. They work without any items in fstab and they use mount command with different switches depending on partition type. This way udev is the only thing I need to automount sda devices.

Offline

#7 2005-11-30 15:14:52

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

lanrat > That's interesting !
Why I'm still looking for a clean way to automount any usbkey plugged into an Arch box with xfce4, is beacause of 6 boxes I'm finishig to configure for an association.
I configured them with emelfm2 started with 2 panels : /home/user & /media, so the users just have to clic on their usbkey & (un)mount it, but :
- Test show they find it uneasy. At least if they don't give a look @ the (short) RTFM we did, they're just lost sad
- usbkey suddently stopped to show up in /media since last sunday upgrade !?

2 more questions whenever you pass by :
- Do you add your "Udev rules for sd* automounting without /etc/fstab" into /etc/udev/rules.d/00.rules as well ?
- Do your external usb devices allways show under the same name, as I can see you provide no {serial} or {idProduct} string (maybe not needed if there's only one usbkey plugged at a time) ?


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#8 2005-11-30 16:12:04

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

kozaki wrote:

- Do you add your "Udev rules for sd* automounting without /etc/fstab" into /etc/udev/rules.d/00.rules as well ?

I have 010.udev.rules and x10.udev.rules (with group permission rules). 010.udev.rules is the place where I keep my sd* rules of course. I do not change any of the standard arch udev.rules (it's much easier to maintain this way after udev upgrades).

kozaki wrote:

- Do your external usb devices allways show under the same name, as I can see you provide no {serial} or {idProduct} string (maybe not needed if there's only one usbkey plugged at a time) ?

That's the whole point. I don't care which name they show up. It's probably /dev/sda and /dev/sdb. That's also why I use "usbhdd" prefix. You can of course use the other attributes (serial, product etc) if they show in udevinfo and use different prefixes for usbstics, hard disks etc. This requires only more udev rules for each device. However not all of my devices support additional /sys parameters. For example my external harddisk connected through IDE to USB connector doesn't show much info. But it works with the general sd* scheme.

Offline

#9 2005-11-30 21:29:03

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

Hey lanrat, dude you're the man !

Believe me, the guys will be happier with that automounting big_smile


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#10 2005-11-30 22:00:38

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

As i plug a single usbkey, the udev rules taken as you created them, create a /media/'name1'.
Then I add an external HDD with 4 fat32 partitions, I see /media/'name1', ~2, ~3 & 4, all of them are the HDD partitions ; the usbkey has gone.
ls /dev/sd* is allright :
sda   sda1  sdb   sdb1  sdb2  sdb3  sdb

Why is that, should I add some more lines, like the devices {serial} IDs ?

It's mostly curiosity, as the actual solution filfull the association's needs smile


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#11 2005-12-01 07:45:29

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

It's because I didn't do enough tests with multiple devices :-)

When you plug first device udev creates /dev/sda1, /dev/usbhdp1 and /media/usbhdp1 (which is the mount point for /dev/sda1). When you plug second device udev generates /dev/sdb1 but it mounts it also under /media/usbhdp1. That's why the first device "disappears" from /media.

The problem with naming and mounting sd* devices using udev and ACTION is that you can't use all udev variables (man udev). Only %k (sda, sda1,...) and %n (partition number 1, 2, ...) work for me. If you use other parameters for example %b (bus id) it will work only on "add" action but it won't work on "remove" action (it won't umount the devices and it will not remove symlinks and subdirs). You can rewrite the rules using %k to prevent this.

I've tested this yesterday:

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/usbhd-%k /mnt/usbhd-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/usbhd-%k", OPTIONS="last_rule"

(be careful when pasting this to your custom udev rules file - long lines will probably be wrapped).

This will generate /dev/usbhd-sda, /dev/usbhd-sda1, ..., /dev/usbhd-sdb, /dev/usbhd-sdb1, .... and coresponding directories under /media. You can use any prefix you like in the place of "usbhd". Whatever is convenient for your users. Just remember you can only use %k and/or %n and don't forget to change it in every rule. This is all I've been able to test so far.

Offline

#12 2005-12-09 19:30:13

stavrosg
Member
From: Rhodes, Greece
Registered: 2005-05-01
Posts: 330
Website

Re: udev to map multiple entries to *few* *partitioned* devices

nice! Just adopted it (I had static fstab entries for the most common device names I am using).

Just one question: Judging from the mount options, it should be safe to unplug even a mounted ext3 volume.
But is it? have you tryied doing so?

Offline

#13 2005-12-10 19:59:12

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

lanrat > this "name%k" works really fine with an external HDD with different FS partitions & a usb key big_smile

There's a single (possibly not related) problem : since i unplugged a memory card (RS-MMC 32MB) my phone cannot recognize it ("wrong format"), but Linux has no trouble doing so (same thing after I reformatted it in Fat 16)


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#14 2005-12-10 23:20:02

stavrosg
Member
From: Rhodes, Greece
Registered: 2005-05-01
Posts: 330
Website

Re: udev to map multiple entries to *few* *partitioned* devices

can't you format it from the camera to have it the way it want?

Offline

#15 2005-12-11 04:44:34

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

Just one question: Judging from the mount options, it should be safe to unplug even a mounted ext3 volume.
But is it? have you tryied doing so?

Well, I tried to put as many safety options as possible and as other people advised them. For me they seem to work. I never had problems. But I don't have many storage devices to test them so use it at your own risk :-) Theoretically it should work even if dmesg complains about unclean umounting. Have in mind however that even in windows you should "manually" umount a storage device before you unplug it. It never destroyed any of my files though.

There's a single (possibly not related) problem : since i unplugged a memory card (RS-MMC 32MB) my phone cannot recognize it ("wrong format"), but Linux has no trouble doing so (same thing after I reformatted it in Fat 16)

Yeah, this could be unrelated. These kind of devices are known for problems with formatting from windows/linux or from a device itself. Try formatting it from the device or windows if you can.

Offline

#16 2005-12-11 04:41:44

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: udev to map multiple entries to *few* *partitioned* devices

lanrat wrote:

There's a single (possibly not related) problem : since i unplugged a memory card (RS-MMC 32MB) my phone cannot recognize it ("wrong format"), but Linux has no trouble doing so (same thing after I reformatted it in Fat 16)

Yeah, this could be unrelated. These kind of devices are known for problems with formatting from windows/linux or from a device itself. Try formatting it from the device or windows if you can.

Perhaps reformat it so the device still recognizes it, then plug it in and remove it from the linux box, without writing anything to it - should help diagnose if it is related in anyway to the umounting.

Offline

#17 2005-12-11 23:38:25

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

stavrosg, phrakture > I wanted to do so but the cell phone dis print some uncomprehensible "Locked code" string. Therafter I reformatted it from windoz when i booted this OS, and the phone did accept the card then.

I had backup of the card content, so there was nothing lost in this location

lanrat > you guessed it the right way smile


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#18 2005-12-13 18:33:00

kozaki
Member
From: London >. < Paris
Registered: 2005-06-13
Posts: 671
Website

Re: udev to map multiple entries to *few* *partitioned* devices

I did not test enough an Udev rule i tried to (u)mount my external drives & keys on a 100% Udev base. And this made Udev be confused between the internal SATA HDD (/dev/sda) & the external IDE USB HDD (also called /dev/sda !)
Checking cat /proc/mounts after boot process didn't give any usefull infos, but last time I booted & was stucked then typed root passwd for maintenance, cat /proc/mounts revealed that external IDE USB HDD was mounted in /dev/sdaN 

Removed this rule and my box returned to KISS 

lanrat > I still consider your hacked rule as a great one. Only Sata sucks my life in some way (think udev, hdparm, etc)

lanrat wrote:

Oh, you're right I was testing the rules on my IDE system only. The easy way is to change [a-z] to something like [b-z] and leave your internal sata hdd (/dev/sda) to be handled by standard arch udev rules.

Yeap, seems to work in this location smile (also deleted /media/ & /mnt/ links & directories related to sda (& i believe i understand Udev rules near to 0%, else could i have adapted lanrat nice rule lol )


Seeded last month: Arch 50 gig, derivatives 1 gig
Desktop @3.3GHz 8 gig RAM, linux-ck
laptop #1 Atom 2 gig RAM, Arch linux stock i686 (6H w/ 6yrs old battery smile) #2: ARM Tegra K1, 4 gig RAM, ChrOS
Atom Z520 2 gig RAM, OMV (Debian 7) kernel 3.16 bpo on SDHC | PGP Key: 0xFF0157D9

Offline

#19 2005-12-19 06:14:25

M6
Member
Registered: 2005-09-18
Posts: 29

Re: udev to map multiple entries to *few* *partitioned* devices

Hi ,
I am using Lanrat's  Udev Automounting rule below:

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd-%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhd-%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/usbhd-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/usbhd-%k /mnt/usbhd-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usbhd-%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/usbhd-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/usbhd-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/usbhd-%k", OPTIONS="last_rule"

It works well for my ExtHD, USB KEY and MP3 Player.

Every time I connect Iget:

/media/usbhd-sda1
/media/usbhd-sda2
/media/usbhd-sdb1 ...etc;

I'd like to get it connected:
/media/usbhd-ExtHd-1
/media/usbhd-ExtHd-2
/media/usbhd-Mp3Ply
/media/usbhd-USBKey

I tried to add :
SYSFS{product}=="Flash Disk " ===>USB MEmory Stick
SYSFS{product}=="<USB PRODUCT> " ===>Mp3 Player
SYSFS{product}=="USB TO IDE" ===>Ext HD(multiple partitions)

SYMLINK+="USB-HDp%n"
SYMLINK+="Mp3-%n" ...etc


to above  rule but It doesn't seems be working. I don't think I understand udev rules correctly.

Any input is much appreciated.
Thanking you in advance.

Ben


Arch a Day Keeps Wfie Away

Offline

#20 2005-12-20 03:45:56

M6
Member
Registered: 2005-09-18
Posts: 29

Re: udev to map multiple entries to *few* *partitioned* devices

Thanks for the reply Lanrat. I followed your advice and now I have

/media/ Mp3-sda1   (Mp3)
/media/USBHD-sdb1   (Ext HD with multiple partitions)
/media/ USBHD-sdb2
/media/ USBHD-sdb3 

I do have a problem with my USB Memory stck.

[root@localhost ~]# ls -l /dev|grep sd
lrwxrwxrwx  1 root root         3 2005-12-20 00:23 USB-sda -> sda
lrwxrwxrwx  1 root root         4 2005-12-20 00:23 USB-sda1 -> sda1
lrwxrwxrwx  1 root root         3 2005-12-20 00:23 USB-sdb -> sdb
lrwxrwxrwx  1 root root         4 2005-12-20 00:23 USB-sdb1 -> sdb1
lrwxrwxrwx  1 root root         4 2005-12-20 00:23 USB-sdb2 -> sdb2
lrwxrwxrwx  1 root root         4 2005-12-20 00:23 USB-sdb3 -> sdb3
lrwxrwxrwx  1 root root         3 2005-12-20 01:17 USB-sdc -> sdc
brw-rw----  1 root users    8,  0 2005-12-20 00:23 sda
brw-rw----  1 root users    8,  1 2005-12-20 00:23 sda1
brw-rw----  1 root users    8, 16 2005-12-20 00:23 sdb
brw-rw----  1 root users    8, 17 2005-12-20 00:23 sdb1
brw-rw----  1 root users    8, 18 2005-12-20 00:23 sdb2
brw-rw----  1 root users    8, 19 2005-12-20 00:23 sdb3
brw-rw----  1 root users    8, 32 2005-12-20 01:17 sdc
[root@localhost ~]#

As you can see  sdc (Memory Stick) doesn't creat /dev/sdc1

I did copy and paste SYSFS{product}=="Flash Disk      " and make sure the spaces are correct.
udevinfo -a -p /sys/block/sdc  <====Memory Stick
    BUS=="scsi" <<<<<<<<<<<<<<<<<<<
    ID=="5:0:0:0"
    DRIVER=="sd"
    SYSFS{device_blocked}=="0"
    SYSFS{iocounterbits}=="32"
    SYSFS{iodone_cnt}=="0x19"
    SYSFS{ioerr_cnt}=="0x18"
    SYSFS{iorequest_cnt}=="0x19"
    SYSFS{max_sectors}=="240"
    SYSFS{model}=="Flash Disk      "
    SYSFS{queue_depth}=="1"
    SYSFS{queue_type}=="none"
    SYSFS{rev}=="2.00"
    SYSFS{scsi_level}=="3"
    SYSFS{state}=="running"
    SYSFS{timeout}=="30"
    SYSFS{type}=="0"
    SYSFS{vendor}=="OTi     "


udevinfo -a -p /sys/block/sda  (Mp3 Player)

    BUS=="usb"
    ID=="1-1.3"
    DRIVER=="usb" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    SYSFS{bConfigurationValue}=="1"
    SYSFS{bDeviceClass}=="00"
    SYSFS{bDeviceProtocol}=="00"
    SYSFS{bDeviceSubClass}=="00"
    SYSFS{bMaxPacketSize0}=="64"
    SYSFS{bMaxPower}=="100mA"
    SYSFS{bNumConfigurations}=="1"
    SYSFS{bNumInterfaces}==" 1"
    SYSFS{bcdDevice}=="1001"
    SYSFS{bmAttributes}=="c0"
    SYSFS{configuration}=="USB/MSC LCD Player"
    SYSFS{devnum}=="3"
    SYSFS{idProduct}=="5512"
    SYSFS{idVendor}=="1462"
    SYSFS{manufacturer}=="<USB MF>"
    SYSFS{maxchild}=="0"
    SYSFS{product}=="<USB PRODUCT>   "
    SYSFS{serial}=="0000410536D48894"
    SYSFS{speed}=="12"
    SYSFS{version}==" 1.10"

I can see there are a lot of rules in udev.rules (Arch Default) for BUS=SCSI but none of the create sdc1.

could you show me how to incoporate BUS=SCSI to these automounting rules please.

Thanks
Ben

I've put this in the forum as well

==================================================================================
KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="USB-%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="USB-%k", GROUP="users", NAME="%k"
#ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/USB-%k"
#New Rules Product Specific
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="<USB PRODUCT>   ", RUN+="/bin/mkdir -p /media/Mp3-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="Flash Disk      ", RUN+="/bin/mkdir -p /media/USBKey-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="USB TO IDE", RUN+="/bin/mkdir -p /media/USBHD-%k"

ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/Mp3-%k /mnt/Mp3-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k /media/Mp3-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/Mp3-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/Mp3-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/Mp3-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/Mp3-%k"

ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/USBKey-%k /mnt/USBKey-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k /media/USBKey-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/USBKey-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/USBKey-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/USBKey-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/USBKey-%k"

ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/USBHD-%k /mnt/USBHD-%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k /media/USBHD-%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/USBHD-%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/USBHD-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/USBHD-%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/USBHD-%k", OPTIONS="last_rule"


Arch a Day Keeps Wfie Away

Offline

#21 2005-12-20 14:26:28

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

Memory stick readers are a special case for udev:

Another difficult situation is having a multiple-slot USB-storage card reader. These types of device generally do not inform the host when new cards are plugged in or out, so plugging a card into an unused slot while the reader is plugged in will not create the extra device node needed for mounting!
This problem also applies to other USB disks - e.g. if you create a new partition, the new partition node will not appear until you re-plug the device.

udev provides a solution here - it is able to create nodes for all partitions of a block device. For every rule that you specify, the block device will have all 16 partition nodes created. To achieve this, you can simply modify the NAME key, as shown below:

BUS="usb", SYSFS{product}="USB 2.0 Storage Device", NAME{all_partitions}="usbhd"
You will now have nodes named: usbhd, usbhd1, usbhd2, usbhd3, ..., usbhd15.

That's probably the reason why you have only /dev/sdc and no partitions. Only the reader is recognized. Plugging memory stick does not generate udev event and it can't be handled dynamically. In this case, I think you can only create one simple udev rule for the memory stick reader that creates all partitions but doesn't mount/umount them. It should create /dev/sdc1-16 and mounting should be done "manually".

Unless of course your memory stick does generate hotplug event. You can try to write a very simple, single test rule only for sdc1, place it at the top of your custom udev rules file with OPTIONS="last_rule" and see if it appears in /dev when you plug the stick into the reader.

If it works post udevinfo for /dev/sdc1 (you don't have multiple partitions on your memory stick, do you?).

----------------------

For the record:
I'm posting my answer to the previous M6' post (it was a PM originally):

Every time I connect Iget:

/media/usbhd-sda1
/media/usbhd-sda2
/media/usbhd-sdb1 ...etc;

I'd like to get it connected:
/media/usbhd-ExtHd-1
/media/usbhd-ExtHd-2
/media/usbhd-Mp3Ply
/media/usbhd-USBKey

Sometimes it's very hard to do this. It depends on a device type and how much info is available through /sys.

I tried to have usbhd0_partition1 or something like this but it worked only for the mount part. It didn't worked at all for umount part. Only %k (sda1 etc.) worked ok with umounting. I guess that's how it works when a device is already physically unplugged (%n returns an empty string).

I tried to add :
SYSFS{product}=="Flash Disk " ===>USB MEmory Stick
SYSFS{product}=="<USB PRODUCT> " ===>Mp3 Player
SYSFS{product}=="USB TO IDE" ===>Ext HD(multiple partitions)

I assume you have "product" info from udevinfo and it is correct and you created a separate rule for each device. I mean you duplicated my rules adding only SYSFS stuff (BTW SYMLINK part is not really important. Forget about it for the moment).

For example:

 
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="Flash Disk      ", RUN+="/bin/mkdir -p /media/UsbKey-%k" 

and so on...

At least at the begining do not use anything other than %k. If you really need to extract partition number use some standard linux tool to cut the last char (the number) from "sda1".

For example:

RUN+="/bin/mkdir -p /media/UsbKey`/bin/echo %k | /bin/tr -d a-z`"

will produce /media/UsbKey1
or

RUN+="/bin/mkdir -p /media/UsbKey-`/bin/echo %k | /bin/tr -d sd`"

will produce /media/UsbKey-a1 (better for multiple usbkeys).

This should ensure it will work for both mounting and umouting.

But first try to introduce only SYSFS field to check if it works only for usbkeys and creates /media/UsbKey-sda1 instead of /media/usbhd-sda1.

Some devices do not return much info via sysfs or it's not usefull for udev rules. My ide-usb connector for hard disks shows almost nothing. I can't use any info to produce any working general rule for usb harddisks. There are some things you should know about using sysfs info in udev rules. Not everything can be used and information from different sections can't be mixed. For more info read "writing udev rules" manual. It's for 0.6 and since this version there were many udev versions released so not everything might be correct. But it's better than nothing.

There is also another way to rename devices. Current udev has many tools (like vol_id) that can be used to identify a device and/or rename to something more readable. Unfortunatelly there is very little or none info how to use them. You can try to find how it works by disabling your custom rules for the moment and use standard arch rules (they're copied from gentoo rules in large part) and let it assign some friendly names. Plug in your usbkey and see what is available in /dev/discs etc. These names are produced by default rules at the bottom of standard arch /etc/udev/rules.d/udev.rules file. They are using different udev tools with nice options like replacing spaces with underscore etc. but they are overcomplicated IMO and I doubt you'll be able to use them for umouting.

That's all I can advice you now. If you have troubles with using sysfs info post all output of udevinfo for your devices. I can try to write some test rule for my usb stick later at home but it's an ordinary usb stick and doesn't have much info in /sys.

Offline

#22 2005-12-21 02:08:30

M6
Member
Registered: 2005-09-18
Posts: 29

Re: udev to map multiple entries to *few* *partitioned* devices

lanrat wrote:

Memory stick readers are a special case for udev:

Another difficult situation is having a multiple-slot USB-storage card reader.

Hi,
Strange enough I plugged all the devices this morning and they all mount/unmount correctly. (I can't explain this) I repeated this many times and re booted the PC to make sure this is not a fluke.

[root@localhost ~]# ls -l /media
total 22
drwxrwxrwx   2 root root  1024 1970-01-01 10:00 Mp3-sda1
drwxr-xr-x     4 root root  1024 2005-12-12 14:48 USBHD-sdc1
drwxr-xr-x      2 root root    48 2005-12-20 23:54 USBHD-sdc2
drwxr-xr-x  18 root root  4096 2005-12-12 16:18 USBHD-sdc3
drwxrwxrwx   2 root root 16384 1970-01-01 10:00 USBKey-sdb1

This is very good.

Now I am trying to get

/media/Mp3-1
/Media/USBKey-1
/Media/USBHD-1
/Media/USBHD-2
/Media/USBHD-3

I've tried  below line (and commented the previous line)

ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="<USB PRODUCT>   ", RUN+="/bin/mkdir -p /media/Mp3-`/bin/echo %k | /bin/tr -d a-z`"

Then it doesn't get mounted. I found below error in /var/daemon.log
Dec 20 23:37:05 localhost udev[8476]: create_node: creating symlink '/dev/USB-sda1' to 'sda1'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mkdir -p /media/Mp3-`/bin/echo sda1 | /bin/tr -d a-z`'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mkdir' (stderr) '/bin/mkdir: invalid option -- d'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mkdir' (stderr) 'Try `/bin/mkdir --help' for more information.'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mkdir' returned with status 1
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/ln -s /media/Mp3-sda1 /mnt/Mp3-sda1'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/ln' returned with status 0
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mount -t vfat -o rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/sda1 /media/Mp3-sda1'

Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mount' (stderr) 'mount: mount point /media/Mp3-sda1 does not exist'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mount' returned with status 32
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/sda1 /media/Mp3-sda1'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mount' (stderr) 'mount: mount point /media/Mp3-sda1 does not exist'
Dec 20 23:37:05 localhost udev[8476]: run_program: '/bin/mount' returned with status 32

But when I tried this line in a terminal it crates /media/Mp3-999 dir.
/bin/mkdir -p /media/Mp3-`/bin/echo sda999 | /bin/tr -d a-z`

I tried without -d
[root@localhost ~]# ls -l /media
total 21
drwxr-xr-x   3 root root    72 2005-12-21 00:02 Mp3-`

I cheked the man page for tr but can't figureout the combination to use.

Could you give this a try please.

Thank you

Ben


Arch a Day Keeps Wfie Away

Offline

#23 2005-12-21 13:22:06

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

Hmm. Looks like we need additional escaped doublequotes. Try this:

ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="<USB PRODUCT> ", RUN+="/bin/mkdir -p "/media/Mp3-`/bin/echo %k | /bin/tr -d a-z`"" 

I'm not 100% sure it will work from an udev rule.

Offline

#24 2005-12-22 12:15:25

M6
Member
Registered: 2005-09-18
Posts: 29

Re: udev to map multiple entries to *few* *partitioned* devices

lanrat wrote:

Hmm. Looks like we need additional escaped doublequotes. Try this:

ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="<USB PRODUCT> ", RUN+="/bin/mkdir -p "/media/Mp3-`/bin/echo %k | /bin/tr -d a-z`"" 

I'm not 100% sure it will work from an udev rule.

Sorry Lanrat this doesn't work either.

Is it possible to add another commend when a usb device is plugged in a file manages opens up?

(I'd rather not use ivman)

Regards
Ben


Arch a Day Keeps Wfie Away

Offline

#25 2005-12-28 01:36:03

lanrat
Member
From: Poland
Registered: 2003-10-28
Posts: 1,274

Re: udev to map multiple entries to *few* *partitioned* devices

M6 wrote:
lanrat wrote:

Hmm. Looks like we need additional escaped doublequotes. Try this:

ACTION=="add", KERNEL=="sd[a-z][0-9]", SYSFS{product}=="<USB PRODUCT> ", RUN+="/bin/mkdir -p "/media/Mp3-`/bin/echo %k | /bin/tr -d a-z`"" 

I'm not 100% sure it will work from an udev rule.

Sorry Lanrat this doesn't work either.

Any results in log files?

M6 wrote:

Is it possible to add another commend when a usb device is plugged in a file manages opens up?

(I'd rather not use ivman)

Theoretically it's possible to run any command from udev. You can try adding another rule with RUN+= filed after the last rule with mount and action=add. There are some problems though. First udev will run the command as root. You could use sudo in the rule or something to change the permissions. Udev also doesn't know if you're running X or not. This can be checked but it'll probably require a full script. But there shouldn't be any bad effects except errors in logs if you run a file manager without X (I'm guessing a lot of things here...). There are other things that might not work well like multiple displays, multiple users, etc. etc. The only way to check if it works is to add another RUN rule (as simple as possible) and see for yourself :-)

Offline

Board footer

Powered by FluxBB