[Return to Library] [Contents] [Previous Chapter] [Next Section] [Next Chapter] [Index] [Help]


C    Writing automount Maps

There are three types of automount maps:

The automount maps can be written in a variety of ways. Maps can be direct or indirect. They can be simple or can use multiple mounts, shared mounts, replicated file systems, or any combination of the three. As discussed in Section C.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 C-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 organization and administration of automount.

Figure C-1: Sample automount Maps

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

Example C-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 C-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 C-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 might read:

/mnt     /etc/auto.indirect

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

Example C-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 C-5); multiple mounts and shared mounts (Example C-6); and multiple mounts, shared mounts, and replicated file systems (Example C-7).

Example C-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 C-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 C-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. 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 (BIND, 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 C-1 is an indirect map that allows users to remote 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 C-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/&


[Return to Library] [Contents] [Previous Chapter] [Next Section] [Next Chapter] [Index] [Help]


C.1    Substitution and Pattern Matching

The automount daemon recognizes the following substitution characters, allowing you to eliminate redundancy within automount 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 daemon encounters an ampersand (&) in a line of an indirect map, it substitutes 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. The automount daemon uses the asterisk to match any host not listed as a key in an entry before the asterisk. The following is a typical use of the asterisk (*):

#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

The automount daemon substitutes the host name (host5) as the key. After it has substituted host5 for the key, it then substitutes host5 for each of the ampersands in the location field as well. The automount daemon translates the preceding command into the following:

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

Note

The automount daemon ignores any entry that follows an asterisk.


[Return to Library] [Contents] [Previous Chapter] [Previous Section] [Next Section] [Next Chapter] [Index] [Help]


C.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

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

/mydir     -rw      server:/export/$HOST


[Return to Library] [Contents] [Previous Chapter] [Previous Section] [Next Section] [Next Chapter] [Index] [Help]


C.3    Mounting File Systems

The automount daemon provides several ways to mount remote directories and file systems:


[Return to Library] [Contents] [Previous Chapter] [Previous Section] [Next Section] [Next Chapter] [Index] [Help]


C.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 automount daemon mounts the entire hierarchy. The entire hierarchy is also unmounted as one object.


[Return to Library] [Contents] [Previous Chapter] [Previous Section] [Next Section] [Next Chapter] [Index] [Help]


C.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

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 has the following entries:

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

When a user accesses a file in /auto.myindirect/mybin, the automount daemon mounts host1:/usr/staff/diane, but creates a symbolic link called /auto.myindirect/mybin to the .L bin) subdirectory in the temporarily mounted file system. If a user immediately tries to access a file in /auto.myindirect/mystuff, the automount daemon needs only to create a symbolic link that points to the mystuff subdirectory because the /usr/staff/diane directory is already mounted. With the following map, the automount daemon must mount the file system twice:

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


[Return to Library] [Contents] [Previous Chapter] [Previous Section] [Next Chapter] [Index] [Help]


C.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 command to each of the specified servers. The server that first responds to the ping command is used for the mount.