autofs is the linux automounter. It's a daemon that automatically mounts filesystems as they are accessed on demand.
The primary configuration file used by automount is
/etc/auto.master which defines what mounts automount is responsible for.
1 # 2 # /etc/auto.master 3 # 4 +auto.master 5 /home /etc/auto.home
In the example above, automount is responsible for mounting directories under /home and the configuration for it is under
/etc/auto.home. The configuration under
/etc/auto.home will define directories in
/home and their corresponding mount locations.
1 # 2 # /etc/auto.home 3 # 4 leo file1:/export/home/leo
Anyone going to
/home/leo will cause automount to mount
You may specify mount options by placing them before the mount location:
1 # 2 # /etc/auto.home 3 # 4 leo -fstype=nfs4 file1:/export/home/leo
Dynamic Automount Rules
The automount configuration can be made as a script to make mounting more intelligent. automount will pass in the mounting point to your
auto mount configuration.
For example, if home directories are stored on multiple file servers, we can make
/home the mounting point for all users by doing something like so:
1 # cat /etc/auto.home 2 #!/bin/sh 3 4 # Automount will pass in the username as the first parameter since we are 5 # mounting /home/<username> 6 Username=$1 7 8 # The default fileserver is 'file1' 9 Server="file1" 10 11 # The path to the mount for this user 12 Path="/export/home/$Username" 13 14 # As a proof of concept, we can make a specific user use a different filesersver 15 # Eg: leo's home directory will be mounted from file2 16 if [ "$Username" = "leo" ] ; then 17 Server="file2" 18 fi 19 20 # Echo out the configuration for automount 21 echo "-fstype=nfs4,sec=krb5,soft,rsize=8192,wsize=8192,rw $Server:$Path"