LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 11-28-2007, 12:16 PM   #1
BigWaveDave
LQ Newbie
 
Registered: Nov 2007
Location: Santa Barbara, CA
Distribution: MontaVista Linux 4
Posts: 3

Rep: Reputation: 0
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.
 
Old 11-28-2007, 05:48 PM   #2
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,443

Rep: Reputation: 73
You might want to explore udev as well...
 
Old 11-28-2007, 06:08 PM   #3
rsashok
Member
 
Registered: Nov 2006
Location: USA, CA
Distribution: RedHat, Debian
Posts: 202

Rep: Reputation: 31
I am not sure about MontaVista, but normally all these stuff is in /etc/fstabs.
 
Old 12-02-2007, 09:37 PM   #4
kennithwang
Member
 
Registered: Aug 2007
Location: shanghai
Distribution: LDD
Posts: 32

Rep: Reputation: 15
What is kernel version of MontaVista Linux 4.0.1?
 
Old 12-05-2007, 01:06 AM   #5
BigWaveDave
LQ Newbie
 
Registered: Nov 2007
Location: Santa Barbara, CA
Distribution: MontaVista Linux 4
Posts: 3

Original Poster
Rep: Reputation: 0
Kernel Version

The kernel version is 2.6.10.
 
Old 12-05-2007, 11:20 AM   #6
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
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]
 
Old 12-05-2007, 11:37 AM   #7
shadowsnipes
Senior Member
 
Registered: Sep 2005
Distribution: Slackware
Posts: 1,443

Rep: Reputation: 73
Check this page out about writing udev rules.

http://reactivated.net/writing_udev_rules.html
 
Old 12-11-2007, 12:58 AM   #8
Peter_APIIT
Member
 
Registered: Dec 2006
Posts: 606

Rep: Reputation: 31
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.
 
Old 12-11-2007, 10:44 AM   #9
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
Quote:
Originally Posted by Peter_APIIT View Post
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
 
Old 12-31-2007, 08:03 PM   #10
elliott678
Member
 
Registered: Mar 2005
Location: North Carolina
Distribution: Arch
Posts: 977

Rep: Reputation: 74
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.
 
Old 06-06-2008, 09:34 AM   #11
edholdsworth
LQ Newbie
 
Registered: Jun 2008
Posts: 1

Rep: Reputation: 0
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.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
USB flash drive (Pen drive) mounts read only prabhatsoni Linux - Hardware 24 07-02-2007 01:28 PM
Automounting Of USB Flash Disks / Network Browsing gruelius Linux - General 1 02-26-2007 08:27 PM
cannot delete drive from root desktop - cannot mount usb flash drive - openSuSE 10.2 bluecog6 Linux - General 6 01-29-2007 03:18 PM
automounting usb drive with -noexec off Rohan_mk1 Linux - Software 0 12-13-2006 09:53 AM
automounting my USB flash drive Artex Linux - Newbie 2 08-27-2006 10:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration