How to install and configure AutoFS

Home > Search > How-to
  by

Use apt-get or yum to install AutoFS.

~]# yum install autofs

 

Start and enable AutoFS.

~]# systemctl start autofs
~]# systemctl enable autofs
~]# systemctl status autofs

 

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/myShare 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 myShare 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 CIFS or NFS share. In this example, the /etc/auto.nfs file will contain the logic to mount the NFS share.

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

 


Firewall

Ensure Firewalld or Iptables is configured to allow NFS on both the client and server.

 


CIFS

Create /etc/auto.cifs.

~]# touch /etc/auto.cifs

 

Ensure /etc/auto.cifs 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.cifs

 

The first field in /etc/auto.cifs 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/myShare on the client, you will have /mnt in /etc/auto.master and myShare in /etc/auto.cifs. 

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

share  -fstype=cifs,username=johndoe,password=myPassword  ://cifs.example.com/share

 

Install CIFS utilities.

~]# yum install cifs-utils

 

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

~]$ mount
. . . 
/etc/auto.cifs on /mnt type autofs

 

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

~]# ls /mnt/myShare

 

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

~]$ mount
. . . 
/etc/auto.cifs on /mnt type autofs
/var/myShare on /mnt

 

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

~]# ls /mnt/myShare
File1 File2 File3

 


NFS

Install the NFS Utilities package.

~]# yum install nfs-utils

 

Create /etc/auto.nfs.

~]# 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/myShare on the client, you will have /mnt in /etc/auto.master and myShare in /etc/auto.nfs. 

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

myShare    nfs.example.com:/share

 

Start and enable NFS.

~]# systemctl start nfs
~]# systemctl enable nfs
~]# systemctl status nfs

 

Restart AutoFS.

~]# systemctl restart autofs
~]# systemctl status 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:/var/myShare on /mnt/share

 

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

~]# ls /mnt/myShare

 

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

~]$ mount
. . . 
/etc/auto.nfson /mnt type autofs
/var/myShare on /mnt

 

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

~]# ls /mnt/myShare
File1 File2 File3

 

 


Debugging

Ensure you can manually mount the share using the mount command.

~]# mount -t nfs fs1.example.com:/srv/nfs/share /mnt/example

 

mount -t cifs //fs1.example.com/share /mnt -o username=john.doe,password=MyPassword

 

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/myShare. 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 .
dr-xr-xr-x. 2  root  root 4096  Aug  29  15:42 ..

 

Try disabling SELinux, Firewalld, and Iptables, if possible.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments