# Automatically mounting USB pens

## barry

Is it possible to have USB pens automatically mounted? Supermount isn't going to work as far as I'm aware, because the device doesn't exist until you insert the pen, and is deleted when you remove it.

It's a pain having to explain that in Windows you can insert and remove the devices while in Linux you have to mount and unmount it first.

----------

## NeddySeagoon

barry,

You don't have to let devfs create and delete /dev/sda1. Take the pen drive out of devfsd control and run mknod to manually create the device special files that you need.

Supermount may work then.

----------

## barry

I guess that might work. Any idea on what needs to be done to stop devfsd from handling /dev/sda?

----------

## mariadne

In my case, with USB removable media enabled (USB pen) when configuring the kernel (In SCSI section) I just have 

/dev/sda1               /mnt/USB        vfat    noauto,user     0 0

in my fstab. 

I then create a desktop icon for easy access.

I just plug in the USB pen, click the icon and thats just all.

In order to check if the USB pen mounts automatic, just issue the command tail /var/log/messages to see whether it is detected or not.

Spiros

----------

## barry

But doing it this way still means having to unmount the pen manually before removing it. I'd like to do away with that - you can do it with a floppy disk using supermount, since /dev/fd0 is always there.

----------

## mariadne

 *barry wrote:*   

> But doing it this way still means having to unmount the pen manually before removing it. I'd like to do away with that - you can do it with a floppy disk using supermount, since /dev/fd0 is always there.

 

To umount it you just right click on the desktop icon and select "umount". Isn't that the same with Windows, where you click the icon in the system tray so as to "remove the PnP device" safely?

Spiros

----------

## vonhelmet

 *barry wrote:*   

> But doing it this way still means having to unmount the pen manually before removing it. I'd like to do away with that - you can do it with a floppy disk using supermount, since /dev/fd0 is always there.

 

Dude, you have to unmount memory sticks manually in Windows to avoid sync errors and data loss... Is it that much hassle to do the same in Linux?

----------

## barry

Ah, I thought in Windows you could just remove it at any time. Still, it would be possible to avoid mounting and unmounting it in Linux, I'm just trying to work out how. If devfsd didn't create and delete the device I think supermount would probably work.

----------

## sabaisabai

I have managed to get it auto-mounting, using hotplug.  It was very problematic though because I wasn't able to catch the event for device removal.  And also, with the sync problem, I found that the data wasn't written unless I cleanly unmounted it first.

----------

## barry

This is why I thought supermount would be suitable. From http://supermount-ng.sf.net -

 *Quote:*   

> Supermount detects when you have finished activity on the subfs, and will flush all buffers to the disk before completing the operation. So, if you copy a file onto a supermounted floppy disk, the data will all be written to disk before the "cp" command finishes. When the command does complete, it will be safe to remove the disk.

 

Surely this applies to USB storage too.

----------

## MrApples

i found this a couple of months ago when having this same issue:

https://listman.redhat.com/archives/rhl-devel-list/2003-August/msg00115.html

----------

## genstef

Ivman tries to solve the iussue and it will finally be able to do so. But for the meantime I think there is a projekt called mntd, that also uses dbus and hal to detect when the device is plugged and unplugged. It will be necessary to use the sync option if you do not want to umount manually.

----------

## smart

As another option, we have "submount" in the portage tree.

----------

## Khan

 *NeddySeagoon wrote:*   

> barry,
> 
> You don't have to let devfs create and delete /dev/sda1. Take the pen drive out of devfsd control and run mknod to manually create the device special files that you need.
> 
> Supermount may work then.

 

Can you please provide and example of how to do this for those of us that don't know? That conf file needs a section titled "Uncomment below to tell devfsd to ignore the creation of specific devices". Examples are a wonderful thing   :Very Happy:   Thanks.

----------

## jonnevers

 *smart wrote:*   

> As another option, we have "submount" in the portage tree.

 

submount/subfs [ http://submount.sourceforge.net/ ]does exactly what you want, you create an /etc/fstab record for the removable device with type "subfs". then you mount that device once.

it will create an icon on your desktop and if using Gnome 2.6, an icon under computer:///

at that point the removeable media device works exactly like the removeable devices in windows. you click on the icon, if the device has media, you see the contents, if no media found, you are told so.

subfs is a compliment of supermount. the difference is submount runs mostly in userspace (rather then kernel space). you do need to compile support for subfs into your kernel though. i really like subfs.

-Jon

----------

## Khan

 *jonnevers wrote:*   

> 
> 
> submount/subfs [ http://submount.sourceforge.net/ ]does exactly what you want, you create an /etc/fstab record for the removable device with type "subfs". then you mount that device once.
> 
> -Jon

 

Jon,

 How does submount deal with the whole devfsd creation/deletion of devices? Does it come with any good examples for ubspens, drives, etc?

----------

## jonnevers

 *Khan wrote:*   

>  *jonnevers wrote:*   
> 
> submount/subfs [ http://submount.sourceforge.net/ ]does exactly what you want, you create an /etc/fstab record for the removable device with type "subfs". then you mount that device once.
> 
> -Jon 
> ...

 

this may get you started: 

http://gentoo-wiki.com/HOWTO_Submount

that explains how to install it and get it going for cdrw/dvd-rom/floppy

(keep in mind you don't need to compile manually, emerge submount is all you need to do to install it)

for a usb removeable pendrive an fstab record like:

```
/dev/sda1 /mnt/flash subfs auto,fs=vfat,noatime 0 0
```

should be what you are looking for, this assumes the /dev node for the device is /dev/sda1. submount should be able to gracefully handle a missing device node (i.e. you removed the pendrive from the usb bus). the first time you mount the device though, have it plugged in and the /dev available.

-Jon

----------

## nevynxxx

You may also want to look at udev and hal, they can be set up to achieve this.

----------

## Arker

 *nevynxxx wrote:*   

> You may also want to look at udev and hal, they can be set up to achieve this.

 

Yes, udev and hal work well for my cellphone that is seen as a USB Mass Storage device (as I suspect your pendrive is).

It seems there are many solutions, none of which are quite fool proof or "drop in". I love Linux   :Smile: 

~djc

----------

## adoarns

Autofs is the ebuild for automounter.  You have to compile your kernel without devfsd support and with automounter support.  Then, emerge autofs and udev.  The auto.master file in /etc/autofs tells the automounter which directories it controls.  I simply let it manage /mnt, and mount my usb pen, cdroms, etc. only when I need them--i.e., I cd to them.  Since I'm using udev and hotplug, the /dev/sda1 entry also only appears when it's plugged in.  And once you unplug it, the /dev entry goes away, and so does the mountpoint.

Not too terrible.

----------

