Bootstrap FreeKB - AutoFS - Install and configure AutoFS with NFS (Network File System)
AutoFS - Install and configure AutoFS with NFS (Network File System)

Updated:   |  AutoFS articles

Typically, AutoFS is used to automatically mount a CIFS (Common Internet File System) or NFS (Network File System) share, or both. This article describes the process to setup AutoFS to mount an NFS share. Refer to install and configure AutoFS with CIFS for the steps on how to setup AutoFS to mount an CIFS share.

On a Red Hat distribution (CentOS, Fedora, Red Hat), dnf or yum can be used to install the NFS utilties and AutoFS packages.

dnf install autofs
dnf install nfs-utils

 

Before setting up AutoFS, ensure you can manually mount the share using the mount command.

mkdir /mnt/share
mount -t nfs fs1.example.com:/srv/nfs/share /mnt/share

 

Then, use the umount command to unmount the share.

umount /mnt/share
rmdir /mnt/share

 

The ps command can be used to determine if your system is using init or systemd. If PID 1 is init, then you will use the service command. If PID 1 is systemd, then you will use the systemctl command.

If your system is using systemd, use the systemctl command to start and enable autofs.

systemctl enable autofs
systemctl start autofs
systemctl status autofs

 

If your system is using init, use the chkconfig and service commands to start and enable autofs.

chkconfig autofs on
service autofs start
service autofs status

 

In this example, the hostname of the file server is server1.example.com, and directory /mnt/share is being shared. The network path to the share is //server1.example.com/share.

In this example, AutoFS will mount //server1.example.com/share to /mnt/myShare on the client.

 

In the /etc/auto.master configuration file, specify the root directory on the client that the share will be mounted on. In this example, since we want //server1.example.com/share mounted to /mnt/share on the client, the root of the mount point is just /mnt. Note: Only /mnt needs to exist on the client. You do not need to create a directory named share on the client.

The second field of /etc/auto.master will be the absolute path to a file that will contain the logic to mount the NFS share. In this example, the /etc/auto.nfs file will contain the logic to mount the share.

/mnt    /etc/auto.nfs    --timeout=60 --ghost

 

Ensure firewalld or iptables is configured to allow NFS on both the client and server.

 

Create /etc/auto.nfs. This file does not need to be named auto.nfs. It can be named anything you would like.

touch /etc/auto.nfs

 

Ensure /etc/auto.nfs permissions are -rw-r--r--. Do not add the x (execute) permission, as this will cause the file to be executed instead of read.

chmod 644 /etc/auto.nfs

 

The first field in /etc/auto.nfs will be the name of the directory on the client where AutoFS will mount the share. For example, if you want to mount //server1.example.com/share to /mnt/share on the client, you will have /mnt in /etc/auto.master and share in /etc/auto.nfs. 

The second field in /etc/auto.nfs will be the file server hostname and the share directory.

share    nfs.example.com:/share

 

Start and enable NFS.

systemctl start nfs
systemctl enable nfs
systemctl status nfs

 

Since changes have been made to configuration files, you will need to restart AutoFS so that AutoFS can used the updated configuration files.

 

systemctl restart autofs

 

The mount command should show that auto.nfs is mapped to mnt. However, //server1.example.com/share will not be mounted at /mnt/myShare because AutoFS is an on-demand mount.

mount
. . . 
nfs.example.com:/share on /mnt/share

 

List the contents of /mnt/share, which will trigger AutoFS to automount the NFS share.

ls /mnt/share

 

The mount command should now show that AutoFS mounted the share.

mount
. . . 
/etc/auto.nfs on /mnt type autofs
nfs.example.com:/share on /mnt/share type nfs

 

You should now be able to list the contents of /mnt/myShare.

ls /mnt/share
. . .
File1 File2 File3

 

If the share is not being mounted, add the following to /etc/sysconfig/autofs. Restart autofs, and there will be debugging events in /var/log/messages.

OPTION="--debug"

 

In the prior examples, the share is being mounted on /mnt/share. List the /mnt directory. Notice the /mnt directory is empty and is 0 bytes. 0 bytes means that automount has read your maps and is possessing the directory.

ls -la /mnt
. . .
drwxr-xr-x  2  root  root    0  Aug  29  15:42 .



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 18c9b4 in the box below so that we can be sure you are a human.