Configuring automounter

The automounter detects when a removable disk has been inserted or removed and automatically mounts or unmounts the drive. This is most efficiently done by the kernel. However the program and its documentation are quite confusing. Below is a procedure for configuring it. We use this with Samba to allow Windows users to back up their hard drives on a Jaz drive attached to a Linux machine over the network.
  1. Enable kernel automounter support in `make config' and recompile the kernel. Install the new kernel and reboot.
  2. Create a file /etc/auto.master containing the `master' mount points followed by the name of a configuration file:
    /mnt    /etc/auto.mnt
    Don't add a 3rd column for '--timeout 300' as some people recommend. This should be done in the /sbin/init.d/autofs script (mainly because it doesn't always work in auto.master).
  3. For each entry in auto.master, create a config file. In this case, there is only one, /etc/auto.mnt which contains 4 lines corresponding to 4 mount points:
    cd              -fstype=iso9660,ro                :/dev/cdrom
    jaz             -fstype=auto,user,suid            :/dev/sda
    zip             -fstype=auto,user,suid            :/dev/sdb
    floppy          -fstype=auto                       :/dev/fd0
    The colon in the last column is necessary if it starts with a '/'. Whenever a read/write accesses /mnt, the automounter checks the file listed in /etc/auto.master. The floppy is not mounted at /mnt as one might expect, but at /mnt/floppy, by concatenating the file extension (mnt) of /etc/auto.mnt with the label from the first column of /etc/auto.mnt that matches the user's command line. Inserting a floppy will have no effect until a read/write is performed. For example, if a user typed
    cp myfile.txt /mnt/floppy 
    /dev/fd0 is automatically mounted at /mnt/floppy (which is created automatically). After a predefined period of inactivity, /dev/fd0 is automatically unmounted and the 'floppy' subdirectory is removed.
  4. Change the line
     time='-t 300' 
    in /sbin/init.d/autofs to a shorter timeout value (such as 3 seconds), so that people don't try to remove disks that are still mounted. (They will try, and they will ask you for paper clips to get the disk out.)
  5. Add an entry in /etc/fstab containing the correct mount point (e.g., /mnt/floppy) so that umount can also be used to unmount the disk if desired.
  6. A common problem is that only root is able to copy files to the mounted disk. The following steps are needed for regular users to be able to mount and use it.
    1. Add 'user' to /etc/fstab to allow the user that mounted the drive to unmount it, or 'users' to allow any user to unmount it.
    2. Set the umask in /etc/fstab (preferred), /etc/auto.master, or /sbin/init.d/autofs (at the "localoptions" line). For example, an fstab line would be:
      /dev/fd0    /mnt/floppy     auto     rw,user,umask=000 0   0 
      Changing the umask in /etc/auto.master or autofs will only work if the disk is formatted for DOS (FAT or FAT32). Otherwise, this option is illegal and will prevent automount from starting. Setting it in /etc/fstab allows permissions to be different for each disk.
    3. For ext2 fs disks, once they are formatted, run the command
      chmod a+rwx /mnt/floppy   
      as root. Note that chmod -R'ing the /mnt directory has no effect, and if you chmoded /mnt itself, it would just get changed back automatically by automount.
  7. To check the automounter status, run '/sbin/init.d/autofs status' - if a disk is mounted, it should say
    dalek:/etc# /sbin/init.d/autofs status
    Checking for service autofs: OK
    Configured Mount Points:
    automount -t 3 /mnt file /etc/auto.mnt  
    Active Mount Points:
    automount -t 3 /mnt file /etc/auto.mnt
  8. '/sbin/init.d/autofs start' will start the automounter daemon and print a number of entries to syslog. Using 'stop' will stop it and 'restart' will cause it to re-read /etc/auto.master. In SuSE Linux, these commands should already be in /sbin/init.d/autofs which is linked from /sbin/init.d/rc2.d/S17autofs and /sbin/init.d/rc2.d/K24autofs (actual numbers may be different), which start and stop the automounter automatically when runlevel 2 is reached or left. Note, autofs is just a fancy script that calls /usr/sbin/automount.
  9. '/sbin/init.d/autofs reload' will check the auto.master map and change those deamons whose entries have changed.
  10. usr/lib/autofs also should contain a number of .so files.
  11. Running 'df' or 'mount' is the easiest way to find out what disks are mounted.
  12. In SuSE, it is also necessary to set START_AUTOFS in /etc/rc.config, otherwise /sbin/init.d/autofs will not execute. Alternatively edit autofs to get rid of the line 'test "START_AUTOFS = yes || exit 0' in /sbin/init.d/autofs.
  13. See 'man 5 autofs', 'man 8 autofs', and 'man auto.master' for more details.
The automount/autofs program does not work very well. Frequently it is unable to correctly mount floppy disks, spewing diagnostic error messages all over the console. For some reason, it is also unable to mount DOS-formatted zip disks on a SCSI drive. Because it sends a large number of commands in a short time, automount/autofs is extremely rough on disk drives. For example, one week after installing it, I typed a 'cp' command to copy files to a zip drive. Automount sent a huge number of commands to the drive, but was unable to mount it, and caused the drive to undergo the "click of death", ruining the drive. At this point, I removed automount and autofs and went back to the old method. The absence of a functional and safe automounter is a major weakness in Linux.