A    Writing Automount and AutoFS Maps

There are three types of Automount or AutoFS maps:

Note

The Automount daemon will be retired in a future release of the operating system. For information about migrating from Automount to AutoFS, see Section 4.6.2.4.

The maps can be written in a variety of ways. They can be simple or can use multiple mounts, shared mounts, replicated file systems, or any combination of the three. As discussed in Section A.1, indirect maps can be written to reduce redundancy by using substitution characters and pattern matching. The examples in this section illustrate how the same maps can be rewritten in a number of ways.

Figure A-1 illustrates an auto.master map that points to the /etc/auto.direct direct map, the built-in -hosts map, and the /etc/auto.home indirect map. Each map to which the auto.master map points is expanded to show its sample contents. Note that all of the information contained in the master map can be specified on the command line. The master map, however, simplifies Automount and AutoFS administration.

Figure A-1:  Sample automount Maps

The following examples show how the /etc/auto.direct map in Figure A-1 can be rewritten using multiple mounts (Example A-1); multiple mounts and shared mounts (Example A-2); and multiple mounts, shared mounts, and replicated file systems (Example A-3).

Example A-1:  Multiple Mounts in a Direct Map

/mnt/mytmp                          june:/usr/staff/jones/tmp
/mnt/mynotes                        june:/usr/staff/jones/notes
/usr/arch       /             -ro   chester:/usr/arch \
                /bsd          -ro   chester:/usr/arch/bsd \
                /standards    -ro   chester:/usr/arch/standards \
                /dec/uws      -ro   chester:/usr/arch/dec/uws \
                /dec/ultrix   -ro   chester:/usr/arch/dec/ultrix

Example A-2:  Multiple Mounts and Shared Mounts in a Direct Map

/mnt/mytmp                          june:/usr/staff/jones:tmp
/mnt/mynotes                        june:/usr/staff/jones:notes
/usr/arch       /             -ro   chester:/usr/arch \
                /bsd          -ro   chester:/usr/arch/bsd \
                /standards    -ro   chester:/usr/arch/standards \
                /dec/uws      -ro   chester:/usr/arch/dec/uws \
                /dec/ultrix   -ro   chester:/usr/arch/dec/ultrix

Example A-3:  Multiple Mounts, Shared Mounts, and Replicated File Systems in a Direct Map

/mnt/mytmp                          june:/usr/staff/jones:tmp
/mnt/mynotes                        june:/usr/staff/jones:notes
/usr/arch       /             -ro   chester:/usr/arch \
                /bsd          -ro   chester:/usr/arch/bsd \
                                    bazel:/src/bsd \
                /standards    -ro   chester:/usr/arch/standards \
                /dec/uws      -ro   chester:/usr/arch/dec/uws \
                                    fiesta:/archive/uws\
                /dec/ultrix   -ro   chester:/usr/arch/dec/ultrix

The /etc/auto.direct maps in the preceding examples could be rewritten as indirect maps. If the /etc/auto.direct map is rewritten to be an indirect map, the entry pointing to it in the auto.master map would look like the following:

/mnt     /etc/auto.indirect

Rewritten as a simple indirect map (/etc/auto.indirect), the /etc/auto.direct map in Figure A-1 would read as shown in Example A-4.

Example A-4:  Simple Indirect Map

mytmp           june:/usr/staff/jones/tmp
mynotes         june:/usr/staff/jones/notes
arch    -ro     chester:/usr/arch

Note that the key is a simple pathname.

The following examples illustrate that indirect maps can also be rewritten using multiple mounts (Example A-5); multiple mounts and shared mounts (Example A-6); and multiple mounts, shared mounts, and replicated file systems (Example A-7).

Example A-5:  Multiple Mounts in an Indirect Map

mytmp                               june:/usr/staff/jones/tmp
mynotes                             june:/usr/staff/jones/notes
arch            /             -ro   chester:/usr/arch \
                /bsd          -ro   chester:/usr/arch/bsd \
                /standards    -ro   chester:/usr/arch/standards \
                /dec/uws      -ro   chester:/usr/arch/dec/uws \
                /dec/ultrix   -ro   chester:/usr/arch/dec/ultrix

Example A-6:  Multiple Mounts and Shared Mounts in an Indirect Map

mytmp                               june:/usr/staff/jones:tmp
mynotes                             june:/usr/staff/jones:notes
arch            /             -ro   chester:/usr/arch \
                /bsd          -ro   chester:/usr/arch/bsd \
                /standards    -ro   chester:/usr/arch/standards \
                /dec/uws      -ro   chester:/usr/arch/dec/uws \
                /dec/ultrix   -ro   chester:/usr/arch/dec/ultrix

Example A-7:  Multiple Mounts, Shared Mounts, and Replicated File Systems in an Indirect Map

mytmp                               june:/usr/staff/jones:tmp
mynotes                             june:/usr/staff/jones:notes
arch            /             -ro   chester:/usr/arch \
                /bsd          -ro   chester:/usr/arch/bsd \
                                    bazel:/src/bsd \
                /standards    -ro   chester:/usr/arch/standards \
                /dec/uws      -ro   chester:/usr/arch/dec/uws \
                                    fiesta:/archive/uws\
                /dec/ultrix   -ro   chester:/usr/arch/dec/ultrix

The -hosts map is a built-in map supplied by Automount and AutoFS. This map allows a client to access directories that are exported from any host in its hosts database. The location of the hosts database that your system uses is determined by the services running on your system (DNS, NIS, local) and how those services are specified in the /etc/svc.conf file. References to a particular host name result in all of the file systems that are exported from that host being mounted on the local system. For example, the following command results in all of the file systems that are exported from host1 being mounted on the local system:

# cd /net/host1

The /etc/auto.home map shown in Figure A-1 is an indirect map that allows users to remotely mount their home directories. It can be rewritten using the ampersand (&) and asterisk (*) substitution characters.

The following example shows how the /etc/auto.home map in Figure A-1 can be rewritten using ampersands (&):

user1  host1:/usr/staff/&
user2  host2:/usr/staff/&
user3  host2:/usr/staff/&
user4  host2:/usr/staff/&
user5  host3:/usr/staff/&

A.1    Substitution and Pattern Matching

Both the automount and autofsmount commands recognize the following substitution characters, allowing you to eliminate redundancy within maps:

Because the ampersand and asterisk are most easily used in indirect maps, this section discusses them in the context of indirect maps only. Recall that lines in indirect maps have the following syntax:

key             mount-options           location

Whenever the automount or autofsmount commands encounter an ampersand (&) in a line of an indirect map, they substitute the key in that line for the ampersand (&).

The following example is an indirect map that does not use ampersands:

#key               mount-options      location
#
host1              -rw,nosuid        host1:/home/host1
host2              -rw,nosuid        host2:/home/host2

Using the ampersand (&) as a substitution character, the entries read as follows:

#key               mount-options     location
#
host1              -rw,nosuid        &:/home/&
host2              -rw,nosuid        &:/home/&

You can use the asterisk (*) to substitute for lines that are all formatted similarly. Both daemons use the asterisk to match any host not listed as a key in an entry before the asterisk. The following example shows how the asterisk (*) is typically used:

#key            mount-options           location
#
host1              -rw,nosuid        &:/home/&
host2              -rw,nosuid        &:/home/&
*                  -rw,nosuid        &:/home/&

Suppose a user enters the following command:

% ls /home/host5

Either daemon recognizes the host name, host5, as the key and substitutes host5 for each of the ampersands in the location field. The map is interpreted as follows for host5:

#key            mount-options           location
#
host5               -rw,nosuid              host5:/home/host5

Note

The automount and autofsmount commands ignore any entry that follows an asterisk.

A.2    Environment Variables

You can use the value of an environment variable in a map by adding a dollar sign ($) prefix to its name. You also can use braces ({ }) to delimit the name of the variable from appended letters or digits.

Environment variables can be inherited from the environment or can be defined explicitly with the -D option on the command line. For example, you can invoke the automount daemon with the HOST variable by entering the following command:

# automount -D HOST=hostname

To define the same variable for the autofsd daemon, enter the following command:

# autofsd -D HOST=hostname

The following is an example of a direct map entry that uses the environment variable HOST to define subnetworks:

/mydir     -rw      server:/export/$HOST

A.3    Mounting File Systems

Automount and AutoFS provide several ways to mount remote directories and file systems:

A.3.1    Multiple Mounts

When you write direct and indirect maps, you can specify that different directories within a file system hierarchy be mounted from different servers. For example, if you mount the /usr/local file system on your machine, you can mount the various subdirectories within /usr/local from different servers.

The following example shows an entry in a direct map in which the directories /usr/local/bin, /usr/local/src, and /usr/local/tools are mounted from the machines host1, host2, and host3, respectively:

/usr/local\
                /bin    -ro        host1:/usr/local/bin \
                /src    -ro        host2:/usr/local/src \
                /tools  -ro        host3:/usr/local/tools

This is a direct map because the key, /usr/local, is an absolute pathname. If this were an entry in an indirect map, the key would be a simple pathname, such as local. The key, /usr/local, comprises three subdirectories, each of which is a mount point for a remote directory on a different remote server. The example shows the entry split into four lines with the continuation lines indented for readability.

The preceding example shows multiple, nonhierarchical mounts under /usr/local. The following example shows a true hierarchical entry:

/usr/local \
             /            -ro        host0:/usr/local \
             /bin         -ro        host1:/usr/local/bin \
             /src         -ro        host2:/usr/local/src \
             /tools       -ro        host3:/usr/local/tools

The mount points used here for the hierarchy are /, /bin, /src, and /tools. Note that these mount points are relative to /usr/local. The mount point / mounts /usr/local from host0.

When file systems are mounted hierarchically, the entire hierarchy is treated as one object. Each file system is mounted on a subdirectory within another file system, and when a subdirectory within the hierarchy is referenced, the daemon mounts the entire hierarchy. The entire hierarchy is also unmounted as one object. The only exception is specific to AutoFS.

Like the automount daemon, the autofsd daemon creates symbolic links for file systems that are served locally. But if the autofsd daemon encounters an entry in a list of hierarchical file systems that is served locally and would result in a circular symbolic link on the local system (for example, a link from the /usr/local/bin directory back to itself), the group semantic is lost. AutoFS will mount and unmount the file systems on an individual basis.

This happens because AutoFS is designed to mount a remote file system on (or create a symbolic link to) the designated mount point itself. It does not, as Automount does, create an additional symbolic link back to a special /tmp_mnt directory from which the remote file system is actually served.

A.3.2    Shared Mounts

When multiple directories within the same remote directory are mounted, the location field can be specified as follows:

host:path:subdir

Note

AutoFS does not support this syntax. If the autofsmount command encounters this syntax, it converts the final colon (:) to a slash (/) and treats the entry as a typical AutoFS mount.

The host field is the remote host from which to mount the file system. The path field is the pathname of the directory to mount, and the subdir field, if specified, is the name of the subdirectory to which the symbolic link is made. This prevents duplicate mounts of the same remote file system when multiple subdirectories within it are accessed.

Suppose an indirect map called /auto.myindirect is specified in a master file as follows:

/mydir          /auto.myindirect
 

And the /auto.myindirect map consists of the following entries:

mybin           host1:/usr/staff/diane:bin
mystuff         host1:/usr/staff/diane:stuff

When a user accesses a file in /mydir/mybin, the automount daemon mounts host1:/usr/staff/diane, but creates a symbolic link called /mydir/mybin to the bin subdirectory in the temporarily mounted file system. If a user immediately tries to access a file in /mydir/mystuff, the automount daemon needs only to create a symbolic link that points to the stuff subdirectory because the /usr/staff/diane directory is already mounted. With the following map, the daemon would perform two separate mount operations:

mybin           host1:/usr/staff/diane/bin
mystuff         host1:/usr/staff/diane/stuff

A.3.3    Replicated File Systems

You can specify multiple locations for a single mount. If a file system is located on several servers and one of the servers is disabled, the file system can be mounted from one of the other servers. This makes sense only when mounting a read-only file system.

In the following example, the reference pages can be mounted from host1, machine2, or system3:

/usr/man\
                -ro,soft        host1:/usr/man \
                                machine2:/usr/man \
                                system3:/usr/man

The preceding example can also be expressed as a list of servers, separated by commas and followed by a colon and the pathname, for example:

/usr/man  -ro,soft  host1,machine2,system3:/usr/man

This syntax is valid only if the pathname is the same on each server.

When you access the reference pages, the automount daemon issues a ping request (NFS v2 loop request) to each of the specified servers concurrently and selects the first server that responds to serve the file system.

In contrast, the autofsd daemon first classifies each of the specified servers based on the proximity of its network address to the current system (Local, Same Subnet, Same Network, or Other Network). The daemon then attempts to serve the file system from the closest resource, starting with Local addresses.

If the file system can be served locally, the daemon uses a symbolic link to access it. If the file system cannot be served locally, the daemon resorts to trying all Same Subnet, Same Network, and Other Network addresses, in that order. Except when checking Local addresses, the system issues a ping request to each server concurrently and selects the first server that responds to serve the file system.