Nfs Mount Autofs
adminApril 29 2021
Nfs Mount Autofs
In this lesson, you will Learn What NFS is and the step by step process of how to configure NFS in Linux, RHEL/CentOS 7 & 8.
Contents
- Autofs should be as performant as fstab based mounting but has the advantage that your shares are mounted on demand which also should give you more reliability in case of network interuptions. First install the autofs package sudo apt-get install autofs.
- This is incorrect, the autofs service mounts shares as needed and unmount them after a period of inactivity, so it will not hold on to the mount and retry forever. – 0xSheepdog Jan 10 '18 at 6:21 The soft option you are talking about is only available for nfs mounts.
- If you want to mount it automatically on boot then you don't need autofs - you can simply add it to your /etc/fstab (although it may need some adjustment of options to prevent boot hangs in the case that the NAS is unavailable) - autofs is really for mounting on demand – steeldriver Feb 17 '17 at 15:12.
- The file /etc/auto.master is the main configuration file for 'autofs' service, this file contains the master map lists of the mount points on the system controlled by 'autofs', and their corresponding configuration files or network sources which are known as 'automount maps'.
NFS, which is an acronym for (Network File system) is a distributed file system protocol.
NFS is server-client based, where the NFS server will be configured and clients can access files on the server over a network just as if they were on the server.
NFS is one of the file system standards for Network-attached storage (NAS), hence can be used as a storage solution. Clients can access and update NFS shared files depending on the permission given on the files
AutoFS: AutoFS is a file system mechanism that provides automatic mounting the NFS protocol. It is a client side service. AutoFS service mounts and unmounts file systems as required without any user intervention.
In this tutorial, we will configure NFS with two systems, one will be the NFS server while the second will be the NFS client.
System A (NFS Server)
Hostname: DRDEV1
IP address: 192.168.170.172
System B (NFS client)
Hostname: HQDEV1
IP address: 192.168.170.171
How To Setup NFS Server In Linux – RHEL/CentOS 7&8
1. Install NFS utility
if the utility is not already installed on your system, install by using the command below
NFS should be used on a trusted network
2. Verify the status of rpcbind, if it is not running, start the service
3. start nfs-server service
For RHEL 8/CentOS 8, use the command below
For RHEL 7/CentOS 7, use the command below
4. Create NFS shared directory.
In this case, our nfs shared directory is “softwaredownload”. You can choose to use an existing directory depending on the directory you want to share.
5. Edit the “/etc/export” configuration file and add the client’s IP in the file.
5. restart the rpcbind service and nfs-server
6. Allow NFS services in the firewall rule
OR
Now we are done with NFS server configuration.
Let’s configure NFS client
How To Setup NFS Client In Linux – RHEL 7/CentOS 7&8
1. Install NFS utilities if it is not installed
2. Verify the rpcbind status and start the service if it is not started
3. verify that the NFS shared directory from the server is available on the client.
showmount -e <host-name> can be used if DNS resolution is working in your environment
If the IP is included on the server, you will see the client’s IP address from the showmount result in the export list. it’s possible other IPs from other clients too would show but the newly added IP will be the first IP to show.
NB: If the IP doesn’t show, restart the nfs-server and rpcbind service on both the client and the server. Also make sure that the client and server can ping each other.
If the IP doesn’t still show after the restart and you have the error “clnt_create: RPC: Unable to recieve”, no worries, you can do a mount test from the client to the server by using the command below
NB: The root filesystem on the NFS server will not be mounted but only the files/directories that are shared.
4. Now that we can see the NFS shared directory on the client, create a mount point for NFS
5. mount the NFS shared directory
6. Verify the NFS shared mount point
OR
7. To make the mount point persistent across reboot, Edit the fstab file
8. verify the shared directory is properly mounted
How To Use Autofs To Mount NFS Shares In Linux – (autofs In Linux)
NFS shares can also be made persistent or mounted on the client by using automount (autofs services) which offers a better performance compared to using the fstab file.
Before we see the step by step guide of how to do this, let’s understand how automount works with NFS in Linux.
How automount/autofs Works In Linux
NFS shares can automatically be mounted on the client whenever it is required (on demand) and be unmounted whenever it is inactive or no longer required with the use of the autofs service, hence offering better performance;
one of which is reducing the booting time of the system because the system won’t find the NFS entries in the fstab file while booting. More so, if the NFS server is down, it won’t affect the system from booting/entering a maintenance mode.
The autofs service needs to be installed, and then configured on the system by using a master map file, and in turn, the master map file will reference a map file.
The master map file can be defined in one of the autofs configuration files (/etc/auto.master).
However, it is recommended most times that the master map file is defined as a drop-in file in (/etc/auto.master.d) because the files in the main configuration file (/etc/auto.master) sometimes may be overwritten if an update is done on the system.
The drop-in file must have an extension of (.autofs) and the same format/syntax that is going to be used in the configuration file of (/etc/auto.master) will also be used in the drop-in file entry.
Let’ see a format of a master map file entry in (/etc/auto.master) configuration file.
Automount maps can be direct or indirect. Hence, In a master map file entry, you can configure a direct or an indirect map mount type.
For a direct map, the client path’s mount point specified in the map file will be absolute.
For an indirect map, the client path’s mount point specified in the map file will not be absolute. A parent directory will be specified in the master map file while a sub-directory will be specified in the map file the master map file is referencing.
We will see how to specify this syntax in the step by step guide.
Step By Step Guide On How To Automount NFS Share In Linux – RHEL/CentOS 7&8
configure automount on NFS client (HQDEV1) using an indirect map and “/software/site1” as the mount point for the client. The NFS share is /softwaredownload
Similarly, use a direct map and “/direct/software” as the mount point for the client. The NFS share is /softwaredownload.
1. Install autofs
2. verify if you can connect to the NFS server and see the export lists from the client
where 192.168.170.172 is the NFS server’s IP. The host name can also be used provided DNS resolution is working.
If you are having difficulties listing the exports list, you can test by mounting the shared directory on the client.
NB: only the shared directories will be mounted and not the entire root filesystem.
3. create a master map file
Note: (This step is for an Indirect mapping)
create a drop in file in (/etc/auto.master.d)
NB: the file must have “.autofs” extension
NB: This entry in master map file (/etc/auto.master.d) tells autofs to look in the map file entry (/etc/auto.tekneed) and create mount-points in the /software directory if there is an activity in the /software directory.
4. put in the entry for “/etc/auto.tekneed”
NB2: tekneed.autofs must correspond with auto.tekneed. Whatever name you used as the master map file/drop-in file must correspond with the name that will be used in the drop-in file entry.
The entries here will reference step 3
The format for the entry of this file is:
<mount point> <-mount options> <server-location>
which is similar to the fstab file format. This creates a new mount point at “/software/site1” and mounts the NFS share directory (/softwaredownload) exported by the server (192.168.170.172) with read and write permission & with immediate synchronization.
For an indirect mapping, a parent directory will be specified in the master map file while a sub-directory will be specified in the map file. autofs mounts the shares from the parent directory to the sub-directory.
Also note that the permission on the NFS share supersedes/takes precedence over the one specified with the mount option. Other mount options just as it can be used in the fstab can also be used here.
5. start and enable autofs
6. Test your configuration
(For a direct mapping)
From step 3, the master map file will be created as
This entry in master map file (/etc/auto.master.d) tells autofs to look in the map file entry (/etc/auto.tekneed) and create mount-points in the absolute path specified in the entry for /etc/auto.tekneed file. That’s what direct map do.
4. put in the entry for “/etc/auto.tekneed”
This creates a new mount point at /direct/software and mounts the NFS share directory (/softwaredownload) exported by the server (192.168.170.172) with read and write permission with immediate synchronization and with nfs version 4 filesystem type.
Other filesystem type can be specified as (-fstype=cifs, -fstype=xfs), etc.
5. start and enable autofs
NB: You may restart autofs if it is already started
6. Test your configuration.
Using Wildcards For automount
wildcards can be useful with automount. If you have a number of directories and you don’t want to specify them one by one in the map file, or you envisage that other sub-directories will be added to the NFS share, you can make do of wildcards.
Using wildcards with examples(indirect map)
from step 3, the master map file can be created as
4. put in the entry for “/etc/auto.tekneed”
This creates a new mount point starting form the /software directory and mounts the NFS share directory (/softwaredownload) exported by the server (192.168.170.172) with read and write permission with immediate synchronization and with nfs version 4 filesystem type.
currently, the NFS share has two sub-directories which are “/image_download” and “/iso_download”. The wildcards (* and &) will take care of the other sub-directoires that may be added to the NFS shares.
5. start and enable autofs
Ubuntu Autofs
NB: you may restart NFS if it already started.
6. Test your configuration.
Another scenario where wildcards can be useful is if we don’t want to specify the number of /home directories one by one in a reference file.
for example,
can be specified as
In conclusion, one of the benefits of automount is that other users that don’t have root privileges to execute the mount command can also access the shares when it is required because it is on-demand.
How To Unmount NFS Share
To unmount NFS share, use the “umount” command.
Nfs Mount Autofs Mod
For example, to unmount the “softwaredownload” NFS share that is not using autofs, use the command below.
Your feedback is welcomed. If you love others, you will share with others.
You need to configure autofs
manually by editing its configuration files with a text editor, such as vim
. There are two basic steps to configure autofs
—the master map file, and specific map files.
The default master configuration file for autofs
is /etc/auto.master
. You can change its location by changing the value of the DEFAULT_MASTER_MAP_NAME
option in /etc/sysconfig/autofs
. Here is the content of the default one for openSUSE Leap:
The |
Although commented out (#) by default, this is an example of a simple automounter mapping syntax. |
In case you need to split the master map into several files, uncomment the line, and put the mappings (suffixed with |
|
Entries in auto.master
have three fields with the following syntax:
Nfs Mount Fstab
The base location where to mount the autofs
file system, such as /home
.
The name of a map source to use for mounting. For the syntax of the maps files, see Section 23.2.2, “Map Files”.
These options (if specified) will apply as defaults to all entries in the given map.
Tip: For More Information
For more detailed information on the specific values of the optional map-type
, format
, and options
, see the auto.master manual page (man 5 auto.master
).
The following entry in auto.master
tells autofs
to look in /etc/auto.smb
, and create mount points in the /smb
directory.
Direct mounts create a mount point at the path specified inside the relevant map file. Instead of specifying the mount point in auto.master
, replace the mount point field with /-
. For example, the following line tells autofs
to create a mount point at the place specified in auto.smb
:
Tip: Maps without Full Path
If the map file is not specified with its full local or network path, it is located using the Name Service Switch (NSS) configuration:
Important: Other Types of Maps
Although files are the most common types of maps for auto-mounting with autofs
, there are other types as well. A map specification can be the output of a command, or a result of a query in LDAP or database. For more detailed information on map types, see the manual page man 5 auto.master
.
Map files specify the (local or network) source location, and the mount point where to mount the source locally. The general format of maps is similar to the master map. The difference is that the options appear between the mount point and the location instead of at the end of the entry:
Make sure that map files are not marked as executable. You can remove the executable bits by executing chmod -x MAP_FILE
.
Specifies where to mount the source location. This can be either a single directory name (so-called indirect mount) to be added to the base mount point specified in auto.master
, or the full path of the mount point (direct mount, see Section 23.2.1.1, “Direct Mounts”).
Nfs Mount Options Autofs
Specifies optional comma-separated list of mount options for the relevant entries. If auto.master
contains options for this map file as well, theses are appended.
Linux Nfs Mount Options
Specifies from where the file system is to be mounted. It is usually an NFS or SMB volume in the usual notation host_name:path_name
. If the file system to be mounted begins with a '/' (such as local /dev
entries or smbfs shares), a colon symbol ':' needs to be prefixed, such as :/dev/sda1
.
Nfs Mount Autofs