Home > Linux, NFS, Ubuntu > Configure Automount/Autofs on Ubuntu 10.10 Maverick Linux

Configure Automount/Autofs on Ubuntu 10.10 Maverick Linux

Automount/autofs is a Linux daemon which allows for behind the scenes mounting and unmounting of NFS exported directories.  Basically with autofs NFS shares will be automatically mounted when a user or system attempts to access their resources and disconnected after a period of inactivity.  This minimizes the number of active NFS mounts and is generally transparent to users.

First we’ll install autofs and include the NFS client:

# sudo apt-get -y install autofs nfs-common

Now we need to define autofs maps, which are basically configuration files which will tell autofs what types of NFS mounts to define.  With autofs there are two types of maps, direct and indirect.  With direct maps we define a list of filesystems to mount that will not share a common higher level directory on the client.  With indirect maps they share a common directory hierarchy, and a bit less overhead is required.  The advantage with direct maps is that if the user runs a common such as “ls” on the directory structure above the directory will show up, whereas with indirect maps they have to actually access the contents of the directory itself.  This can cause some confusion for users because running “ls” on a directory containing indirect mounts will not show the autofs directories until after the contents within have been accessed.  Indirect maps may also not be available by browsing the directory structure with a GUI file manager, you’ll need to specifically type in the path to get to it.  In this example I’ll show the use of both types of maps.

Master Map

First we need to define a master map, which basically will tell us what indirect/direct maps we want to use and the appropriate config files to read.  Edit the “auto.master” file and append this content:

# sudo vi /etc/auto.master

# directory    map
/server1       /etc/auto.server1
/-             /etc/auto.direct

The first entry is an indirect map, all of the mounts will be created under /server1 directory and the configuration will be read from “auto.server1”.  With direct maps we use a special character “/-” and will read the config from “auto.direct”.

Indirect Maps

Time to set up our indirect maps:

# sudo vi /etc/auto.server1

apps        -ro server1:/nfs/apps
files       -fstype=nfs4 server1:/nfs/files

The first column represents the subdirectory to be created under “/server1”.  The second shows the host and NFS export, with apps mounted as read only.  Notice with files that we specify NFSv4, obviously the NFS share must be compatible with NFSv4.  Not specifying an “fstype” should revert autofs to using NFSv3.

Direct Maps

Now we’ll do a direct map:

# sudo vi /etc/auto.direct

/mnt/data     server1:/nfs/data

Setting up a direct map is basically like configuring an NFS mount in the “/etc/fstab” file.  Include the full directory name from /, and include the host and NFS export names.  The options that we used with the indirect maps above can also be used on direct map mounts if desired.

While I don’t believe it is explicitly required, I have had difficulty accessing NFS shares unless the directory for the direct map is created manually before running autofs:

# sudo mkdir /mnt/data

Now we need to configure automount/autofs to start when the system starts:

# sudo update-rc.d autofs defaults

I am using the “update-rc.d” command, which has very similar functionality to the “chkconfig” utility in the Red Hat world.  It will create links in the various runlevel directories to the daemon’s initialization script.  Autofs is the daemon name, and using the defaults options tells the system to start autofs in runlevel 2-5, and stop in 0, 1, and 6.  Most of the startup runlevels are not used with Debian/Ubuntu, runlevel 2 is the one that matters most to us.

Now restart the autofs daemon to pickup the new configuration:

# sudo service autofs restart

Browse to the newly established autofs mounts or type in the full path where you mounted the NFS export if using indirect maps.  The files on your NFS host should now be available on your client!

Categories: Linux, NFS, Ubuntu Tags: , ,
  1. Gregory
    September 28, 2011 at 3:31 pm

    This was a lot more useful than the ubuntu community documentation. Thanks!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: