RHCSA Rapid Track
Objectives
After completing this section, you 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 automatically mounts 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 and 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 on the client side; no server-side configuration is required.
The automounter uses the same options as the mount command, including security options.
The automounter supports both direct and indirect mount-point mapping, for flexibility in mount-point locations.
autofscreates and removes indirect mount points, eliminating manual management.NFS is the default automounter network file system, but other network file systems can be automatically mounted.
autofsis a service that is managed like other system services.
Create an automount
Configuring an automount is a multiple step process:
Install the autofs package.
[user@host ~]$sudo yum 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.[user@host ~]$sudo vim /etc/auto.master.d/demo.autofsThe name of the master map file is arbitrary (although typically meaningful), but it must have an extension of
.autofsfor the subsystem to recognize it. You can place multiple entries in a single master map file; alternatively, you can create multiple master map files each with its own entries grouped logically.Add the master map entry, in this case, for indirectly mapped mounts:
/shares /etc/auto.demo
This entry uses the
/sharesdirectory as the base for indirect automounts. The/etc/auto.demofile contains the mount details. Use an absolute file name. Theauto.demofile needs to be created before starting theautofsservice.Create the mapping files. Each mapping file identifies the mount point, mount options, and source location to mount for a set of automounts.
[user@host ~]$sudo vim /etc/auto.demoThe mapping file-naming convention is
/etc/auto., wherenamenamereflects the content of the map.work -rw,sync serverb:/shares/work
The format of an entry is mount point, mount options, and source location. This example shows a basic indirect mapping entry. Direct maps and indirect maps using wildcards are covered later in this section.
Known as the key in the man pages, the mount point is created and removed automatically by the
autofsservice. In this case, the fully qualified mount point is/shares/work(see the master map file). The/sharesdirectory and the/shares/workdirectories are created and removed as needed by theautofsservice.In this example, the local mount point mirrors the server's directory structure, however this is not required; the local mount point can be named anything. The
autofsservice does not enforce a specific naming structure on the client.Mount options start with a dash character (-) and are comma-separated with no white space. Mount options available to a manual mounting of a file system are available when automounting. In this example, the automounter mounts the share with read/write access (
rwoption), and the server is synchronized immediately during write operations (syncoption).Useful automounter-specific options include
-fstype=and-strict. Usefstypeto specify the file system type, for example,nfs4orxfs, and usestrictto treat errors when mounting file systems as fatal.The source location for NFS shares follows the
host:/pathnamepattern; in this example,serverb:/shares/work. For this automount to succeed, the NFS server,serverb, must export the directory with read/write access and the user requesting access must have standard Linux file permissions on the directory. Ifserverbexports the directory with read/only access, then the client will get read/only access even though it requested read/write access.
Start and enable the automounter service.
Use systemctl to start and enable the
autofsservice.[user@host ~]$sudo systemctl enable --now autofsCreated symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.
Direct Maps
Direct maps are used to map an NFS share to an existing absolute path mount point.
To use directly mapped mount points, the master map file might appear as follows:
/- /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.
The content for the /etc/auto.direct file might appear as follows:
/mnt/docs -rw,sync serverb:/shares/docs
The mount point (or key) is always an absolute path. The rest of the mapping file uses the same structure.
In this example the /mnt directory exists, and it is not managed by autofs.
The full directory /mnt/docs will be created and removed automatically by the autofs service.
Indirect Wildcard Maps
When an NFS server exports multiple subdirectories within a directory, then the automounter can be configured to access any one of those subdirectories using a single mapping entry.
Continuing the previous example, if serverb:/shares exports two or more subdirectories and they are accessible using the same mount options, then the content for the /etc/auto.demo file might appear as follows:
* -rw,sync serverb:/shares/&
The mount point (or key) is an asterisk character (*), and the subdirectory on the source location is an ampersand character (&). Everything else in the entry is the same.
When a user attempts to access /shares/work, the key * (which is work in this example) replaces the ampersand in the source location and serverb:/shares/work is mounted.
As with the indirect example, the work directory is created and removed automatically by autofs.
References
autofs(5), automount(8), auto.master(5), and mount.nfs(8) man pages