jacky.lee 发表于 2008-01-19 15:21

Using Automount Maps


Using Automount Maps
The
file system
resources for automatic mounting are defined in automount maps. The image shows maps defined in the /etc directory.
http://blogimg.chinaunix.net/blog/upfile2/080119151950.gif
The AutoFS map types are:

Master map - Lists the other maps used for establishing the AutoFS file system. The automount command reads this map at boot time.
Direct map - Lists the mount points as absolute path names. This map explicitly indicates the mount point on the client.
Indirect map - Lists the mount points as relative path names. This map uses a relative path to establish the mount point on the client.
Special - Provides access to NFS
servers
by using their host names.
The automount maps can be obtained from ASCII data files, NIS maps, NIS+ tables, or from an LDAP database. Together, these maps describe information similar to the information specified in the /etc/vfstab file for remote file resources.
The source for automount maps is determined by the automount entry in the /etc/nsswitch.conf file. For example, the entry:automount: files
tells the automount command that it should look in the /etc directory for its configuration information. Using nis instead of files tells automount to check the NIS maps for its configuration information.
The auto_master map associates a directory, also called a mount point, with a map. The auto_master map is a master list specifying all the maps that the AutoFS service should check. Names of direct and indirect maps listed in this map refer to files in the /etc directory or to name service databases.
Associating a Mount Point With a Map
The following example shows an /etc/auto_master file.# cat /etc/auto_master
# Master map for automounter
#
+auto_master
/net        -hosts        -nosuid,nobrowse
/home        auto_home        -nobrowse
The general syntax for each entry in the auto_master map is:mount point                map name                mount options
where:
Fields in the auto_master Map
Field
Description
mount point
The full path name of a directory. If the directory does not exist, the AutoFS service creates one, if possible.
map name
The name of a direct or indirect map. These maps provide mounting information. A relative path name in this field requires AutoFS to consult the /etc/nsswitch.conf file for the location of the map.
mount options
The general options for the map. The mount options are similar to those used for standard NFS mounts. However, the nobrowse option is an AutoFS-specific mount option.
Note: The plus (+) symbol at the beginning of the +auto_master line in this file directs the automountd daemon to look at the NIS, NIS+, or LDAP databases before it reads the rest of the map. If this line is commented out, only the
local files
are searched unless the /etc/nsswitch.conf file specifies that NIS, NIS+, or LDAP should be searched.
There are two mount point entries listed in the default /etc/auto_master file.# cat /etc/auto_master
#
# Copyright 2003 Sun Microsystems, Inc.All rights reserved.
# Use is subject to license terms.
#
# ident “@(#)auto_master      1.8   03/04/28 SMI”
#
# Master map for automounter
#
+auto_master
/net            -hosts          -nosuid,nobrowse
/home         auto_home       -nobrowse
The two mount points for special maps are:
Mount Points for Special Maps
Mount Point
Description
The -hosts map
Provides access to all resources shared by NFS servers. The resources being shared by a server are mounted below the /net/hostname directory, or, if only the server’s
IP address
is known, below the /net/IPaddress directory. The server does not have to be listed in the hosts
database
for this mechanism to work.
The auto_home map
This map provides the mechanism to allow users to access their centrally located $HOME directories.
Using the /net Directory
Shared resources associated with the hosts map entry are mounted below the /net/hostname directory. For example, a shared resource named /documentation on host sys42 is mounted by the command:# cd /net/sys42/documentation
Using the cd command to trigger the automounting of sys42’s resource eliminates the need to log in to the system. Any user can mount the resource by executing the command to change to the directory that contains the shared resource. The resource remains mounted until a predetermined time period of inactivity has occurred.
The -nobrowse option prevents all the potential mount points from being visible. Only those resources that are actually mounted are visible.
The /- entry in the example master map defines a mount point for direct maps.# cat /etc/auto_master
# Master map for automounter
#
+auto_master
/net        -hosts        -nosuid,nobrowse
/home        auto_home        -nobrowse
/-        auto_direct        -ro
The /- mount point is a pointer that informs the automount facility that the full path names are defined in the file specified by map_name (the /etc/auto_direct file in this example).
Note: The /- entry is not an entry in the default master map. This entry has been added here as an example. The other entries in this example already exist in the auto_master file.
Even though the map_name entry is specified as auto_direct, the automount facility automatically searches for all map-related files in the /etc directory; therefore, based upon the automount entry in the /etc/nsswitch.conf file, the auto_direct file is the /etc/auto_direct file. If the auto_direct file is to be stored in another directory, the absolute path name to the file should be used.
Note: An NIS or NIS+ master map can have only one direct map entry. A master map that is a local file can have any number of entries.
Creating a Direct Map
Direct maps specify the absolute path name of the mount point, the specific options for this mount, and the shared resource to mount. For example:# cat /etc/auto_direct
# Superuser-created direct map for automounter
#
/apps/frame        -ro,soft        server1:/export/framemaker,v6.0
/opt/local        -ro,soft        server2:/export/unbundled
/usr/share/man        -ro,soft        server3,server4,server5:/usr/share/man
The syntax for direct maps is:key [ mount-options] location
where:
Direct Map Syntax
Syntax Field
Description
key
The full path name of the mount point for the direct maps.
mount-options
The specific options for a given entry.
location
The location of the file resource specified in server:pathname notation.
The following direct map entry specifies that the client mounts the /usr/share/man directory as read-only from the servers server3, server4, or server5, as available./usr/share/man       -ro       server3,server4,server5:/usr/share/man
This entry uses a special notation, a comma-separated list of servers, to specify a powerful automount feature–multiple locations for a file resource. The automountd daemon automatically mounts the /usr/share/man directory as needed, from servers server3, server4, or server5, with server proximity and administrator-defined weights determining server selection. If the nearest server fails to respond within the specified timeout period, the next server which responds first is selected.
Note: Selection criteria for
multiple servers
, such as server proximity and administrator-defined weights, is defined in the “Replicated File Systems” section of the automount man page.
The /home entry defines a mount point for an indirect map. The map auto_home lists relative path names only. Indirect maps obtain the initial path of the mount point from the master map.# cat /etc/auto_master
# Master map for automounter
#
+auto_master
/net        -hosts        -nosuid,nobrowse
/home        auto_home        -nobrowse
The
Solaris
2.6 through the Solaris 10 OS releases support browsing of indirect maps and special maps with the -browse option. This support allows all of the potential mount points to be visible, regardless of whether they are mounted. The -nobrowse option disables the browsing of indirect maps. Therefore, in this example, the /home automount point does not provide browser functions for any directory other than those that are currently mounted. The default for this option is -browse.
Creating an Indirect Map
Use the auto_home indirect map to list the location of home directories across the
network
. For example,# cat /etc/auto_home
# Home directory map for automounter
#
+auto_home
stevenu        host5:/export/home/stevenu
johnnyd        host6:/export/home/johnnyd
wkd        server1:/export/home/wkd
mary        mars:/export/home/mary
The example /etc/auto_home file implies the following mount points: /home/stevenu, /home/johnnyd, /home/wkd, and /home/mary. The image shows the /home/mary mount point.
The following describes the syntax for indirect maps:key[ mount-options ]    location
where:
Indirect Map Syntax
Syntax Field
Description
key
Specifies the path name of the mount point relative to the beginning of the path name specified in the master map.
mount-options
Specifies the options for a given entry.
location
Specifies the location of the file resource specified in server:pathname notation.
http://blogimg.chinaunix.net/blog/upfile2/080119152039.gif
Reducing the auto_home Map to a Single Line
The following entry reduces the auto_home file to a single line. The use of substitution characters specifies that for every login ID, the client remotely mounts the /export/home/loginID directory from the NFS server server1 onto the local mount point /home/loginID, as shown in the image.
The image shows that this entry uses the wildcard character (*) to match any key. The wildcard character cannot be used in combination with any other character. The substitution character (&) at the end of the location is replaced with the matched key field. Using wildcard and substitution characters works only when all home directories are on a single server (in this example, server1).
http://learning-solaris.com/content-img/autofs-autohome-map.gif
When making changes to the master map or creating a direct map, run the automount command to make the changes effective.
Running the automount Command
The syntax of the command is:automount [-t duration] [-v]
where:
The automount Command Syntax
Syntax Field
Description
-t duration
Specifies a time, in seconds, that the file
system
remains mounted when not in use. The default is 600 seconds (10 minutes).
-v
Specifies verbose mode, which displays output as the automount command executes.
You can modify the master map entries or add entries for new maps. However, you must run the automount command to make these changes effective.
You do not have to stop and restart the automountd daemon after making changes to existing entries in a direct map, because the daemon is stateless. You can modify existing entries in the direct map at any time. The new information is used when the automountd daemon next accesses the map entry to perform a mount.
Any modifications to indirect maps are automatically used by the automountd daemon.
A modification is a change to options or resources. A change to the key (the mount point) or a completely new line is an added entry, a deleted entry, or both.
Use the table to determine whether you should run (or rerun) the automount command.
When to Run the automount Command
Automount Map
Run if the Entry is Added or Deleted
Run if the Entry is Modified
master map
Yes
Yes
Direct map
Yes
No
Indirect map
No
No
Verifying AutoFS Entries in the /etc/mnttab File
The /etc/mnttab file is a file system that provides read-only access to the table of mounted file systems for the current host. Mounting a file system adds an entry to this table. Unmounting a file system removes the entry from this table. Each entry in the table is a line of fields separated by spaces in the form of:special   mount_pointfstype   options   time   
where:
AutoFS Entries in the /etc/mnttab File
Field
Description
special
The name of the resource to be mounted
mount_point
The path name of the directory on which the file system is mounted
fstype
The type of file system
options
The mount options
time
The time at which the file system was mounted
The autofs service is enabled or disabled automatically as the system transitions between run levels, or you can enable or disable the service manually from the command line.
Stopping the Automount System
When the autofs service is disabled, it performs a forced unmount of all AutoFS file systems, and it then kills the automountd daemon.
The autofs service is disabled automatically when transitioning to the single-user milestone.
To disable the service, become superuser, and kill the automountd daemon by typing the following command:# svcadm disable svc:/system/filesystem/autofs
Starting the Automount System
When the autofs service is enabled, the service management facility starts the automountd daemon, and then it runs the automount utility as a background task.
The service starts automatically when transitioning to
multi-user
milestone.
To enable the service manually, become superuser, and start the automountd daemon by performing the command:# svcadm enable svc:/system/filesystem/autofs


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36549/showart_467877.html
页: [1]
查看完整版本: Using Automount Maps