RHCSA Rapid Track
Install the necessary package:
autofs.Create a master map file in
/etc/auto.master.d/.file.autofsCreate a map file for accessing the NFS share:
/etc/auto..nameDirect maps.
Indirect maps.
Indirect maps using wildcards.
Start and enable the
autofsservice using systemctl.
Objectives
After completing this section, students should be able to:
Describe the benefits of using the automounter.
Automount NFS shares using direct and indirect maps, including wildcards.
Mounting NFS shares with the automounter
The automounter is a service (autofs) that can automatically mount NFS shares "on demand," and will automatically unmount NFS shares when they are no longer being used.
Automounter benefits
Users do not need to have root privileges to run the mount/umount commands.
NFS shares configured in the automounter are available to all users on the machine, subject to access permissions.
NFS shares are not permanently connected like entries in
/etc/fstab, freeing network and system resources.The automounter is configured entirely on the client side; no server-side configuration required.
The automounter uses the same mount options used by the mount command, including security options.
Support for both direct and indirect mount point mapping, providing flexibility in mount point locations.
Indirect mount points are created and removed by autofs, alleviating the need to manually manage them.
NFS is the default file system for the automounter, but it can be used to automount a range of different file systems.
autofs is a service that is managed like other system services.
Create an automount
Configuring an automount is a multistep process:
Install the
autofspackage.[student@desktopX ~]$sudo yum -y install autofsThis package contains everything needed to use the automounter for NFS shares.
Add a master-map file to
/etc/auto.master.d—this file identifies the base directory used for mount points and identifies the mapping file used for creating the automounts.Use vim to create and edit the master-map file:
[student@desktopX ~]$sudo vim /etc/auto.master.d/demo.autofsThe name of the master-map file is not important, but it is normally something meaningful. The only requirement is it must have an extension of
.autofs. The master-map file can hold multiple mapping entries, or use multiple files to separate configuration data.Add the master-map entry, in this case, for indirectly mapped mounts:
/shares /etc/auto.demo
This entry would use the
/sharesdirectory as the base of future indirect automounts. The/etc/auto.demofile contains the mount details; use an absolute filename. Theauto.demofile needs to be created before starting theautofsservice.To use directly mapped mount points, add an entry to the same file (or in a separate file):
/- /etc/auto.direct
All direct map entries use "
/-" as the base directory. In this case, the mapping file that contains the mount details is/etc/auto.direct.Create the mapping file(s). The mapping file identifies the mount point, mount options, and source location to mount.
Use vim to create and edit the mapping file:
[student@desktopX ~]$sudo vim /etc/auto.demoThe file name is not important, but by convention is located in
/etcand calledauto., wherenamenameis something meaningful to the included contents.work -rw,sync serverX:/shares/work
The format of an entry is mount point, mount options, and source location. This example is showing a basic indirect mapping entry. Direct maps and indirect maps using wildcards will be covered later in this section.
Known as the "key" in the man pages, the mount point will be created and removed automatically by the
autofsservice. In this case, the fully qualified mount point will be/shares/work—see the master-map file. The/sharesdirectory and theworkdirectory will be created and removed as needed by theautofsservice.In this example, the local mount point mirrors the server's directory structure. The local mount point can be named anything. There is no requirement to align the names of the local mount point and the server directory structure.
Mount options start with a "
-" (dash) and are comma-separated with no white space. The mount options available are the same as those available to the equivalent manual mount command. In this example, the automounter will try and mount the share using read/write access, security will be based on standard Linux file permissions (the default: sec=sys), and the server will be synchronized immediately during write operations.There are a couple of useful automounter specific options:
-fstype=and-strict. Usefstypeto specify the file system if it is not NFS and usestrictto treat errors, when mounting file systems, as fatal.The source location for NFS shares follows the
host:/pathnamepattern; in this example,serverX:/shares/work. This directory will need to have been exported on serverX with support for read/write access and standard Linux file permissions for the mount to be successful.If the file system to be mounted begins with a "
/" (slash), such as local device entries or SMB shares, then a ":" (colon) needs to be prefixed; for example, an SMB share would be://serverX/share.
Start and enable the automount service.
Use systemctl to both start and enable the
autofsservice.[student@desktopX ~]$sudo systemctl enable autofsln -s '/usr/lib/systemd/system/autofs.service' ...[student@desktopX ~]$sudo systemctl start autofs
The mapping file—direct maps
As the name implies, direct maps are used to map an NFS share to an existing mount point.
The automounter will not attempt to create the mount point automatically; it must exist prior
to the autofs service being started.
Continuing from the previous example, the content for the /etc/auto.direct
file might look like this:
/mnt/docs -rw,sync serverX:/shares/docs
The mount point (or key) is always an absolute path, starting with "/" (slash).
The rest of the mapping file uses the same structure.
Only the right-most directory is put under automounter control. Thus, the directory structure
above the mount point (/mnt in this example) is not obscured by
autofs.
The mapping file—indirect wildcard maps
When an NFS server is exporting multiple subdirectories within a directory, then the automounter can be configured to access any one of those subdirectories using a single mapping entry. As an example, this can be really useful for automounting user home directories from an NFS server.
Continuing the previous example, if serverX:/shares is exporting two or more
subdirectories and they are able to be accessed using the same mount options, then the content
for the /etc/auto.demo file might look like this:
* -rw,sync serverX:/shares/&
The mount point (or key) is an "*" (asterisk), and the subdirectory on the
source location is an "&" (ampersand). Everything else in the entry is the
same.
When a user attempts to access /shares/work, the key *
(which is work in this example) will replace the ampersand in the source
location and serverX:/shares/work will be mounted. As with the indirect example,
the work directory will be created and removed automatically by the
autofs service.
References
autofs(5), automount(8), auto.master(5), and mount.nfs(8) man pages