AutoFS  in Linux
Venu Reddy    1 
 
Linux: How To Setup AutoFS 
Installing AutoFS on Ubuntu Desktop 10.04.1 
I followed most of the instructions here: 
https://help.ubuntu.com/community/Autofs 
First, install this on the client: 
# apt-get install -y autofs 
Edit the /etc/auto.master file: 
/home /etc/auto.home 
+auto.master 
 which means for the local mount point /home, use the /etc/auto.home config file. 
Then edit /etc/auto.home: 
*   my-nfs-server:/home/& 
Unmount static mounts (if any) and edit /etc/fstab (if any): 
$ sudo umount /server 
Remove (or comment out) their respective entries in /etc/fstab. 
#server:/ /server/ nfs defaults 0 0 
Reload autofs: 
# /etc/init.d/autofs reload 
How to test that it works: 
1.  Create a user on the NFS server with a home directory. Create a test file like test-
nfs.txt. 
2.  Create the same user (without a home dir) on the NFS client with the same user ID and 
group ID (required). 
3.  Create a password for the new user on the NFS client. 
4.  Log into the NFS client as the new user and list files to see your test file. 
5.  This also works when you log in as the new user from the Ubuntu GUI login screen. 
 
AutoFS  in Linux 
Venu Reddy    2 
 
Another AutoFS example configuration 
Client 
/etc/auto.master: 
/nfs/home /etc/auto.home 
+auto.master 
/etc/auto.home: 
*  nfs-server:/nfs/home/& 
Even simpler, minimal AutoFS example configuration 
Client 
/etc/auto.master: 
/nfs /etc/auto.nfs 
+auto.master 
/etc/auto.nfs: 
*  nfs-server:/nfs/& 
# service autofs restart 
autofs start/running, process XXXXX 
===================================================================================== 
Mounting NFS File Systems using autofs 
A third option for mounting an NFS share is the use of the autofs service. Autofs uses the automount 
daemon to manage your mount points by only mounting them dynamically when they are accessed.  
Autofs consults the master map configuration file /etc/auto.master to determine which mount 
points are defined. It then starts an automount process with the appropriate parameters for each 
mount point. Each line in the master map defines a mount point and a separate map file that defines the 
file systems to be mounted under this mount point. For example, the /etc/auto.misc file might 
define mount points in the /misc directory; this relationship would be defined in the 
/etc/auto.master file.  
Each entry in auto.master has three fields. The first field is the mount point. The second field is the 
location of the map file, and the third field is optional. The third field can contain information such as a 
timeout value.  
For example, to mount the directory /proj52 on the remote machine penguin.example.net at the 
mount point /misc/myproject on your machine, add the following line to auto.master:  
/misc   /etc/auto.misc --timeout 60 
Next, add the following line to /etc/auto.misc:  
myproject  -rw,soft,intr,rsize=8192,wsize=8192 penguin.example.net:/proj52 
The first field in /etc/auto.misc is the name of the /misc subdirectory. This subdirectory is created 
dynamically by automount. It should not actually exist on the client machine. The second field contains 
AutoFS  in Linux 
Venu Reddy    3 
 
mount options such as rw for read and write access. The third field is the location of the NFS export 
including the hostname and directory.  
Note 
The directory /misc must exist on the local file system. There should be no subdirectories in /misc on 
the local file system.  
To start the autofs service, at a shell prompt, type the following command:  
 /sbin/service autofs restart  
To view the active mount points, type the following command at a shell prompt:  
 /sbin/service autofs status  
If you modify the /etc/auto.master configuration file while autofs is running, you must tell the 
automount daemon(s) to reload by typing the following command at a shell prompt:  
 /sbin/service autofs reload  
 
======================================================================= 
HOWTO Setup autofs on Fedora 
With autofs, the file systems are mounted as required or on demand, and then automatically 
unmounted when they have not been used for some time. This means you can have two machines 
both of which mount file systems from the other and the order you boot them does not  
matter as long as the remote system is not required during the boot. 
Before we begin you will need a machine that is exporting some shares over NFS so see my 
HOWTO install NFS on Fedora page for getting that setup first. I'll wait. 
So now you know how to setup NFS and get some directories shared. 
Installing the software on Fedora is as easy as any other with yum. 
sudo yum install autofs 
That will also install a number of configuration files into /etc and one in /etc/sysconfig. 
To set up a the automounts for the NFS shares being exported by a server we need to edit the file 
/etc/auto.master adding one line. Using the shares from a machine called linux32. we will be 
mounting them locally in /net/linux32/ 
with a 10 minute (600 second) time out.  
sudo nano /etc/auto.master 
AutoFS  in Linux 
Venu Reddy    4 
 
/etc/auto.master 
/net/linux32              /etc/auto.nfslinux32       --timeout=600  
The file in the middle does not exist, yet, we are about to create it.  
sudo nano /etc/auto.nfslinux32 
/etc/auto.nfslinux32 
home       -fstype=nfs,rsize=32768,wsize=32768,intr,tcp,noatime   linux32:/home  
You will need a line similar to the one above for each share from linux32. The magic of 
automounting is that you do not need to create all the local mount point directories yourself. they 
will be created and deleted as necessary. The entry in auto.master will create the first two 
directories /net and /net/linux32.  
To explain the layout of auto.nfslinux32. The first parameter is the mount point on the local 
machine. In this case home which means you will access the fs via /net/linux32/home. The next 
parameter -fstype gives the mounting options note it is an fs type of 'nfs'. 
The remaining options are from mount and fstab. Take a look at the man pages you may not 
want to use these. 
Make sure that the autofs service will startup at boot time. If not set it so it will. 
sudo chkconfig --list autofs 
autofs          0:off 1:off 2:on 3:on 4:on 5:on 6:off 
sudo chkconfig  autofs on 
Start, stop and reload the files for autofs without rebooting using the usual service command. 
sudo service autofs status 
sudo service autofs stop 
sudo service autofs start 
sudo service autofs restart 
sudo service autofs reload  
Very similar automounting will be done automatically when the mount point starts with /net. I 
found there were a few annoyances using the automatic configuration so I do the above. 
You may like to turn on the browse mode. This does have one downside in that it means that the 
auto mounts will be mounted each time you access the root directory where they are mounted. 
AutoFS  in Linux 
Venu Reddy    5 
 
Edit the file /etc/sysconfig/autofs changing the BROWSE_MODE flag to "yes" and reloading 
autofs 
/etc/sysconfig/autofs 
sudo nano /etc/sysconfig/autofs 
sudo service autofs reload  
 
Further reading 
1.  Man pages for autofs, auto.master, mount, umount, nfs 
2.  The mount & umount commands, how to mount stuff and it's options and get it unmounted 
again. 
3.  /etc/fstab how to mount file systems automatically at boot time 
4.  a href="http://blogging.dragon.org.uk/index.php/mini-howtos/howto-install-nfs-of-
fedora">HOWTO install NFS on Fedora 
5.  /etc/hosts file IP lookups 
6.  /etc/hosts.allow and /etc/hosts.deny A bit of security 
7.  Setting up Samba/Cifs