LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 10-17-2007, 06:31 PM   #1
njnear
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Rep: Reputation: 0
Trying to use udev to auto mount usb drive



I am trying to get Ubuntu to automatically mount my attache USB drive using udev.

After inserting the drive, I expect to see the name "attache" (based on the rule) in the /dev directory, but I get nothing. However, I can mount the drive manually using the /dev/sda1 device.

Any suggestions?

This is my /etc/udev/rules.d/86-local.rules file:

BUS="usb", SYSFS{serial}="0E506950402358AB", SYSFS{model}="USB Flash Memory", NAME="attache", SYMLINK="attache-lnk"

===============
This is the output of: uname -a
Linux lepton 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006 i686 GNU/Linux

===============
This is my Distro:
Ubuntu, kernel 2.6.17-10-generic

===============
This is the output of: udevinfo -a -p /block/sda/sda1

udevinfo starts with the device the node belongs to and then walks up the
device chain, to print for every device found, all possibly useful attributes
in the udev key format.
Only attributes within one device section may be used together in one rule,
to match the device for which the node will be created.

looking at device '/block/sda/sda1':
KERNEL=="sda1"
SUBSYSTEM=="block"
SYSFS{stat}==" 192 1536 0 0"
SYSFS{size}=="1001440"
SYSFS{start}=="32"
SYSFS{dev}=="8:1"

looking at device '/block/sda':
ID=="sda"
BUS=="block"
DRIVER==""
SYSFS{stat}==" 110 87 1576 252 0 0 0 0 0 252 252"
SYSFS{size}=="1001472"
SYSFS{removable}=="1"
SYSFS{range}=="16"
SYSFS{dev}=="8:0"

looking at device '/devices/pci0000:00/0000:00:10.3/usb4/4-5/4-5:1.0/host12/target12:0:0/12:0:0:0':
ID=="12:0:0:0"
BUS=="scsi"
DRIVER=="sd"
SYSFS{ioerr_cnt}=="0x2"
SYSFS{iodone_cnt}=="0x416"
SYSFS{iorequest_cnt}=="0x416"
SYSFS{iocounterbits}=="32"
SYSFS{timeout}=="30"
SYSFS{state}=="running"
SYSFS{rev}=="1.04"
SYSFS{model}=="USB Flash Memory"
SYSFS{vendor}==" "
SYSFS{scsi_level}=="3"
SYSFS{type}=="0"
SYSFS{queue_type}=="none"
SYSFS{queue_depth}=="1"
SYSFS{device_blocked}=="0"
SYSFS{max_sectors}=="240"

looking at device '/devices/pci0000:00/0000:00:10.3/usb4/4-5/4-5:1.0/host12/target12:0:0':
ID=="target12:0:0"
BUS==""
DRIVER==""

looking at device '/devices/pci0000:00/0000:00:10.3/usb4/4-5/4-5:1.0/host12':
ID=="host12"
BUS==""
DRIVER==""

looking at device '/devices/pci0000:00/0000:00:10.3/usb4/4-5/4-5:1.0':
ID=="4-5:1.0"
BUS=="usb"
DRIVER=="usb-storage"
SYSFS{modalias}=="usb:v0930p6533d0100dc00dsc00dp00ic08isc06ip50"
SYSFS{bInterfaceProtocol}=="50"
SYSFS{bInterfaceSubClass}=="06"
SYSFS{bInterfaceClass}=="08"
SYSFS{bNumEndpoints}=="03"
SYSFS{bAlternateSetting}==" 0"
SYSFS{bInterfaceNumber}=="00"

looking at device '/devices/pci0000:00/0000:00:10.3/usb4/4-5':
ID=="4-5"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{serial}=="0E506950402358AB"
SYSFS{product}=="USB Flash Memory"
SYSFS{maxchild}=="0"
SYSFS{version}==" 2.00"
SYSFS{devnum}=="15"
SYSFS{speed}=="480"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bNumConfigurations}=="1"
SYSFS{bDeviceProtocol}=="00"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="00"
SYSFS{bcdDevice}=="0100"
SYSFS{idProduct}=="6533"
SYSFS{idVendor}=="0930"
SYSFS{bMaxPower}=="200mA"
SYSFS{bmAttributes}=="80"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"

looking at device '/devices/pci0000:00/0000:00:10.3/usb4':
ID=="usb4"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{serial}=="0000:00:10.3"
SYSFS{product}=="EHCI Host Controller"
SYSFS{manufacturer}=="Linux 2.6.17-10-generic ehci_hcd"
SYSFS{maxchild}=="6"
SYSFS{version}==" 2.00"
SYSFS{devnum}=="1"
SYSFS{speed}=="480"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bNumConfigurations}=="1"
SYSFS{bDeviceProtocol}=="01"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="09"
SYSFS{bcdDevice}=="0206"
SYSFS{idProduct}=="0000"
SYSFS{idVendor}=="0000"
SYSFS{bMaxPower}==" 0mA"
SYSFS{bmAttributes}=="e0"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"

looking at device '/devices/pci0000:00/0000:00:10.3':
ID=="0000:00:10.3"
BUS=="pci"
DRIVER=="ehci_hcd"
SYSFS{modalias}=="pci:v00001106d00003104sv00001106sd00003104bc0Csc03i20"
SYSFS{local_cpus}=="ff"
SYSFS{irq}=="169"
SYSFS{class}=="0x0c0320"
SYSFS{subsystem_device}=="0x3104"
SYSFS{subsystem_vendor}=="0x1106"
SYSFS{device}=="0x3104"
SYSFS{vendor}=="0x1106"

looking at device '/devices/pci0000:00':
ID=="pci0000:00"
BUS==""
DRIVER==""



 
Old 10-17-2007, 07:40 PM   #2
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
AFAIK udev does not mount a USB device. It detects it, gives it a standard device name and assigns a major and minor number to it.

To mount a USB device automatically use /etc/fstab

To check a USB device detected at a hardware level use root console command "fdisk -l"

To mount a USB device sdb1 manually, make a directory in /mnt by "mkdir /mnt/sdb1" and mount it by "mount /dev/sdb1 /mnt/sdb1" in root console.

A USB device can only be mounted after it has been formatted.
 
Old 10-17-2007, 09:18 PM   #3
njnear
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Original Poster
Rep: Reputation: 0
I think I used the wrong terminology. I didn't mean that I'm expecting udev to mount the device (though that is what I said, isn't it). I mean, udev is not assigning the device name that I am asking it to. Based on the rule I show below, I'm expecting the name "attache" to be listed, rather than /dev/sda1. (Or maybe in addition to?)
 
Old 10-18-2007, 02:34 AM   #4
saikee
Senior Member
 
Registered: Sep 2005
Location: Newcastle upon Tyne UK
Distribution: Any free distro.
Posts: 3,398
Blog Entries: 1

Rep: Reputation: 112Reputation: 112
Just out of curiosity why you think Linux must call it "attache" and not /dev/sda1?

There are thousands USB devices out there and the drivers in Linux is always generic. Remember you don't need to feed a manufacturer's driver to a Linux in such case.

To Linux your USB device is just a block device. Do you have a problem using it? or rather to mount it on /attache in the filing system after making the directory /attache? Although generally one would mount it as /mnt/attache.

When you are actually working files in the device the /dev/<whatever name> is not used.
 
Old 10-18-2007, 09:44 PM   #5
njnear
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Original Poster
Rep: Reputation: 0
I don't so much care what the device is named. I realize I can name the symlink to the device whatever I want and use that to mount the drive. In this case, I was just naming the device for practice and using a name that sticks out. After a LOT of digging, I found that my rules had a plethora of syntax errors. So, I fixed them and it works now.

Thanks for the help, though!

Just for posterity, here's my "newer and better" rules:

#PNY Attache USB drive
KERNEL=="sd[a-z]1", SYSFS{serial}=="0E506950402358AB", SYSFS{product}=="USB Flash Memory", NAME="%k", SYMLINK+="usb/attache"
KERNEL=="sd[a-z]1", SYSFS{serial}=="0E506950402358AB", SYSFS{product}=="USB Flash Memory", RUN+="/root/usbbeep"
#ATP Petito USB drive
SYSFS{size}=="2012160", NAME="%k", SYMLINK+="usb/petito"
SYSFS{size}=="2012160", RUN+="/root/usbbeep2"

The Petito is strange. When it's plugged in, two "sd" devices show up. So, the only unique attribute I could find between the two was the SYSFS{size} attribute. I've never seen that before.
 
Old 12-04-2007, 01:53 AM   #6
pillarsdotnet
LQ Newbie
 
Registered: Dec 2007
Location: Norfolk, Virginia
Distribution: gentoo
Posts: 6

Rep: Reputation: 1
Lightbulb

I solved the same problem you did, but (I hope) in a more generic way that is not relying on a particular device type. Here's how I did it:

Find an existing udev rule that is launched after the your usb partition node is created. For me, the rule was in /etc/udev/rules.d/60-persistent-storage.rules, and it looked like this:
Code:
ENV{DEVTYPE}=="partition", IMPORT{program}="vol_id --export $tempnode"
Modify the rule to run mount/unmount scripts of your choosing, like
this:
Code:
ENV{DEVTYPE}=="partition", IMPORT{program}="vol_id --export $tempnode", RUN+="/lib/udev/usb_mount", ENV{REMOVE_CMD}="/lib/udev/usb_unmount"
Write the mount/unmount scripts. Here is my /lib/udev/usb_mount script:
Code:
#!/bin/sh
[ "$ACTION" = "add" -a "$DEVTYPE" = "partition" -a "$ID_BUS" = "usb" ] || exit 0
MNTDIR=/mnt/auto/${DEVNAME##/dev/}
chown root:usb "$DEVNAME"
chmod 0660 "$DEVNAME"
mkdir $MNTDIR
/bin/mount -t $ID_FS_TYPE  $DEVNAME $MNTDIR -o noatime,noexec,nosuid,nodev,nodiratime,nosuid,rw,umask=0,dmask=0,fmask=111,uid=65534,gid=65534
... and here is my /lib/udev/usb_unmount script:
Code:
#!/bin/sh
[ "$ACTION" = "remove" ] && (grep -q "^$DEVNAME" /proc/mounts || grep -q "^$DEVNAME" /etc/mtab) || exit 0
/bin/umount -l "$DEVNAME"
rmdir /mnt/auto/${DEVNAME##/dev/}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get utf8 support for auto mount by hal(udev)? notsay Slackware 5 03-22-2008 02:59 PM
got my ntfs sata drive to mount but cat get to auto mount Jack Daniels Linux - Hardware 3 04-15-2007 10:42 AM
SuSE 9.3 USB Flash Drive Auto Mount Stopped Working nuro305 Linux - Hardware 11 04-15-2007 05:21 AM
auto mount usb drive jag Slackware 3 07-28-2006 03:09 AM
udev, USB Flash Drives, and usb-mount talkingwires Debian 13 11-07-2004 12:15 PM


All times are GMT -5. The time now is 05:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration