sections in this module City College of San Francisco - CS260A
Unix/Linux System Administration

Module: Filesystems III
module list

The automounter

Note: this is not an exhaustive treatment of the automounter. We will, however, learn how to mount filesystems using it.

When we were discussing the use of the CD and USB drives for sources of data, you probably noticed that it is difficult at the commandline to know where the data is, since the system automatically creates a mount point and mounts the device for you, somewhere under /media. There is one other unfortunate problem that has been overlooked - this time with NFS-mounted filesystems. When an NFS filesystem is placed in the fstab, the system will stop during boot until either the NFS mount is available or it times out, which is often quite long (several minutes). In fact, an unavailable NFS-mounted filesystem that is hard-mounted, which is the safest type for data, can seriously cripple a system if it is mounted from the fstab since the system will periodically try to mount the filesystem until it becomes available. In addition, if the filesystem becomes unavailable, the system may hang waiting for it.

Both of these problems are alleviated by judicious use of the automounter. With the automounter, you specify that a particular directory is mounted from a device (or NFS location), and the actual mount is delayed until the directory is accessed. Further, the directory is unmounted automatically if it is unused for a period. This means:

the CDROM's data, for example, can be made available at a particular static directory. (This is in addition to rather than instead of the auto-generated mount point)

an NFS location can be the source of data at one or more specified directories, and the NFS location will not be mounted until the directory is accessed. Further, since essentially a backgrounded process keeps testing the NFS location for availability, accessing the directory fails immediately if the NFS location is unavailable, rather than having to time-out. This is not to say that using the automounter solves any NFS hanging problems - you can still hang the system badly, especially if the automounter is misconfigured.

Configuring the automounter

automount is a daemon used to monitor automounted filesystems and configure them according to changes. It is started by the autofs subsystem. automount is configured using global options in /etc/sysconfig/autofs. The locations it automounts are configured using a set of configuration files in the /etc directory, called maps. There are three type of map files:

Let's consider a simple scenario:

You have three partitions

Most of the time this data is not being used, and you would like it to be safely unmounted. You would like these partitions containing "your stuff" to be placed at a common directory beneath /home, say, /home/mystuff. The mounted locations should be /home/mystuff/audio, /home/mystuff/video and /home/mystuff/docs

Besides your "stuff". you  also have a directory containing a set of installation files (the contents of an installation CD) that is on another system, but is available using NFS. You want this directory to be mounted when it is accessed, but you need it to be mounted at /inst.

We will configure these using an indirect map for your three personal partitions and a direct map for /inst.

Here is how this situation would be configured: Your master map (auto.master) would contain two configuration lines:

Remember, direct and indirect map files are meaningless unless they are entered in the master map.

Let's look at the lines from each of these three files:

lines from /etc/auto.master

# the first line is a special syntax that refers to the direct map
/-  /etc/auto.direct    
# now the indirect map
/home/student/mystuff   /etc/auto.mystuff

contents of /etc/auto.direct

/inst   -hard,intr,nolock  192.168.122.251:/SL

contents of /etc/auto.mystuff

audio   -fstype=ext4   :/dev/vda11
video   -fstype=ext4   :/dev/vda12
docs   -fstype=ext4   :/dev/vda13

Now that we have shown an example, let's discuss each of these pieces in more detail.

The master map

The master map, whose name is given in /etc/sysconfig/autofs, is used to associate files with direct and indirect maps. The format of these lines is

direct map:

/-  pathtomapfile

indirect map:

mountpoint  pathtomapfile

The direct and indirect maps have the same format

key [ -mountopts ]  location

where

key is the subdirectory of mountpoint that is to be automounted

mountopts is a comma-separated list of options to mount(8) and location is usually an NFS mount. mountopts are preceded by a dash (-), and are optional, however, the default location type is NFS. If location is a device file (as in our example), the special mountopt -fstype=x must be specified.

location is an NFS location or a device with a : prefix. If you want to mount your device by UUID, use the device /dev/disk/by-uuid/UUID

automounting home directories

Using the automounter to mount the user's home directory at login is inviting especially if the user account is a network (NIS, LDAP) account. This is more convenient if you use a special capability of the automounter, to specify a line in the home directory's indirect map to mount any directory beneath a mount point. Let's see how this works:

Suppose you have an NIS or LDAP server configured to provide authentication over the network for a set of twenty users. Their home directories are available via NFS on foo.com in the standard /home location. As usual, once authentication succeeds, they will be connected to their home directory. We want this home directory to be automounted from foo.com when they connect to it.

Obviously, we will have an entry in /etc/auto.master to configure /home using an indirect map. Here is the line from /etc/auto.master

/home    /etc/auto.home

Now, in /etc/auto.home, we want to mount foo.com:/home/yyy as /home/yyy for any yyy. Here is what the entry looks like

*  -mountopts  foo.com:/home/&

The * is intuitive - it means 'mount any subdirectory'. The & means 'take the name of the directory you mounted (remember, this is relative to /home) and insert it here'. Thus, if the user gboyd logged in, an attempt would be made to connect to /home/gboyd, which would result in the automounter trying to mount foo.com:/home/gboyd on /home/gboyd. If it was successful, the user is connected. If the automount fails, the user is connected to / .

Unfortunately, there is a problem here: usually the system you are on has its own [local] accounts and they are configured beneath /home. Since the automounter wants complete control of /home in order to mount any directory beneath it independently, this mix of local and remote home directories wont work.

There are three solutions to this issue:

/home/foo   -NFSopts  server:/home/foo

Using a remote-mounted home directory

The use of remote-mounted home directories assumes that the user is authenticating against the same server that houses the home directories. This is not necessarily true, however. It is possible to use remote home directories with a local account so long as a matching account with the same uid and gid exists on the server. Keeping multiple such accounts synchronized across multiple systems is problematic of course, but it is possible for a single account and a few systems.

Reloading the map files

Changes to an indirect map file are supposed to be incorporated the next time an automount is performed automatically. Changes to direct map files or to the auto.master file require reloading the maps. The simplest way is to use service autofs reload.

The auto.misc file

Most versions of the automounter come with a preconfigured auto.misc file that reserves /misc as an automount location for various things. Examples in the auto.misc indirect map file indicate mounting the CDROM device at /misc/cd, for example, which alleviates the issue at the beginning of this section with not knowing the path to the CD's data from the command-line. Take a look at it.

Unresponsive NFS server

If the automounter tries to mount an unavailable NFS directory the result could hang the process. There are two situations to consider here:

Prev This page was made entirely with free software on linux:  
the Mozilla Project
and Openoffice.org      
Next

Copyright 2012 Greg Boyd - All Rights Reserved.