Questo contenuto non è disponibile nella lingua selezionata.
Chapter 32. Mounting file systems on demand
As a system administrator, you can configure file systems, such as NFS, to mount automatically on demand.
32.1. The autofs service
					The autofs service can mount and unmount file systems automatically (on-demand), therefore saving system resources. It can be used to mount file systems such as NFS, AFS, SMBFS, CIFS, and local file systems.
				
					One drawback of permanent mounting using the /etc/fstab configuration is that, regardless of how infrequently a user accesses the mounted file system, the system must dedicate resources to keep the mounted file system in place. This might affect system performance when, for example, the system is maintaining NFS mounts to many systems at one time.
				
					An alternative to /etc/fstab is to use the kernel-based autofs service. It consists of the following components:
				
- A kernel module that implements a file system, and
- A user-space service that performs all of the other functions.
32.2. The autofs configuration files
					This section describes the usage and syntax of configuration files used by the autofs service.
				
The master map file
						The autofs service uses /etc/auto.master (master map) as its default primary configuration file. This can be changed to use another supported network source and name using the autofs configuration in the /etc/autofs.conf configuration file in conjunction with the Name Service Switch (NSS) mechanism.
					
All on-demand mount points must be configured in the master map. Mount point, host name, exported directory, and options can all be specified in a set of files (or other supported network sources) rather than configuring them manually for each host.
					The master map file lists mount points controlled by autofs, and their corresponding configuration files or network sources known as automount maps. The format of the master map is as follows:
				
mount-point map-name options
mount-point  map-name  optionsThe variables used in this format are:
- mount-point
- 
								The autofsmount point; for example,/mnt/data.
- map-file
- The map source file, which contains a list of mount points and the file system location from which those mount points should be mounted.
- options
- If supplied, these apply to all entries in the given map, if they do not themselves have options specified.
Example 32.1. The /etc/auto.master file
						The following is a sample line from /etc/auto.master file:
					
/mnt/data /etc/auto.data
/mnt/data  /etc/auto.dataMap files
Map files configure the properties of individual on-demand mount points.
The automounter creates the directories if they do not exist. If the directories exist before the automounter was started, the automounter will not remove them when it exits. If a timeout is specified, the directory is automatically unmounted if the directory is not accessed for the timeout period.
The general format of maps is similar to the master map. However, the options field appears between the mount point and the location instead of at the end of the entry as in the master map:
mount-point options location
mount-point  options  locationThe variables used in this format are:
- mount-point
- 
								This refers to the autofsmount point. This can be a single directory name for an indirect mount or the full path of the mount point for direct mounts. Each direct and indirect map entry key (mount-point) can be followed by a space separated list of offset directories (subdirectory names each beginning with/) making them what is known as a multi-mount entry.
- options
- 
								When supplied, these options are appended to the master map entry options, if any, or used instead of the master map options if the configuration entry append_optionsis set tono.
- location
- 
								This refers to the file system location such as a local file system path (preceded with the Sun map format escape character :for map names beginning with/), an NFS file system or other valid file system location.
Example 32.2. A map file
						The following is a sample from a map file; for example, /etc/auto.misc:
					
payroll -fstype=nfs4 personnel:/exports/payroll sales -fstype=xfs :/dev/hda4
payroll  -fstype=nfs4  personnel:/exports/payroll
sales    -fstype=xfs   :/dev/hda4
						The first column in the map file indicates the autofs mount point: sales and payroll from the server called personnel. The second column indicates the options for the autofs mount. The third column indicates the source of the mount.
					
						Following the given configuration, the autofs mount points will be /home/payroll and /home/sales. The -fstype= option is often omitted and is not needed if the file system is NFS, including mounts for NFSv4 if the system default is NFSv4 for NFS mounts.
					
						Using the given configuration, if a process requires access to an autofs unmounted directory such as /home/payroll/2006/July.sxc, the autofs service automatically mounts the directory.
					
The amd map format
						The autofs service recognizes map configuration in the amd format as well. This is useful if you want to reuse existing automounter configuration written for the am-utils service, which has been removed from Red Hat Enterprise Linux.
					
					However, Red Hat recommends using the simpler autofs format described in the previous sections.
				
32.3. Configuring autofs mount points
					Configure on-demand mount points by using the autofs service.
				
Prerequisites
- Install the - autofspackage:- yum install autofs - # yum install autofs- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Start and enable the - autofsservice:- systemctl enable --now autofs - # systemctl enable --now autofs- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Procedure
- 
							Create a map file for the on-demand mount point, located at /etc/auto.identifier. Replace identifier with a name that identifies the mount point.
- In the map file, enter the mount point, options, and location fields as described in The autofs configuration files section.
- Register the map file in the master map file, as described in The autofs configuration files section.
- Allow the service to re-read the configuration, so it can manage the newly configured - autofsmount:- systemctl reload autofs.service - # systemctl reload autofs.service- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Try accessing content in the on-demand directory: - ls automounted-directory - # ls automounted-directory- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
32.4. Automounting NFS server user home directories with autofs service
Configure the autofs service to mount user home directories automatically.
Prerequisites
- The autofs package is installed.
- The autofs service is enabled and running.
Procedure
- Specify the mount point and location of the map file by editing the - /etc/auto.masterfile on a server on which you need to mount user home directories. To do so, add the following line into the- /etc/auto.masterfile:- /home /etc/auto.home - /home /etc/auto.home- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Create a map file with the name of - /etc/auto.homeon a server on which you need to mount user home directories, and edit the file with the following parameters:- * -fstype=nfs,rw,sync host.example.com:/home/& - * -fstype=nfs,rw,sync host.example.com:/home/&- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow - You can skip - fstypeparameter, as it is- nfsby default. For more information, see- autofs(5)man page on your system.
- Reload the - autofsservice:- systemctl reload autofs - # systemctl reload autofs- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
32.5. Overriding or augmenting autofs site configuration files
It is sometimes useful to override site defaults for a specific mount point on a client system.
Example 32.3. Initial conditions
For example, consider the following conditions:
- Automounter maps are stored in NIS and the - /etc/nsswitch.conffile has the following directive:- automount: files nis - automount: files nis- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- The - auto.masterfile contains:- +auto.master - +auto.master- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- The NIS - auto.mastermap file contains:- /home auto.home - /home auto.home- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- The NIS - auto.homemap contains:- beth fileserver.example.com:/export/home/beth joe fileserver.example.com:/export/home/joe * fileserver.example.com:/export/home/& - beth fileserver.example.com:/export/home/beth joe fileserver.example.com:/export/home/joe * fileserver.example.com:/export/home/&- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- The - autofsconfiguration option- BROWSE_MODEis set to- yes:- BROWSE_MODE="yes" - BROWSE_MODE="yes"- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- 
								The file map /etc/auto.homedoes not exist.
Procedure
						This section describes the examples of mounting home directories from a different server and augmenting auto.home with only selected entries.
					
Example 32.4. Mounting home directories from a different server
						Given the preceding conditions, let’s assume that the client system needs to override the NIS map auto.home and mount home directories from a different server.
					
- In this case, the client needs to use the following - /etc/auto.mastermap:- /home /etc/auto.home +auto.master - /home /etc/auto.home +auto.master- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- The - /etc/auto.homemap contains the entry:- * host.example.com:/export/home/& - * host.example.com:/export/home/&- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
						Because the automounter only processes the first occurrence of a mount point, the /home directory contains the content of /etc/auto.home instead of the NIS auto.home map.
					
Example 32.5. Augmenting auto.home with only selected entries
						Alternatively, to augment the site-wide auto.home map with just a few entries:
					
- Create an - /etc/auto.homefile map, and in it put the new entries. At the end, include the NIS- auto.homemap. Then the- /etc/auto.homefile map looks similar to:- mydir someserver:/export/mydir +auto.home - mydir someserver:/export/mydir +auto.home- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- With these NIS - auto.homemap conditions, listing the content of the- /homedirectory outputs:- ls /home - $ ls /home beth joe mydir- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
						This last example works as expected because autofs does not include the contents of a file map of the same name as the one it is reading. As such, autofs moves on to the next map source in the nsswitch configuration.
					
32.6. Using LDAP to store automounter maps
					Configure autofs to store automounter maps in LDAP configuration rather than in autofs map files.
				
Prerequisites
- 
							LDAP client libraries must be installed on all systems configured to retrieve automounter maps from LDAP. On Red Hat Enterprise Linux, the openldappackage should be installed automatically as a dependency of theautofspackage.
Procedure
- 
							To configure LDAP access, modify the /etc/openldap/ldap.conffile. Ensure that theBASE,URI, andschemaoptions are set appropriately for your site.
- The most recently established schema for storing automount maps in LDAP is described by the - rfc2307bisdraft. To use this schema, set it in the- /etc/autofs.confconfiguration file by removing the comment characters from the schema definition. For example:- Example 32.6. Setting autofs configuration - DEFAULT_MAP_OBJECT_CLASS="automountMap" DEFAULT_ENTRY_OBJECT_CLASS="automount" DEFAULT_MAP_ATTRIBUTE="automountMapName" DEFAULT_ENTRY_ATTRIBUTE="automountKey" DEFAULT_VALUE_ATTRIBUTE="automountInformation" - DEFAULT_MAP_OBJECT_CLASS="automountMap" DEFAULT_ENTRY_OBJECT_CLASS="automount" DEFAULT_MAP_ATTRIBUTE="automountMapName" DEFAULT_ENTRY_ATTRIBUTE="automountKey" DEFAULT_VALUE_ATTRIBUTE="automountInformation"- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Ensure that all other schema entries are commented in the configuration. The - automountKeyattribute of the- rfc2307bisschema replaces the- cnattribute of the- rfc2307schema. Following is an example of an LDAP Data Interchange Format (LDIF) configuration:- Example 32.7. LDIF Configuration - Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
32.7. Using systemd.automount to mount a file system on demand with /etc/fstab
					Mount a file system on demand using the automount systemd units when mount point is defined in /etc/fstab. You have to add an automount unit for each mount and enable it.
				
Procedure
- Add desired fstab entry as documented in Persistently mounting file systems. For example: - /dev/disk/by-id/da875760-edb9-4b82-99dc-5f4b1ff2e5f4 /mount/point xfs defaults 0 0 - /dev/disk/by-id/da875760-edb9-4b82-99dc-5f4b1ff2e5f4 /mount/point xfs defaults 0 0- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- 
							Add x-systemd.automountto the options field of entry created in the previous step.
- Load newly created units so that your system registers the new configuration: - systemctl daemon-reload - # systemctl daemon-reload- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Start the automount unit: - systemctl start mount-point.automount - # systemctl start mount-point.automount- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- Check that - mount-point.automountis running:- systemctl status mount-point.automount - # systemctl status mount-point.automount- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Check that automounted directory has desired content: - ls /mount/point - # ls /mount/point- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
32.8. Using systemd.automount to mount a file system on-demand with a mount unit
Mount a file system on-demand using the automount systemd units when mount point is defined by a mount unit. You have to add an automount unit for each mount and enable it.
Procedure
- Create a mount unit. For example: - mount-point.mount [Mount] What=/dev/disk/by-uuid/f5755511-a714-44c1-a123-cfde0e4ac688 Where=/mount/point Type=xfs - mount-point.mount [Mount] What=/dev/disk/by-uuid/f5755511-a714-44c1-a123-cfde0e4ac688 Where=/mount/point Type=xfs- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- 
							Create a unit file with the same name as the mount unit, but with extension .automount.
- Open the file and create an - [Automount]section. Set the- Where=option to the mount path:- [Automount] Where=/mount/point [Install] WantedBy=multi-user.target - [Automount] Where=/mount/point [Install] WantedBy=multi-user.target- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Load newly created units so that your system registers the new configuration: - systemctl daemon-reload - # systemctl daemon-reload- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Enable and start the automount unit instead: - systemctl enable --now mount-point.automount - # systemctl enable --now mount-point.automount- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
Verification
- Check that - mount-point.automountis running:- systemctl status mount-point.automount - # systemctl status mount-point.automount- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow 
- Check that automounted directory has desired content: - ls /mount/point - # ls /mount/point- Copy to Clipboard Copied! - Toggle word wrap Toggle overflow