Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
HOWTO Fully Automated USB mounting using udev [WIP]
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
MHenry676
Tux's lil' helper
Tux's lil' helper


Joined: 02 Aug 2004
Posts: 125

PostPosted: Sun Jun 19, 2005 3:57 am    Post subject: HOWTO Fully Automated USB mounting using udev [WIP] Reply with quote

Well, after a few day playing with this, I'm finally happy with what I got working, especially seeing that my experience with Linux is about 3 months (1st month of time spread out over the last few years, last 2 months straight Gentoo). This is my first HOWTO, so please be understanding.

Summary:
This is a HOWTO for having udev automatically mount USB flash drives, create the mount point for it, and create a KDE Desktop link when such device is plugged into a USB port. When it is removed, the script will unmount the drive, remove the mount point, and remove the Desktop Icon for it. No entry in /etc/fstab needs to be defined, unless a device is to be handle in a specific way. I have included the portion of the script with my camera as an example of this. No extra auto-mount services, such as pmount, usbmount, or ivman are used. I will breakdown the script and explain what is needed to define a specific device and what is not needed if you just want it to handle USB flash devices generically. Note: I have not worked on getting USB Hard drives to work properly with this. Follow the references at the end of this post for information on this.

This is written for the experienced and the noob alike. From a noob.

Foreword:
I've been using Gentoo (using livecd 2005.0) for the last two months straight. I've been doing Windows (or has Windows been doing me?) for years. I tried it last year, but never got too far (M$ kept sucking me back.) Then after being inspired by an article in Maximum PC about the writer of the article about how he went to straight Linux, I decided to go full Gentoo. The writer had used Debian (he mentioned Gentoo briefly.) There was a time during my installation of Gentoo that I did have a problem, and proceeded to start downloading Debian's DVD image, but while that was taking it's time downloading (which I think finished in a total of 24+ hours) I was able to fix Gentoo. But I'm a tweaker, a somewhat conservative tweaker, but I do have my moments. My Windows XP installation was about as tweaked as I could. It's main running directories (like the Windows folder, Documents and Settings, and pagefile) were spread across three different drives, all unnecessary services were stopped even Automatic Updates except when I needed to use Windows Update. Heck, my Athlon XP 2500, which is suppose to be running at 1.8GHz, is pushing over 2.5GHz, out running a 3.7 P4 (darn my 333 FSB and memory, and yeah they are overclocked slightly too) So Gentoo was the way for me. And you can't beat the fast and very helpful support from the Gentoo Forums. Kudos to all who has helped someone in these forums.

After figuring out how to best deal with USE flags (and this was a while), I got Gentoo running well. Put KDE 3.2 on which I got up to 3.4, switched to using KDM with some cool themes thanks to kde-look.org (someone get that LCARS working right – though I haven't tried it – yet.) Got dual-monitors working well. Spent a good deal of time getting alsa up, XINE playing DVDs in 5.1 sound, and dumping aRts. Got TV working good through my ATI TV Wonder. Got WINE running some windows programs I couldn't live without. Got my printing and scanning working right through CUPS and xsane on a HP PSC 500. And I can't wait to get some R&R from my Neverwinter Nights running through Gentoo.

After all that, next I wanted my USB flash drives to have the same plug-in-and-go functionality I enjoyed with Windows XP. This is where I took things into my own hands. After searching, it seemed like I'd have to have several services running to make this easy. I found pmount (which seems to only be for Debian/RH for the moment,) ivman (which seemed kinda cool,) and usbmount (again a Debian/RH thing.). I also found a mention of using gnome-volume-manager, but I just don't like the looks of gnome (just my preference, not a slander of gnome.)

Then I found this: How to automate auto mounting/unmounting of USB devices in Linux and Writing udev rules. So thanks to diwaker and Daniel Drake! And while I'm giving thanks, thanks to my wife for her patience and support.

So after finding out how udev could do this for me, especially seeing that it was running on my system, and didn't appear to need any extra auto-mounting services. I set out to do it my own way, which was to take any USB flash drive, plug it in, have it mounted, and a link appear somewhere to it (for this I chose my KDE desktop) but if it was a specific device, like my Fuji S5000 camera, handle that in its own special way. The react properly when the flash drive is unplugged, like umount the drive and remove the link. So far, it works exactly like this.

Getting Started:
If there is something that needs to be corrected, that can be optimized, or if there is any info you think I should add/change/delete, please feel free to post and I'll correct it here. I welcome all comments. Just note, I'm no Linux guru. In fact this forum right now has my status as noob, which I am to Linux.

First, you will need to be running with udev, not devfs. You will also have to be running with a kernel capable of supporting udev, with the necessary modules loaded (either in the kernel or out.) If you don't have USB working on your system, follow the Gentoo Linux USB Guide I don't know exactly what is needed besides this, so please post what should be needed.

Second, the script will have to be placed in the directory /etc/dev.d/block/ and the file will have to end in .dev for it to be run. You will have to create the block/ directory under /etc/dev.d/, if it does not exist. Scripts put here, and I think only one can exist here, will be ran when udev detects a change, such as plugging in a USB flash drive.

Third, you might need a rule added to /etc/udev/rules.d/. NOTE: I'm not sure of this, cause I don't have any real scsi devices. USB flash devices are considered emulated scsi devices. Seeing that I don't have any scsi devices, not using a rule seems to work fine for me. But I tried the script with the rule defined in my /etc/udev/rules.d/10-local.rules as
Code:
BUS="usb", KERNEL="sd?1", NAME="%k", SYMLINK="usb%k"
and it works fine. It will just create both /dev/sda1 and /dev/usbsda1 to the first USB device I have plugged in, /dev/sdb1 and /dev/usbsdb1 for the second, and so on. So if you do have scsi devices, you may need this rule. This continues as if you don't have any real scsi! Please someone post a response if I am right or wrong on this!

If you ls the directory (/etc/udev/rules.d/), you'll see a file named '50-udev.rules'. The rules listed in this file are what makes /dev/hda and /dev/hde5 and /dev/cdrom work the way they do, by default. Check out this file, but NEVER EDIT THIS! What you can do to add your own rules, is to create a file in this directory with the naming convention of '#<50-whatever.rules' Mine is named 10-local.rules cause it will run before 50-udev.rules, but yours can be 10-ILOVESPAM.rules. As long as the leading number is less than the default rules file, it will be processed first. Also, any rules in the first rules file will take precedence over any other rules processed afterwards for the same device. Now, no rule file has to be added to /etc/udev/rules.d/ for this script to work, unless you need to have a device handled in its own way. In fact, here is my 10-local.rules
Code:

BUS="usb", SYSFS{serial}="serial number of my camera", KERNEL="sd?1", NAME="%k", SYMLINK="Fuji_S5000"
#BUS="usb", KERNEL="sd?1", NAME="%k", SYMLINK="usb%k"


The first line is for my camera cause I wanted it mounted always to a specific mount point, which is defined in my fstab. Notice the second line is commented, therefore, not used. Originally, the first script I had was similar to what I found on diwaker's page (see references at the end of this post.) My first 10-local.rules only had the line
Code:
BUS="usb", KERNEL="sd?1", NAME="%k", SYMLINK="usb%k"
. It would redefine any usb flash device as /dev/usbsdX1 (X being the letter the kernel would define for it, for example /dev/sda1 or /dev/sdb1) then mount it when it was plugged in. Then I needed each of those possible mount points defined in my fstab. This to me seemed unnecessary, which is why I wrote my own script.

So, now for the script. First I will break it down and explain each section, then list the script in its entirety.

Breakdown of the Script:

From now on, I will use 'sdX1', where X can be any letter that is used. When you plug in two or more flash devices, the first one will use sda1 and the second will use sdb1 and so on.

The first part of the script comes from diwaker's script. It simply sets the variable $base to the device that is assigned to the flash device, be it sda1, sdb1, sdc1, etc. It then sends information to the system logger about what's being done. (I don't know more about the system logger other than it logs and I have syslog-ng running, yet, like I said I'm a Linux noob.) It then makes sure that the only devices that are controlled by this script are of the sd type (like sda1, sde5, etc) which are scsi devices. (Make sure you read the bolded note above if you have real scsi devices!)

Code:

#!/bin/bash
base=$(basename $DEVNAME)

#Send info to logger
logger -t automount_dev "`env`"

#Check to see if the device is a sdX1 device
if [[ $base != sd[a-g][1-9] ]]
then
exit
fi


The next part starts what to do when the device is added. It will first gather information about the device such as the name of the device the maker of the device and it's serial number. This information is used to name the link created on the desktop. Remember, this is for KDE. I don't know how gnome does this or any other window manager. It also stores this information in a file located in the /tmp directory as '/tmp/sdX1'. Storing this information is not necessary if you don't need any special handling for specific devices, but it won't harm anything and might even be useful to you. I used the '+' as the delimiter because the serial number for my camera contains dashes and carrots (- and ^) so I was being safe, but you might need to change it if you need to.
Code:

#Do this when adding the plugged device
if [ "$ACTION" == "add" ]
then
#Retrieve info about the added device and store into variables
product=$(udevinfo -a -p $DEVPATH | grep SYSFS{product} -m 1 | cut --delim='"' -f2)
vendor=$(udevinfo -a -p $DEVPATH | grep SYSFS{vendor} -m 1 | cut --delim='"' -f2)
serial=$(udevinfo -a -p $DEVPATH | grep SYSFS{serial} -m 1 | cut --delim='"' -f2)
#Store the device info into a file named after the /dev/sdX1 point
#--Only needed when retrieving info for specific devices when unplugged
#--because you can't query a non-existent device
echo "$base+$DEVPATH+$vendor+$product+$serial" >> /tmp/$base


(Optional) This next section is an example of detecting a specific device, so if you don't need to do this you can just remove this section. I chose to check the serial number of the device, and if it is that device to do the stated action. In this example, it will verify that the plugged in device is my camera, then mount it simply with a 'mount /dev/Fuji_S5000'. This is because /dev/Fuji_S5000 is defined in my /etc/fstab as '/dev/Fuji_S5000 /mnt/Fuji_S5000/camera auto noauto,gid=100,umask=0707 0 0' and a mount point is always available at /mnt/Fuji_S5000/camera/. It then exits cause that is all that is needed. The link icon exists on my desktop at all times. Now this part is optional even for the camera, it will just work as any other usb flash device would if I didn't have this section in there. The only thing I haven't figured out is how to get the icon for the camera to switch from the unmounted to mounted icon.

Now as I'm writing this I just thought of something. Is this serial for the camera? Or the memory card? Where is my other memory card? I'm not sure, but this I can easily just make it check for the vendor name which is FUJIFILM. Once I find that other memory card, I'll know for sure.

Code:

#If device is my Fuji S5000 by checking the serial of the plugged device
#--do this then exit
#--this device is added into /etc/fstab as...
#--/dev/Fuji_S5000 /mnt/Fuji_S5000/camera auto noauto,gid=100,umask=0707 0 0
if [ "$serial" == "serial number of my camera" ]
then
mount /dev/Fuji_S5000
exit
fi


This now continues as if the camera was not the device plugged in. It will create the mount point at /mnt/usb/sdX1 then mount it. The mount options I used are to mount it asynchronously (so that all reads/writes are done then and there) and allow all users rw access. You may need to change this based on your needs.

Code:

#Create mount point and mount the device to it with proper access
mkdir /mnt/usb/$base
mount -o async,gid=100,umask=0707 /dev/$base /mnt/usb/$base


Now we create the KDE desktop icon. Pretty simple here. First it is created in /tmp and filled with the information...

Code:

#Create a KDE link file for use on the desktop (used for KDE 3.4)
#--Link name is generated from the devices' vendor, product, serial and $base
echo "[Desktop Entry]" >> /tmp/link2$base
echo "Dev=/dev/$base" >> /tmp/link2$base
echo "Encoding=UTF-8" >> /tmp/link2$base
echo "Icon=usbpendrive_mount" >> /tmp/link2$base
echo "MountPoint=/mnt/usb/$base" >> /tmp/link2$base
echo "Name=$vendor $product [$serial] on $base" >> /tmp/link2$base
echo "Name[en_US]=$vendor $product [$serial] on $base" >> /tmp/link2$base
echo "ReadOnly=False" >> /tmp/link2$base
echo "Type=FSDevice" >> /tmp/link2$base
echo "UnmountIcon=usbpendrive_unmount" >> /tmp/link2$base
echo "Encoding=UTF-8" >> /tmp/link2$base


...then copied to all users under /home

Code:

#Copy the link file to all users' Desktops and to the root's
for x in /home/*; do cp /tmp/link2$base $x/Desktop/link2$base; done
cp /tmp/link2$base /root/Desktop/link2$base


And of course the whole desktop icon part (the last two sections) is completely removable/changeable. As in the script, the icon will appear on your desktop titled according to the device info the script gathered, but the actual file is at /home/yourusername/Desktop/link2sdX1. For example, my flash drive will appear as 'SanDisk Cruzer Micro [SERIALNUMBERHERE] on sda1'. This should give enough distinction if you plug in two of them, especially if the are both Cruzer Micros for example.

And now what to do when the device is removed...

Code:

#Do this when the device is unplugged
elif [ "$ACTION" == "remove" ]
then


(Optional) The device has been removed. You can't retrieve information from the device if it doesn't exist. So you retrieve it from the file that was created upon insertion of the device. (Wow, that last part sounded so covert operational) This file is /tmp/$base/.

Code:

#Retrieve the serial number of the device from the /tmp/$base file
#--only needed for checking for specific devices
serial=$(cat /tmp/$base | cut --delim='+' -f5)


Now this is for checking my camera, which like I said before, checking via serial may be wrong. So you could use vendor by changing this next line to
Code:
vendor=$(cat /tmp/$base | cut –delim'+' -f3)


(Optional) This is where you find out if the device removed was that specific device you specifically mounted in the ADD section. Like my camera for example, I check the serial and if it matches, it umounts my camera. The -l makes the system unmount it when the system is done with it, to avoid any issues. It would then exit.

Code:

#If the device removed was my Fuji S5000
if [ "$serial" == "serial number of my camera" ]
then
umount -l /dev/Fuji_S5000
rm -f /tmp/$base
exit
fi


Now, continuing if it was just a generic device. Unmount the device at /mnt/usb/sdX1, remove the mount point, and all tmp files.

Code:

#Unmount the device and cleanup references
umount -l /mnt/usb/$base
rmdir /mnt/usb/$base
rm -f /tmp/link2$base
rm -f /tmp/$base


Then delete the desktop links.

Code:

#Remove KDE Desktop links created
for x in /home/*; do rm -f $x/Desktop/link2$base; done
rm -f /tmp/$base /root/Desktop/$base
fi


And that's it!


Now, the full script:

Code:

#!/bin/bash
base=$(basename $DEVNAME)

#Send info to logger
logger -t automount_dev "`env`"

#Check to see if the device is a sdX1 device
if [[ $base != sd[a-g][1-9] ]]
then
exit
fi

#Do this when adding the plugged device
if [ "$ACTION" == "add" ]
then
#Retrieve info about the added device and store into variables
product=$(udevinfo -a -p $DEVPATH | grep SYSFS{product} -m 1 | cut --delim='"' -f2)
vendor=$(udevinfo -a -p $DEVPATH | grep SYSFS{vendor} -m 1 | cut --delim='"' -f2)
serial=$(udevinfo -a -p $DEVPATH | grep SYSFS{serial} -m 1 | cut --delim='"' -f2)
#Store the device info into a file named after the /dev/sdX1 point
#--Only needed when retrieving info for specific devices when unplugged
#--because you can't query a non-existent device
echo "$base+$DEVPATH+$vendor+$product+$serial" >> /tmp/$base

#If device is my Fuji S5000 by checking the serial of the plugged device
#--do this then exit
#--this device is added into /etc/fstab as...

#--/dev/Fuji_S5000 /mnt/Fuji_S5000/camera auto noauto,gid=100,umask=0707 0 0
if [ "$serial" == "<my camera's serial number>" ]
then
mount /dev/Fuji_S5000
exit
fi

#Create mount point and mount the device to it with proper access
mkdir /mnt/usb/$base
mount -o async,gid=100,umask=0707 /dev/$base /mnt/usb/$base

#Create a KDE link file for use on the desktop (used for KDE 3.4)
#--Link name is generated from the devices' vendor, product, serial and $base
echo "[Desktop Entry]" >> /tmp/link2$base
echo "Dev=/dev/$base" >> /tmp/link2$base
echo "Encoding=UTF-8" >> /tmp/link2$base
echo "Icon=usbpendrive_mount" >> /tmp/link2$base
echo "MountPoint=/mnt/usb/$base" >> /tmp/link2$base
echo "Name=$vendor $product [$serial] on $base" >> /tmp/link2$base
echo "Name[en_US]=$vendor $product [$serial] on $base" >> /tmp/link2$base
echo "ReadOnly=False" >> /tmp/link2$base
echo "Type=FSDevice" >> /tmp/link2$base
echo "UnmountIcon=usbpendrive_unmount" >> /tmp/link2$base
echo "Encoding=UTF-8" >> /tmp/link2$base
#Copy the link file to all users' Desktops and to the root's
for x in /home/*; do cp /tmp/link2$base $x/Desktop/link2$base; done
cp /tmp/link2$base /root/Desktop/link2$base

#Do this when the device is unplugged
elif [ "$ACTION" == "remove" ]
then
#Retrieve the serial number of the device from the /tmp/$base file
#--only needed for checking for specific devices
serial=$(cat /tmp/$base | cut --delim='+' -f5)

#If the device removed was my Fuji S5000
if [ "$serial" == "<my camera's serial number>" ]
then
umount -l /dev/Fuji_S5000
rm -f /tmp/$base
exit
fi

#Unmount the device and cleanup references
umount -l /mnt/usb/$base
rmdir /mnt/usb/$base
rm -f /tmp/link2$base
rm -f /tmp/$base

#Remove KDE Desktop links created
for x in /home/*; do rm -f $x/Desktop/link2$base; done
rm -f /tmp/$base /root/Desktop/$base
fi




References:
Gentoo Linux USB Guide
– Wouldn't have made it too far without this.

How to automate auto mounting/unmounting of USB devices in Linux
-- What helped me figure this script out.

Writing udev rules
-- Lots of useful information. How I found I could retrieve the information of the devices.

Thanks to:
Shyam Mani, diwaker and Daniel Drake; the authors of the above articles, in order.

Well, there ya go. Hope you get it working for you. Feel free to post questions (and post and corrections.)

Things to do:
Find that memory card!

Get this working with USB Hard Drives. (Are they all called 'USB 2.0 Storage Device' for SYSFS{product}?)

Re-word some of this. (Currently quite sleepy, but wanted to get this out)

Fix any errors/misconceptions in this HOWTO.

Have sections to create desktop shortcuts for other windows managers. Please post what you can, cause I probably won't use anything but KDE.

Network shares?

CD/DVD automount on disc insertion, eject with eject button (for non-usb drives)

Anything else I can think of.


Last edited by MHenry676 on Mon Jul 18, 2005 10:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
johntramp
Guru
Guru


Joined: 03 Feb 2004
Posts: 457
Location: New Zealand

PostPosted: Sun Jun 19, 2005 9:44 am    Post subject: Reply with quote

Quote:

When it is removed, the script will unmount the drive

Hi. Would you not want to umount the device BEFORE you disconnect it from the computer. Doesn't the defeat the purpose of umounting a device if it doesn't have access to it anymore?

PS: I only skimmed throught the howto, but it does look like you put a lot of effort into it. It looks very good, hopefully it will help out other users like yourself :)
Back to top
View user's profile Send private message
hadur
n00b
n00b


Joined: 04 Nov 2004
Posts: 8

PostPosted: Sun Jun 19, 2005 12:41 pm    Post subject: Reply with quote

I was looking for something like this. I hated the idea of running extra services just for USB auto-mounting. This is perfect. Thank you!
Back to top
View user's profile Send private message
MHenry676
Tux's lil' helper
Tux's lil' helper


Joined: 02 Aug 2004
Posts: 125

PostPosted: Sun Jun 19, 2005 1:36 pm    Post subject: Reply with quote

johntramp said:
Quote:
Hi. Would you not want to umount the device BEFORE you disconnect it from the computer. Doesn't the defeat the purpose of umounting a device if it doesn't have access to it anymore?


You still have the option. It's kinda like with Windows, before unplugging the USB device to click on that hardware icon on the sys tray, to stop the device. I'm assuming cause this is to make sure any queued read/writes are finished before unpluging it. For the mount options, i'm not sure if mounting with sync or async is the best way. I couldn't find a solid answer on what should be used, though the man page was my only reference on this. So I think I have it working where all data handleing should be done on the spot (is it?). I tried both with the understanding that async would perform all actions asynchronously (meaning out of sync with the system cache and doing all read/writes then and there) and that sync would perform all actions synchronously (meaning sync'ed with the system cache and doing all read/writes the next time it could, just not neccessarily right away.)

Now, as far as just right clicking on that created desktop icon and selecting unmount? It doesn't do that as of now. I probably have to change the mount statement to allow this, just not sure exactly how at the moment. So if you wish to unmount the drive before unplugging it, you'll have to unmount it as root. Again, I think I just need a better mount statement.
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Sun Jun 19, 2005 1:43 pm    Post subject: Reply with quote

I know you mentioned doing this without any programs like pmount, or ivman but isn't that a lot of work for nothing? Aren't you just repeating what they do? I'm not trying to discourage you, but seems like a lot of unneeded work.

Pmount is such a small program and once installed I only needed to edit 1 or lines and all my usb devices worked automatically in KDE. (several flash keys, portable hard drive, and camera.

This includes a desktop icon for each that appears when inserted and removed when unplugged.
Right clicking any icon has a safely remove option to make sure write cache is empty before unmounting.

Absolutely no problems with this system and auto-mounting of CDs works flawless too.
Back to top
View user's profile Send private message
MHenry676
Tux's lil' helper
Tux's lil' helper


Joined: 02 Aug 2004
Posts: 125

PostPosted: Sun Jun 19, 2005 3:16 pm    Post subject: Reply with quote

Headrush wrote:
Quote:
I know you mentioned doing this without any programs like pmount, or ivman but isn't that a lot of work for nothing? Aren't you just repeating what they do? I'm not trying to discourage you, but seems like a lot of unneeded work.

Pmount is such a small program and once installed I only needed to edit 1 or lines and all my usb devices worked automatically in KDE. (several flash keys, portable hard drive, and camera.

This includes a desktop icon for each that appears when inserted and removed when unplugged.
Right clicking any icon has a safely remove option to make sure write cache is empty before unmounting.

Absolutely no problems with this system and auto-mounting of CDs works flawless too.


Well, it was just one of those things I wanted to do myself. (Why would you climb the mountain when you can take a hellicopter ride to the top?) Plus, the state it is in now doesn't require all that much work to suit it to your needs, and it's quite easy.

For example, if you want your Flash drive to be specifically mounted to a certain location all the time, plug it in with this script running. You'll then see the information about the drive that you can use and do something similar like I did with my camera.

BTW, Simpsons fan? (Location: Bizarro Wolrd)
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Sun Jun 19, 2005 5:27 pm    Post subject: Reply with quote

MHenry676 wrote:

Well, it was just one of those things I wanted to do myself. (Why would you climb the mountain when you can take a hellicopter ride to the top?) Plus, the state it is in now doesn't require all that much work to suit it to your needs, and it's quite easy.

For example, if you want your Flash drive to be specifically mounted to a certain location all the time, plug it in with this script running. You'll then see the information about the drive that you can use and do something similar like I did with my camera.

I applaud your work, but I thought it just seemed like a solution needing a problem with the latest KDEs and HAL support. But that is the great thing about Gentoo, choose your own preference :-)

MHenrey676 wrote:
BTW, Simpsons fan? (Location: Bizarro Wolrd)

Actually a Seinfeld fan :-) , but the Simpsons are great too!
Back to top
View user's profile Send private message
MHenry676
Tux's lil' helper
Tux's lil' helper


Joined: 02 Aug 2004
Posts: 125

PostPosted: Mon Jun 20, 2005 3:39 am    Post subject: Reply with quote

Quote:
...with the latest KDEs and HAL support.


Curious, what KDE support is there for this kind of thing? I've read that gnome has the gnome-volume-manager, but have found nothing like what I got going for KDE.
Back to top
View user's profile Send private message
nephros
Advocate
Advocate


Joined: 07 Feb 2003
Posts: 2139
Location: Graz, Austria (Europe - no kangaroos.)

PostPosted: Mon Jun 20, 2005 5:30 am    Post subject: Reply with quote

Quote:
For the mount options, i'm not sure if mounting with sync or async is the best way. I couldn't find a solid answer on what should be used, though the man page was my only reference on this.

From what I gather from a recent (and lengthy) thread on LKML, flash drives should in any case be mounted async, because the current FAT implementations are poison for flash media.
(In particular, the FAT table gets written to a lot when using sync, leading to strain of the physical media containing the FAT table, eventually damaging it permanently).
_________________
Please put [SOLVED] in your topic if you are a moron.
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Mon Jun 20, 2005 5:33 pm    Post subject: Reply with quote

MHenry676 wrote:
Quote:
...with the latest KDEs and HAL support.


Curious, what KDE support is there for this kind of thing? I've read that gnome has the gnome-volume-manager, but have found nothing like what I got going for KDE.

It may not be exact to what you have, but with KDE 3.4 devices are placed on the desktop when inserting removeable media.
When you double click the icon, the drive is automatically mounted and entries created in /etc/fstab.
The contextual menu for each icon has "unmount, safely remove, and eject" options.

As far as I know, names are determined by volume name on device and mount points are in /media, not /mnt.

This works with my USB hard drive, usb flash key, and my usb camera.
Back to top
View user's profile Send private message
RinkyDinks_RJ
n00b
n00b


Joined: 12 Aug 2003
Posts: 42

PostPosted: Tue Jun 21, 2005 3:47 am    Post subject: Reply with quote

Using KDE 3.4, with udev, hald, dbus, and ivman, I have links automatically put onto my desktop when inserted. You do have to have the Storage Media Applet in the panel (takes up no space when devices are mounted) and you might have to do some customizing of which types of devices you want shown on the desktop. KControl -> Behavior -> Device Icons.

Also, you can access your devices from the media:/ kioslave in Konqueror.

Anyhow, great writeup.
Back to top
View user's profile Send private message
Headrush
Watchman
Watchman


Joined: 06 Nov 2003
Posts: 5597
Location: Bizarro World

PostPosted: Tue Jun 21, 2005 5:01 am    Post subject: Reply with quote

RinkyDinks_RJ wrote:
You do have to have the Storage Media Applet in the panel (takes up no space when devices are mounted) and you might have to do some customizing of which types of devices you want shown on the desktop. KControl -> Behavior -> Device Icons.

I do not have the applet loaded and it works fine.
Back to top
View user's profile Send private message
maguire
Tux's lil' helper
Tux's lil' helper


Joined: 27 May 2004
Posts: 103
Location: Longmont, Colorado

PostPosted: Fri Jul 29, 2005 9:44 pm    Post subject: Definition of "sync" and "async" in the Reply with quote

I believe that the original author has the definitions of "sync" and "async" mixed up. He says:
Quote:

mount it asynchronously (so that all reads/writes are done then and there)


A synchronous write is "done then and there"; i.e. the write command only returns when the data is actually written to the media. An asynchronous write command will return successfully, even though the data may only exist in a cache somewhere---not actually on the media.

This definition makes sense, because synchronous means "happening, existing, or arising at precisely the same time" (Merriam Webster Online Dictionary). So a synchronous write is one that really occurs when you issued the command. Asynchronous writes may not occur at the time you commanded, because the data may be stored in a cache somewhere ("buffered-up") until some time in the future when the system determines that the real write should occur.

So, at first blush, it may appear that synchronous (sync) would be the best mode for removable media---since the media may be removed at any time, and any writes to it had better been done as soon as possible. Unfortunately, with Flash media, there is a counterbalancing concern: The media is only good for a some number of writes (hundreds of thousands or millions). That may not seem to be a problem to you, but it may be a problem for the filesystem. I believe that is what one of the other posters meant when he referenced a discussion about "sync" mounts and the FAT filesystem. If the filesystem does many writes to a small area of the disk (like a File Allocation Table), then that inherent limitation of the Flash memory can occur much earlier than you would have thought.

Adding even more confusion to the issue, is that fact that the mount manpage says this:
Quote:

...the sync option today has effect only for [sic] ext2, ext3 and ufs...


So, I really don't know the definitive answer, but hopefully this clears-up the sync/async definitions and issues.

Bruce.
Back to top
View user's profile Send private message
urcindalo
l33t
l33t


Joined: 08 Feb 2005
Posts: 623
Location: Almeria, Spain

PostPosted: Mon Nov 14, 2005 4:09 pm    Post subject: Reply with quote

I use Gentoo AMD64, and followed this guide to the letter. However, I see no icon appear on my desktop one I insert my USB flash disk.

This is what I did:

1) I created the file /etc/udev/rules.d/10-local.rules with the content specified in the thread:
Code:
$ ls -lA /etc/udev/rules.d/
total 20
-rw-r--r--  1 root root    54 nov 14 16:57 10-local.rules
-rw-r--r--  1 root root 11492 nov  4 17:21 50-udev.rules
-rw-r--r--  1 root root    42 nov 10 10:10 60-vmware.rules
$ ls -lA /etc/udev/rules.d/10-local.rules
-rw-r--r--  1 root root 54 nov 14 16:57 /etc/udev/rules.d/10-local.rules
$ cat /etc/udev/rules.d/10-local.rules
BUS="usb", KERNEL="sd?1", NAME="%k", SYMLINK="usb%k"
$


2) I saved the script in this thread in /etc/dev.d/block after commenting out all the lines pertaining to the author's digital camera, and gave it exec permissions:
Code:
$ ls -lA /etc/dev.d/block
total 4
-rwxr-xr-x  1 root root 2787 nov 14 16:26 automontaje.dev
$


3) I commented out the line in my /etc/fstab that I used in the past to mount the usb sitck:
Code:
$ cat /etc/fstab | grep usb
none /proc/bus/usb usbfs defaults,devmode=0666 0 0
#/dev/sda       /mnt/usbdisk    vfat    noauto,users,exec,noatime       0       0
$


4) I rebooted

However, nothing happens when I plug the usb flash disk. Why is that? I use the very latest AMD64 stable KDE and udev.
Back to top
View user's profile Send private message
incabolocabus
Apprentice
Apprentice


Joined: 24 Nov 2003
Posts: 232
Location: Fort Collins, CO

PostPosted: Tue Nov 15, 2005 6:58 pm    Post subject: Reply with quote

When you plug in your flash disk, you should see something like this
Code:
Nov 15 11:39:03 foo ohci_hcd 0000:00:02.0: wakeup
Nov 15 11:39:03 foo usb 1-8: new full speed USB device using ohci_hcd and address 5
Nov 15 11:39:03 foo scsi3 : SCSI emulation for USB Mass Storage devices
Nov 15 11:39:03 foo usb-storage: device found at 5
Nov 15 11:39:03 foo usb-storage: waiting for device to settle before scanning
Nov 15 11:39:08 foo Vendor:           Model: USB DISK          Rev: 2.08
Nov 15 11:39:08 foo Type:   Direct-Access                      ANSI SCSI revision: 00
Nov 15 11:39:08 foo SCSI device sda: 1015808 512-byte hdwr sectors (520 MB)
Nov 15 11:39:08 foo sda: Write Protect is off
Nov 15 11:39:08 foo sda: Mode Sense: 43 00 00 00
Nov 15 11:39:08 foo sda: assuming drive cache: write through
Nov 15 11:39:08 foo SCSI device sda: 1015808 512-byte hdwr sectors (520 MB)
Nov 15 11:39:08 foo sda: Write Protect is off
Nov 15 11:39:08 foo sda: Mode Sense: 43 00 00 00
Nov 15 11:39:08 foo sda: assuming drive cache: write through
Nov 15 11:39:08 foo sda: sda1
Nov 15 11:39:08 foo Attached scsi removable disk sda at scsi3, channel 0, id 0, lun 0
Nov 15 11:39:08 foo usb-storage: device scan complete
Nov 15 11:39:09 foo scsi.agent[8108]: disk at /devices/pci0000:00/0000:00:02.0/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:0
Nov 15 11:39:09 foo automount_dev: PHYSDEVPATH=/devices/pci0000:00/0000:00:02.0/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:0 ID_MODEL=USB_DISK ID_REVISION=2.08 ID_BUS=usb SUBSYSTEM=block ID_SERIAL=_USB_DISK_19320FA20597 DEVPATH=/block/sda MINOR=0 ACTION=add PWD=/ MAJOR=8 UDEVD_EVENT=1 DEVNAME=/dev/sda SHLVL=1 PHYSDEVDRIVER=sd ID_TYPE=disk ID_VENDOR= PHYSDEVBUS=scsi ID_PATH=usb-19320FA20597:0:0:0 SEQNUM=1102 _=/usr/bin/env
Nov 15 11:39:09 foo automount_dev: PHYSDEVPATH=/devices/pci0000:00/0000:00:02.0/usb1/1-8/1-8:1.0/host3/target3:0:0/3:0:0:0 ID_MODEL=USB_DISK ID_REVISION=2.08 ID_FS_LABEL_SAFE= ID_FS_LABEL= ID_BUS=usb SUBSYSTEM=block ID_SERIAL=_USB_DISK_19320FA20597 ID_FS_UUID=1CE4-0F4D DEVPATH=/block/sda/sda1 ID_FS_VERSION=FAT16 MINOR=1 ACTION=add PWD=/ ID_FS_TYPE=vfat MAJOR=8 UDEVD_EVENT=1 DEVNAME=/dev/sda1 SHLVL=1 ID_FS_USAGE=filesystem PHYSDEVDRIVER=sd ID_TYPE=disk ID_VENDOR= PHYSDEVBUS=scsi ID_PATH=usb-19320FA20597:0:0:0 SEQNUM=1103 _=/usr/bin/env


The script assumes you already have a /mnt/usb directory and will fail if you don't.
Once I made this directory, it worked well.
_________________
1970s Sears Hawthorne, green, 3 gears, front and rear fenders, rear dual basket rack, overclocked to 1.3 hz.
Back to top
View user's profile Send private message
urcindalo
l33t
l33t


Joined: 08 Feb 2005
Posts: 623
Location: Almeria, Spain

PostPosted: Wed Nov 16, 2005 10:20 am    Post subject: Reply with quote

incabolocabus wrote:
When you plug in your flash disk, you should see something like this
{....}

The script assumes you already have a /mnt/usb directory and will fail if you don't.
Once I made this directory, it worked well.


Thanks for trying to help me out here.

1) Where should I see the output you mention?

2) I created the directory as you suggested, and _rebooted_ (to be sure the new config is correctly read). However, still the same: nothing happens on my desktop. I see no icon appear automounting the flash disk.

Just in case, this is what I get from lsusb:
Code:
# lsusb
Bus 005 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 004: ID 054c:011d Sony Corp.
Bus 001 Device 003: ID 054c:011c Sony Corp.
Bus 001 Device 002: ID 054c:011e Sony Corp.
Bus 001 Device 001: ID 0000:0000
# lsusb -t
Bus#  5
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  4
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  3
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  2
`-Dev#   1 Vendor 0x0000 Product 0x0000
Bus#  1
`-Dev#   1 Vendor 0x0000 Product 0x0000
  `-Dev#   2 Vendor 0x054c Product 0x011e
    |-Dev#   3 Vendor 0x054c Product 0x011c
    `-Dev#   4 Vendor 0x054c Product 0x011d
#


It is a Sony USB 2.0 128 MB flash disk with a memory stick reader incorporated. This is the info from "dmesg":
Code:
usb 1-8: new high speed USB device using ehci_hcd and address 2
hub 1-8:1.0: USB hub found
hub 1-8:1.0: 2 ports detected
usb 1-8.1: new high speed USB device using ehci_hcd and address 3
scsi2 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 3
usb-storage: waiting for device to settle before scanning
usb 1-8.2: new high speed USB device using ehci_hcd and address 4
scsi3 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 4
usb-storage: waiting for device to settle before scanning
  Vendor: Sony      Model: Storage Media     Rev: 1.00
  Type:   Direct-Access                      ANSI SCSI revision: 00
SCSI device sda: 256000 512-byte hdwr sectors (131 MB)
sda: Write Protect is off
sda: Mode Sense: 00 06 00 00
sda: assuming drive cache: write through
SCSI device sda: 256000 512-byte hdwr sectors (131 MB)
sda: Write Protect is off
sda: Mode Sense: 00 06 00 00
sda: assuming drive cache: write through
 sda: unknown partition table
Attached scsi removable disk sda at scsi2, channel 0, id 0, lun 0
Attached scsi generic sg0 at scsi2, channel 0, id 0, lun 0,  type 0
usb-storage: device scan complete
  Vendor: Sony      Model: USM-MS            Rev: 1.00
  Type:   Direct-Access                      ANSI SCSI revision: 00
Attached scsi removable disk sdb at scsi3, channel 0, id 0, lun 0
Attached scsi generic sg1 at scsi3, channel 0, id 0, lun 0,  type 0
usb-storage: device scan complete
Back to top
View user's profile Send private message
AmosMutke
Apprentice
Apprentice


Joined: 24 Dec 2003
Posts: 235
Location: Akita, Japan.

PostPosted: Thu Nov 17, 2005 8:02 am    Post subject: Reply with quote

urcindalo wrote:
1) Where should I see the output you mention?


From the output of "dmesg" (as you seemed to have figured out) or alternatively should be printed in the "F12" terminal window too. <ctrl>+<alt>+F12


Isn't there an obvious problem with pulling a USB memory device without unmouting it first if you hav async? Everything in the cache will be lost and it's possible files where left open which might cause them to be damaged.

BTW.. ef'n great tutorial. I recently bought a USB2.0/IEEE hard drive and want it mounted automatically in the same place.. of course my problem is that I also mount my digital camera and usb stick. At different times and in different order. That means I was required to manually mount each device in /mnt/usb1 /mnt/usb2 and /mnt/usb3 and then remember what each was. (I have a laptop that I bring with me to work everyday to two different offices and at home. Hence the constant re-plugging of devices). This was next on my list to tackle. You save me lots of leg work. Next time you're in Northern Honshu, Japan, I'll buy you an Asahi.

-Amos
Back to top
View user's profile Send private message
AmosMutke
Apprentice
Apprentice


Joined: 24 Dec 2003
Posts: 235
Location: Akita, Japan.

PostPosted: Sat Nov 19, 2005 10:45 am    Post subject: test.dev autoload test script Reply with quote

OK.. thanx to this howto, I was quickly able to get my digital camera, usb memory stick, and external ieee1394 hard drive to auto mount. I'm adding my experience to the knowlege base in the hopes it might be useful to somebody at some point.

I initially had trouble trying to find out what information was provided by "udevinfo" in my autoload.dev script, so I wrote this script to dump the contents to a temporary file.
Code:
#!/bin/bash
base=$(basename $DEVNAME)
debuginfo=$(udevinfo -a -p $DEVPATH)
if [[ $base == sd[a-g][1-9] ] &&  "$ACTION" == "add" ]
then
  echo "$debuginfo" > /tmp/automount.dev.debug
fi


creat a file called /etc/dev.d/block/test.dev with the contents of the above code block in it and make it executable
Code:
chmod +x /etc/dev.d/block/test.dev


Now when you plug in a usb storrage device, it will put the information available for that device in /tmp/automount.dev.debug
You can use this information to help build your autoload.dev script. for me "model" was the only unique common variable for all three devices, but it is suffecient.

Here's the info on my setup. I have a Buffalo External IEEE1394 250GB Harddrive, Sony Cybershot DSC-P200 digital camera, and a Buffalo USB2.0 250MB Clip Drive.

My IEEE1394 Harddrive holds all my media files and I want to have a link from ~/multimedia/video -> /mnt/ieee1394/sd?1/video
(It's important that pron be easily accessable)
When the usb stick or camera is connected, I want "~/usb" and "~/camera" directories created respectively.

here's my /etc/dev.d/block/autoload.dev script
Code:
#!/bin/bash
base=$(basename $DEVNAME)

#Send info to logger
logger -t automount_dev "`env`"

#Check to see if the device is a sdX1 device
if [[ $base != sd[a-g][1-9] ]]
then
  exit
fi

if [ "$ACTION" == "add" ]
then
  model=$(udevinfo -a -p $DEVPATH | grep model -m 1 | cut --delim='"' -f2 | tr -d ' ')
  debuginfo=$(udevinfo -a -p $DEVPATH)
  echo "$debuginfo" > /tmp/automount.dev.debug
 

  #  See if it's the external HD, camera, or usb clip drive.
  if [ "$model" == "SonyDSC" ]
  then
    #  Create mount point and mount the device to it with proper access
    mkdir /mnt/usb/$base
    mount -o async,gid=100,umask=0707 /dev/$base /mnt/usb/$base
    echo "camera" > /tmp/$base
    ln -s /mnt/usb/$base /home/shawn/camera
  elif [ "$model" == "ClipDrive" ] # buffalo clip drive
  then
    mkdir /mnt/usb/$base
    mount -o async,gid=100,umask=0707 /dev/$base /mnt/usb/$base
    echo "buffalo clip drive" > /tmp/$base
    ln -s /mnt/usb/$base /home/shawn/usb
  elif [ "$model" == "WD2500BB-22GUC0" ]
  then
    mkdir /mnt/ieee1394/$base
    mount -o async,gid=100,umask=0707 /dev/$base /mnt/ieee1394/$base
    echo "buffalo ieee1394 hd" > /tmp/$base
    ln -s /mnt/ieee1394/$base/video /home/shawn/multimedia/video
    ln -s /mnt/ieee1394/$base/video /home/stopher/multimedia/video   
  else exit
  fi
#Do this when the device is unplugged
elif [ "$ACTION" == "remove" ]
then
  #  Unmount the device and cleanup references
  unplugged=$(cat /tmp/$base)   

  if [ "$unplugged" == "camera" ] # camera
  then
    umount -l /mnt/usb/$base
    rm -f /home/shawn/camera
  elif [ "$unplugged" == "buffalo clip drive" ] # buffalo clip drive
  then
    umount -l /mnt/usb/$base
    rm -f /home/shawn/usb
  elif [ "$unplugged" == "buffalo ieee1394 hd" ] # buffalo ieee hard drive
  then
    umount -l /mnt/ieee1394/$base
    rm -f /home/shawn/multimedia/video
    rm -f /home/stopher/multimedia/video
  else exit
  fi

  rmdir /mnt/usb/$base
fi


Concerns
  • I have some thoughts about possible problems, or rather a false sense of security, by using automount. Namely, if you don't first umount your device, it's possible that parts of files are still in a cache and will not be written when you disconnect the device. Does anyone know if there is a command to flush a possible cache before you pull the device? say "flush /dev/sda" for example?
  • If you haven't written anything to the disk (Let's say you insert your usb memory stick, check the contents, and then remove it), is there any danger of damaging the file system? reason would suggest it's OK.
Back to top
View user's profile Send private message
anheuser50
n00b
n00b


Joined: 20 Nov 2005
Posts: 2

PostPosted: Sun Nov 20, 2005 1:06 pm    Post subject: Reply with quote

I found the information here quite interesting and modified your script quite a bit. I hate icon names that are 5 miles long (Such as with my alienware 1G Pendrive) and wanted a bit more functionality. The following script is derivied from your work, but also scans the /etc/udev/rules.d directory for matching devices to grab the SYMLINK name of the device.

The symlink is used to named the device if available and a symlink is created in the mount point directory. Note that in this script I have created a directory of /r for the removable media to be mounted under.

Code:
#!/bin/bash

#Function to extract the SYMLINK="link" entry from a line from the udev rules
getSymLink () {
        for var in $line ; do
            if [[ "$var" == SYMLINK* ]] ; then
                symlink=$(echo $var | cut --delim='"' -f2)
                break
            fi
        done
}

base=$(basename $DEVNAME)

#Send info to logger
logger -t automount_dev "USB $ACTION: $DEVPATH"

#Check to see if the device is a sdX1 device // Changed a-g to a-z (I have 13 SCSI devices)
if [[ $base != sd[a-z][1-9]* ]]; then
    #echo "$base != sdX1" >> /r/debug
    exit
fi


case $ACTION in
    add)
   vendor=$(udevinfo -a -p /sys/block/$DEVNAME | grep SYSFS{vendor} -m 1 | cut --delim='"' -f2)
        #What SYSFS Entries are we going to search through to match the symlink?
   lookin="serial idProduct idVendor product vendor"

   for filename in /etc/udev/rules.d/*.rules ; do
       symlink=""
       for look in $lookin ; do
           match=$(udevinfo -a -p /sys/$DEVPATH | grep SYSFS\{$look\} -m 1 | cut --delim='"' -f2)
           line=$(grep SYSFS\{$look\}=\"$match\" -m 1 $filename)
           if [[ -n $line ]] ; then
               getSymLink
           fi
       done
       if [[ -n $symlink ]] ; then
           #Use the SymLink as the name
           linkname="$symlink [$base]"
           break
       else
           #Use something else as the name
           linkname="$vendor [$base]"
           break
       fi
   done

   
        echo "$base+$DEVPATH+$vendor+$product+$serial" > /r/info_$base
   
   
        #Create mount point and mount the device to it with proper access
        mkdir /r/$base
        mount -t vfat -o async,gid=100,umask=0707 /dev/$base /r/$base
   if [[ -n $symlink ]] ; then
           ln -s /r/$base /r/$symlink
   fi
   
        #Create a KDE link file for use on the desktop (used for KDE 3.4)
        #--Link name is generated from the devices' vendor, product, serial and $base
        echo "[Desktop Entry]" > /tmp/link2$base
        echo "Dev=/dev/$base" >> /tmp/link2$base
        echo "Encoding=UTF-8" >> /tmp/link2$base
        echo "Icon=usbpendrive_mount" >> /tmp/link2$base
        echo "MountPoint=/mnt/usb/$base" >> /tmp/link2$base
        echo "Name=$vendor $product [$serial] on $base" >> /tmp/link2$base
        echo "Name[en_US]=$linkname" >> /tmp/link2$base
        echo "ReadOnly=False" >> /tmp/link2$base
        echo "Type=FSDevice" >> /tmp/link2$base
        echo "UnmountIcon=usbpendrive_unmount" >> /tmp/link2$base
        echo "Encoding=UTF-8" >> /tmp/link2$base
   
        #Copy the link file to all users' Desktops
        for x in /home/*; do cp /tmp/link2$base $x/Desktop/link2$base; done
        ;;
    remove)
        #Retrieve the serial number of the device from the /tmp/$base file
        #--only needed for checking for specific devices
        serial=$(cat /r/info_$base | cut --delim='+' -f5)
        vendor=$(cat /r/info_$base | cut ?delim'+' -f3)
   
        #Unmount the device and cleanup references
        umount -l /r/$base
        rmdir /r/$base
        rm -f /tmp/link2$base
       rm -f /r/info_$base
        #Remove KDE Desktop links created
        for x in /home/*; do rm -f $x/Desktop/link2$base; done
        ;;
    *)
        #Not add? Not remove? Hmm... (grumble grumble)
        ;;
esac


Hope this helps someone, I changed a few lines especially
Code:
if [[ $base != sd[a-z][1-9]* ]]; then
due to the number of scsi devices I have along with the 3 pen drives.

Also I changed the mount command to
Code:
mount -t vfat -o async,gid=100,umask=0707 /dev/$base /r/$base
becuase I would rather have them mounted as VFAT instead of FAT for the long filenames... =)

For reference, my udev rules file lookes like this:
Code:
#SanDisk Cruzer MINI 1GB
BUS="usb", SYSFS{serial}="SNDK9BAB943875707102", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="cruzer"

#SanDisk Cruzer Micro 1GB
BUS="usb", SYSFS{serial}="0000290905001520", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="cruzerMicro"

#Alienware 1G
BUS="usb", SYSFS{idProduct}="6025", SYSFS{idVendor}="0204", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="alien1g"

#Iomega ZIP Drive
BUS="ide", SYSFS{size}="196608", SYSFS{removable}="1", KERNEL="hd?4", OWNER="anheuser50", NAME="%k", SYMLINK="iomega"


#Dell 2405FPW LCD Monitor card reader
#BUS="usb", SYSFS{product}="USB2223", KERNEL="sd*", OWNER="anheuser50", NAME="%k", SYMLINK="cardreader%n"


#Dell 2405FPW LCD Monitor card reader
BUS="scsi", SYSFS{model}="223 U HS-MS", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="memorystick"
BUS="scsi", SYSFS{model}="223 U HS-SD/MMC", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="multimediacard"
BUS="scsi", SYSFS{model}="223 U HS-CF", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="compactflash"


#Winders XPensinve Drive
BUS="scsi", SYSFS{model}="ST318404LW      ", KERNEL="sd?1", OWNER="anheuser50", NAME="%k", SYMLINK="winxp"


Comments are welcome expecially for cleaning up the method used to grab the UDEV SYMLINK stuff.

Thanks =)
_________________
|.·´¨)
'' ¸·´ .·´¨)'` .·~> "I drink beer, I run Linux. Period. Winblow$ can suck my left nut." ~Beerman
`(¸.·´ . (¸.·´
Back to top
View user's profile Send private message
anheuser50
n00b
n00b


Joined: 20 Nov 2005
Posts: 2

PostPosted: Sun Nov 20, 2005 1:10 pm    Post subject: Reply with quote

urcindalo wrote:

It is a Sony USB 2.0 128 MB flash disk with a memory stick reader incorporated. This is the info from "dmesg":
Code:
sda: Write Protect is off
sda: Mode Sense: 00 06 00 00
sda: assuming drive cache: write through
 sda: unknown partition table


Unknown partition table, means the kernel doesn't know what kind of filesystem is on the drive. Is the memory card formatted funky for a mac? or not formatted at all? Have you tried
Code:
mkdir /mnt/pendrive
mount -t vfat /dev/sda /mnt/pendrive

*Note the missing "1" on sda

Hope this helps.
_________________
|.·´¨)
'' ¸·´ .·´¨)'` .·~> "I drink beer, I run Linux. Period. Winblow$ can suck my left nut." ~Beerman
`(¸.·´ . (¸.·´
Back to top
View user's profile Send private message
AmosMutke
Apprentice
Apprentice


Joined: 24 Dec 2003
Posts: 235
Location: Akita, Japan.

PostPosted: Tue Nov 22, 2005 1:47 am    Post subject: Reply with quote

fdisk will also display the partition types if it can identify them. Might want to give that a try. Just replace "hda" with your pendrive device file "sd?".

Code:
 ~/shawn >fdisk -l /dev/hda

Disk /dev/hda: 60.0 GB, 60011642880 bytes
255 heads, 63 sectors/track, 7296 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1               1           9       72261   83  Linux
/dev/hda2              10         134     1004062+  82  Linux swap / Solaris
/dev/hda3             135         384     2008125   83  Linux
/dev/hda4             385        7296    55520640   83  Linux
Back to top
View user's profile Send private message
neopath
n00b
n00b


Joined: 28 Nov 2005
Posts: 4

PostPosted: Mon Nov 28, 2005 2:06 am    Post subject: Re: test.dev autoload test script Reply with quote

AmosMutke wrote:

[list][*]I have some thoughts about possible problems, or rather a false sense of security, by using automount. Namely, if you don't first umount your device, it's possible that parts of files are still in a cache and will not be written when you disconnect the device. Does anyone know if there is a command to flush a possible cache before you pull the device? say "flush /dev/sda" for example?


Would not it be possible to use the sync command? I had a usb drive that did not always get written to due to the async in the mount command. Would running sync before removing the usb drive be a safe way to take care of unmounting when using the script? Right now I have a button on the panel that runs sync in a terminal. I press that button before pulling out the usb drive. The script then unmounts with umount -l. I think that would take care of the cashe being written, but not sure about how good it is to just unplug the device after that or about the second concern that was given:
AmosMutke wrote:
If you haven't written anything to the disk (Let's say you insert your usb memory stick, check the contents, and then remove it), is there any danger of damaging the file system? reason would suggest it's OK.


Many thanks for the howto.
Back to top
View user's profile Send private message
soya
Guru
Guru


Joined: 29 Jan 2004
Posts: 429

PostPosted: Fri Dec 02, 2005 10:23 am    Post subject: Reply with quote

It does not work for uba detected devices.At least for me. I've changed a pair of lines to try to makeit work with uba detected devices but obviusly i've done it wrong cause it does not work. Can someone post what to change to work with such detected devices? thanks in advanced, hope someone can answer :)

PD: For all people talking about pmount hald etc i think that they didn't understand the post, the main goal of this post is not to use such extra daemons which have to be started at boot time and we don't want this to be this way. It's very easy to understand, i say this cause in other posts also happens the same. So people wanting to use pmount etc don't have to read neither post here to say that exist other solutions as long as the autor seems to know them and doesn't want to use. Any other post trying to improve this method is welcome. Just an opinion.
_________________
Si el tonto te alaba laméntalo, si el listo te censura piénsalo.
Back to top
View user's profile Send private message
andersbk
n00b
n00b


Joined: 16 Aug 2003
Posts: 35

PostPosted: Wed Feb 22, 2006 6:44 pm    Post subject: Reply with quote

Beerman...or anyone that has hotpluging of CF working.

I'm trying to get udev and hotplug working with the built in multireader of my Dell 2405fpw. Udev seems to be working, kindof, but I don't get any events when I plug in a CF card. Help needed.

First, here are the relevent udev rules I'm using:
Code:

#Dell 2405FPW LCD Monitor card reader
BUS="scsi", SYSFS{model}="223 U HS-CF", KERNEL="sd?1", NAME="%k", SYMLINK="dellcf"
BUS="scsi", SYSFS{model}="223 U HS-MS", KERNEL="sd?1", NAME="%k", SYMLINK="dellms"
BUS="scsi", SYSFS{model}="223 U HS-SM", KERNEL="sd?1", NAME="%k", SYMLINK="dellsm"
BUS="scsi", SYSFS{model}="223 U HS-SD/MMC", KERNEL="sd?1", NAME="%k", SYMLINK="dellsd"


If I turn my monitor on without any card type in the multireader, I get:
Code:

usb 1-2.1.1.1: new full speed USB device using ehci_hcd and address 43
  Vendor: SMSC      Model: 223 U HS-CF       Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 8:0:0:0: Attached scsi removable disk sdb
  Vendor: SMSC      Model: 223 U HS-MS       Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 8:0:0:1: Attached scsi removable disk sdc
  Vendor: SMSC      Model: 223 U HS-SM       Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 8:0:0:2: Attached scsi removable disk sdd
  Vendor: SMSC      Model: 223 U HS-SD/MMC   Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 8:0:0:3: Attached scsi removable disk sde
usb-storage: device scan complete

# ls -ltr /dev
brw-rw----  1 root disk    8,  16 Feb 22 11:39 sdb
brw-rw----  1 root disk    8,  32 Feb 22 11:39 sdc
brw-rw----  1 root disk    8,  48 Feb 22 11:39 sdd
brw-rw----  1 root disk    8,  64 Feb 22 11:39 sde



Next, if I plug in a CF in the reader, nothing happens, nothing changes in dmesg, and no new dev entries are created by udev.

Now if I turn the monitor off, and then power it up again, but this time with a CF card inserted, I get:
Code:

usb 1-2.1.1.1: new full speed USB device using ehci_hcd and address 49
  Vendor: SMSC      Model: 223 U HS-CF       Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
SCSI device sdb: 2014992 512-byte hdwr sectors (1032 MB)
sdb: Write Protect is off
sdb: Mode Sense: 23 00 00 00
sdb: assuming drive cache: write through
SCSI device sdb: 2014992 512-byte hdwr sectors (1032 MB)
sdb: Write Protect is off
sdb: Mode Sense: 23 00 00 00
sdb: assuming drive cache: write through
 sdb: sdb1
sd 9:0:0:0: Attached scsi removable disk sdb
  Vendor: SMSC      Model: 223 U HS-MS       Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 9:0:0:1: Attached scsi removable disk sdc
  Vendor: SMSC      Model: 223 U HS-SM       Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 9:0:0:2: Attached scsi removable disk sdd
  Vendor: SMSC      Model: 223 U HS-SD/MMC   Rev: 3.60
  Type:   Direct-Access                      ANSI SCSI revision: 00
sd 9:0:0:3: Attached scsi removable disk sde
usb-storage: device scan complete

# ls -ltr /dev
brw-rw----  1 root disk    8,  16 Feb 22 11:36 sdb
brw-rw----  1 root disk    8,  32 Feb 22 11:36 sdc
brw-rw----  1 root disk    8,  48 Feb 22 11:36 sdd
brw-rw----  1 root disk    8,  17 Feb 22 11:36 sdb1
lrwxrwxrwx  1 root root         4 Feb 22 11:36 dellcf -> sdb1
brw-rw----  1 root disk    8,  64 Feb 22 11:36 sde



Notice that this time, the CF card is registered and there's now a /dev entry I can use to mount to.

How do I get the multi reader to "post" that a card has been inserted? Am I missing some hotplug thing here? Does anyone know?

TIA,
-anders.
Back to top
View user's profile Send private message
andersbk
n00b
n00b


Joined: 16 Aug 2003
Posts: 35

PostPosted: Fri Feb 24, 2006 4:49 pm    Post subject: Multi reader success Reply with quote

I got it working. My Dell 2405fpw multi-reader is alive!

Here's the details. Basically, I still don't get any "notification" when a CF card is inserted, however, using the following setup works and seems clean to me.

The relevant udev rules for the 2405fpw are now:
Code:

BUS="scsi", SYSFS{model}="223 U HS-CF",     KERNEL="sd*", NAME="dell/cf%n", OPTIONS="all_partitions"
BUS="scsi", SYSFS{model}="223 U HS-MS",     KERNEL="sd*", NAME="dell/ms%n", OPTIONS="all_partitions"
BUS="scsi", SYSFS{model}="223 U HS-SM",     KERNEL="sd*", NAME="dell/sm%n", OPTIONS="all_partitions"
BUS="scsi", SYSFS{model}="223 U HS-SD/MMC", KERNEL="sd*", NAME="dell/sd%n", OPTIONS="all_partitions"


I then decided to use submount (emerge --search submount for details), which incidentally am also using for my CD and DVD drives. Submount is very very nice for removable media. Good man page too.

Anyhow, the following is my fstab entry to mount the CF card, regardless of its presence:
Code:

/dev/dell/cf1           /mnt/dell/cf1   subfs           fs=vfat,users,exec,umask=0,defaults                0 0


Mount shows:
Code:

> mount
/dev/dell/cf1 on /mnt/dell/cf1 type subfs (rw,nosuid,nodev,fs=vfat,umask=0)


So, now I can just insert the card and it's there.

Just be careful to "sync" before removing to make sure all writes have taken.

out.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum