Using automount and samba

Automount and Samba for removable devices

Samba is great, but when it comes to removable devices, it can be a bit problematic.  Here is a solution to using samba, with automount to support removable devices.

Step1. Install automount.
This requires a kernel component and a user space application.  If you are using a distribution, it may already be installed.

Step 2. Configure automount
This is documented in the automount readme, but I am not sure if it works correctly.  I suggest you start with the following settings and work from there.

/etc/auto.master
/auto    /etc/auto.misc     --timeout 30

/etc/auto.misc
zip1  -user,umask=0,fstype=vfat  :/dev/sdc1
zip4  -user,umask=0,fstype=vfat  :/dev/sdc4
cdrom -ro,fstype=iso9660         :/dev/scd0

In this case, there is a zip disk at /dev/sdc.  For unknown reasons, some zip disks are partitioned to use partition 1, others use partition 4.   Add both and then you can use either.

There is also a cdrom /dev/scd0

Step 3. Test you automount configuration
You will need to start/restart automount.  When you change to /auto/zip1, /auto/zip4 and /auto/cdrom, you should be able to access the media.

Step 4. Umounting.
For some reason, the --timeout 30 option did not work for me, so I added a root cronjob
* * * * * killall -USR1 automount
You can edit your crontab by typing
crontab -e

It has been suggested that the correct syntax should be --timeout=30 but RedHat 6.2's autofs package now works with a space so I assume that most people can skip this step.

Step 5 . Samba
Now, because we want samba to give a point and click interface to the users, we want it to show a list of available media.  The way to do this is create a samba share such as
[automount]
path = /autoshare
read only = No

Step 6. Create some symbolic links
now, create the /autoshare directory and create symbolic links to the /auto/xxx directories.
mkdir /autoshare
ln -s /auto/zip4 /autoshare/zip4

etc...

Step 7. Try it out
Restart samba and try it out.

You should see a share called autoshare.  When you select it, samba will stat all the files in the directory.  This will trigger automount to try and mount all the unmounted entries (which have links to them).  If the device can be mounted, the user will see it, if it can't be mounted (because there is no media), samba will decide the file does not exist and will not list it.

The device will be umounted as soon as it can, so the user can remove the media without having to issue eject or umount commands.

Note:
There are security risks associated with this technique, but as removable media are not secure anyway, who cares?

Why not just use preexec and postexec?
The postexec is only executed after all handles to the share are closed, and the connection times out.  By default, the connection never times out.  You can set the timeout to one minute, but if you keep an explorer window open there are still open handles so the timeout still won't expire.

To make matters worse, the timeout is based on a host to host session, so if you are using another share on the machine, the timeout would never occur. That is why I worked out this solution.

the preexec/postexec does work, but is not friendly to users who don't understand why you can't eject a disk that is in use.


Last modified 20020507
Maintained by John Newbigin