Tux

...making Linux just a little more fun!

udev rules ca't auto mount my pen drive

J. Bakshi [j.bakshi at unlimitedmail.org]


Sat, 4 Apr 2009 00:44:46 +0530

Hello,

Hope you all are well.

Recently my attention is on udev rules. I was never bothered about it but during google search to find out how to automount my pendrive; I have found udev as the solution. I admit that I don't understand it properly but my intention to mount my pendrive to a pre-defined mount point pushed me to do some experiment with it. I have first collected the required information by *udevinfo -a -p $(udevinfo -q path -n /dev/sda)*

looking at device '/block/sda':

    KERNEL=="sda"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{range}=="16"
    ATTR{removable}=="1"
    ATTR{size}=="15687680"
    ATTR{stat}=="      77      421     2292     1436        0
0        0        0        0      956     1436" ATTR{capability}=="13"

looking at parent device

'/devices/pci0000:00/0000:00:10.3/usb4/4-5/4-5:1.0/host7/target7:0:0/7:0:0:0':
KERNELS=="7:0:0:0" SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{device_blocked}=="0"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="3"
    ATTRS{vendor}=="JetFlash"
    ATTRS{model}=="Transcend 8GB   "
    ATTRS{rev}=="8.07"

<snip>

lots of other stuff

</snip>

Then I constructed my rules as

10-usb.rules
--------------------------------
SUBSYSTEM=="block", KERNEL=="sda", ATTRS{vendor}=="JetFlash",
ATTRS{model}=="Transcend 8GB   ", ACTION=="add", RUN+="mount -t
reiserfs /dev/sda2 /mnt/pen"
-------------------------------------

/mnt/usb is already there. From /var/log/syslog I can confirm that 10-usb.rules has been read with out any error

---------------------------------------
debian udevd[2874]: parse_file: reading
'/etc/udev/rules.d/10-usb.rules' as rules file
-----------------------------------------------

but after inserting my pendrive it is not auto mounted at /mnt/pen.

I have no clue if my rule is wrong or any thing else is preventing the auto mount. My box is debian lenny.

Could any one please enlighten me ?

Thanks,

PS: please CC to me


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Sat, 4 Apr 2009 15:41:33 -0400

On Sat, Apr 04, 2009 at 12:44:46AM +0530, J. Bakshi wrote:

> 
> Recently my attention is on udev rules. I was never bothered about it
> but during google search to find out how to automount my pendrive; I
> have found udev as the solution. I admit that I don't understand it
> properly but my intention to mount my pendrive to a pre-defined mount
> point pushed me to do some experiment with it. I have first collected
> the required information by   *udevinfo -a -p $(udevinfo -q path
> -n /dev/sda)*

[snip]

> Then I constructed my rules as
> 
> 10-usb.rules

Mistake #1: user-constructed rules aren't supposed to happen that early. I recommend reading '/etc/udevd/README':

Files should be named xx-descriptive-name.rules, the xx should be
chosen first according to the following sequence points:
 
  00   rules that it is critical to be run first, usually
       only WAIT_FOR_SYSFS
 
  20   rules that change the name from the device from the default
       (cannot be overriden)
 
  40   rules that set the permissions of device nodes
       (can be overriden by later rules)
 
  60   rules that add symlinks to device nodes
       (adds to those set in earlier rules)
 
  80   rules that run programs (but do not load modules)
 
  90   rules that load modules
 
  99   rules that it is critical to be run last
 
 
This scheme has been chosen so that user-supplied rules are normally
named 50-*.rules for the right thing to happen.
 
Packages should chose the approriate sequence point and add 5 to it
(e.g. 25-iftab.rules, 45-libsane.rules, etc.) unless there is a need
for a particular order.
> --------------------------------
> SUBSYSTEM=="block", KERNEL=="sda", ATTRS{vendor}=="JetFlash",
> ATTRS{model}=="Transcend 8GB   ", ACTION=="add", RUN+="mount -t
> reiserfs /dev/sda2 /mnt/pen"
> -------------------------------------

I'd suggest you examine some of the other rulesets in /etc/udevd. Note, for one thing, that none of them run "mount" explicitly; it's very unlikely that you need to either.

> but after inserting my pendrive it is not auto mounted at /mnt/pen.
> 
> I have no clue if my rule is wrong or any thing else is preventing the
> auto mount. My box is debian lenny.
> 
> Could any one please enlighten me ?

I recently had to do this for a USB GPS, and found the "udev" methods unpleasantly dense and cryptic to work with, and the docs annoyingly sparse. Lots of other people seem to like it. [shrug]

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *


Top    Back


J. Bakshi [j.bakshi at unlimitedmail.org]


Sun, 5 Apr 2009 21:08:32 +0530

On Sat, 4 Apr 2009 15:41:33 -0400 Ben Okopnik <ben@linuxgazette.net> wrote:

> Mistake #1: user-constructed rules aren't supposed to happen that
> early. I recommend reading '/etc/udevd/README':
> 
> ``
> Files should be named xx-descriptive-name.rules, the xx should be
> chosen first according to the following sequence points:
> 
>   00   rules that it is critical to be run first, usually
>        only WAIT_FOR_SYSFS
> 
>   20   rules that change the name from the device from the default
>        (cannot be overriden)
> 
>   40   rules that set the permissions of device nodes
>        (can be overriden by later rules)
> 
>   60   rules that add symlinks to device nodes
>        (adds to those set in earlier rules)
> 
>   80   rules that run programs (but do not load modules)
> 
>   90   rules that load modules
> 
>   99   rules that it is critical to be run last
> 
> 
> This scheme has been chosen so that user-supplied rules are normally
> named 50-*.rules for the right thing to happen.
> 
> Packages should chose the approriate sequence point and add 5 to it
> (e.g. 25-iftab.rules, 45-libsane.rules, etc.) unless there is a need
> for a particular order.
> ''
> 
> > --------------------------------
> > SUBSYSTEM=="block", KERNEL=="sda", ATTRS{vendor}=="JetFlash",
> > ATTRS{model}=="Transcend 8GB   ", ACTION=="add", RUN+="mount -t
> > reiserfs /dev/sda2 /mnt/pen"
> > -------------------------------------
> 
> I'd suggest you examine some of the other rulesets in /etc/udevd.
> Note, for one thing, that none of them run "mount" explicitly; it's
> very unlikely that you need to either.

Thanks a lot for your nice explanation. In the mean time I have found another nice tool called "pmount" in debian which supports userspace mount operation if the user belongs to plugdev group and it mounts under /media. But I'm still trying to fix udev which can do automount with out user intervention. If there will be any progress I'll come back with the information.

thanks


Top    Back