Automatically mounting USB w/o GUI?

Benjamin Scott dragonhawk at gmail.com
Tue Jul 27 15:36:54 EDT 2010


On Tue, Jul 27, 2010 at 10:01 AM, Tom Buskey <tom at buskey.name> wrote:
> I want my USB drive to show up mounted on /media/<some label> after I plug
> it in. I don't mind having to type something on the command line to trigger it.

  I can describe one way to do this.

A1. Set-up devfs or hotplug or udev or DeviceKit or whatever it is
this week to give your USB flash storage device a consistent name
under /dev/  Let's say /dev/foo but you could use /dev/sandisk or
/dev/jumpdrive or whatever you like.

A2. Add an entry to /etc/fstab associating /dev/foo with /media/foo
(or /mnt/foo or whatever); give it a mount option of "users" so that
any user can mount it

A3. Now, when you plug in the flash thingy, you can do "mount
/media/foo" and it will mount.  You don't need to be root.

  If you want, you could also add:

A4. Use automount/autofs/amd/whatever, so that when a user attempts to
access /auto/foo, the system automatically tries to mount /dev/foo on
/auto/foo.  Optionally, create a symlink from /media/foo to /auto/foo
to make that more obvious.

  If the flash device is FATor some other non-Unixy filesystem:

A5. Add uid/gid/umask/dmask options to the /etc/fstab entry so that
the appropriate users can read/write the mounted filesystem.

  One attribute of this approach is that other than step A1, all steps
use standard Unix techniques which have been around since before USB
was even invented.  I strongly prefer this building block approach,
rather than the "throw everything out and start from scratch with
every problem" that seems to have invaded Linux in the past few years.

  IMO.  YMMV.  HTH.  HAND.

-- Ben


More information about the gnhlug-discuss mailing list