LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   automounting USB Flash Drive (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/automounting-usb-flash-drive-603031/)

BigWaveDave 11-28-2007 12:16 PM

automounting USB Flash Drive
 
I'm wondering if anyone has tackled the issue of having a USB flash drive automatically mount to the file system when it is inserted? I am working on a TI DM355 DaVinci EVM board running MontaVista Linux 4.0.1.

I can do this manually easily enough by:

mkdir /mnt/usbflash
mount /dev/sda1 /mnt/usbflash

To make this mount occur automatically, I *think* that I need to use autofs to do this, but if that's wrong I'd like to know.

Using autofs, here is what I did...

I inserted the following into /etc/auto.master:
/mnt/usbflash /etc/auto.usbflash --timeout=30 --ghost

I inserted the following into /etc/auto.usbflash:
usbflash -fstype=auto,sync :/dev/sda1

I then:
mkdir /mnt/usbflash
/etc/init.d/autofs restart

and this appeared to work. But for some reason, the directory /mnt/usbflash was mysteriously deleted. And inserting the USB stick does not force an automatic mount.

Any suggestions?
Thanks in advance.

shadowsnipes 11-28-2007 05:48 PM

You might want to explore udev as well...

rsashok 11-28-2007 06:08 PM

I am not sure about MontaVista, but normally all these stuff is in /etc/fstabs.

kennithwang 12-02-2007 09:37 PM

What is kernel version of MontaVista Linux 4.0.1?

BigWaveDave 12-05-2007 01:06 AM

Kernel Version
 
The kernel version is 2.6.10.

schneidz 12-05-2007 11:20 AM

im not sure if this is elegant but you can waste negligible processor cycles by doing something like:
[untested]
Code:

while [ 1 ]
do
 mnt=`dmesg | tail | grep usb` # my system spits out the make/ model of the usb thumb drive when i insert it
 if [ mnt ]
 then
  mount /mnt/point /dir
 fi
done

[/untested]

shadowsnipes 12-05-2007 11:37 AM

Check this page out about writing udev rules.

http://reactivated.net/writing_udev_rules.html

Peter_APIIT 12-11-2007 12:58 AM

You can download a program called automount and this program will automatically mount a usb flsh drive for you without any edit of /etc/fstab or script.

schneidz 12-11-2007 10:44 AM

Quote:

Originally Posted by Peter_APIIT (Post 2986805)
You can download a program called automount and this program will automatically mount a usb flsh drive for you without any edit of /etc/fstab or script.

this seems like the least abrasive solution. i've never looked at the source for automount but i suspect that it does the equivelent of :
Code:

while [ 1 ]
do
 mnt=`dmesg | tail | grep usb` # my system spits out the make/ model of the usb thumb drive when i insert it
 if [ mnt ]
 then
  mount /mnt/point /dir
 fi
done


elliott678 12-31-2007 08:03 PM

If you have udev, you could use something like this:
Code:

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%n"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /mnt/usb%n", 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 /mnt/usb%n", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usb%n"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /mnt/usb%n", OPTIONS="last_rule"

It will probably need tweaking to work with your specific setup, this is my setup and it works very well.

edholdsworth 06-06-2008 09:34 AM

udev is the best approach
 
Depends on your version of Montavista but 5.0 has udev support and as people have contributed above this is the best way.


All times are GMT -5. The time now is 09:39 AM.