Auto-mounting an NFS share using autofs

by Anish


Posted on Friday July 6


Referefce https://docs.oracle.com/cd/E23823_01/html/816-4555/rfsrefer-75.html

autofs is a program for automatically mounting directories on an as-needed basis. Auto-mounts are mounted only as they are accessed, and are unmounted after a period of inactivity. Because of this, automounting NFS/Samba shares conserves bandwidth and offers better overall performance compared to static mounts via fstab

autofs uses /etc/auto.master (master map) as its default primary configuration file.

Auto-mounting an NFS share

First Verify the NFS mount is accessiblle and available for mount

[root@]showmount -e 192.0.2.68
Export list for 192.0.2.68:
/mnt/nfsvol (everyone)

Install autofs

[root@]yum -y install autofs 
*       -rw     192.0.2.68:/mnt/nfsvol

Configuring user home directory in NFS share

Edit the file /etc/auto.master and create an indirect maps

[root@]cat /etc/auto.master
/home      /etc/auto.home

Edit/create the file /etc/auto.home and add automount location

[root@]cat /etc/auto.home
*       -rw     192.0.2.68:/mnt/nfsvol

Changes to the The Name Service Switch (NSS) configuration file, /etc/nsswitch.conf automount: files nis

start the autos service root@host-172-16-9-16 home]# systemctl start autofs

check the status of autofs service is running, you will be noticing lookupnssread_map: reading map file /etc/auto.home

Jul 06 04:27:07 host-172-16-9-16 automount[20523]: master_do_mount: mounting /home
Jul 06 04:27:07 host-172-16-9-16 automount[20523]: automount_path_to_fifo: fifo name /run/autofs.fifo-home
Jul 06 04:27:07 host-172-16-9-16 automount[20523]: lookup_nss_read_map: reading map file /etc/auto.home

Testing

Login to the client

[root@host-172-16-9-16 home]# ssh [email protected]
[email protected]'s password: 
Last login: Fri Jul  6 04:23:36 2018 from host-172-16-9-16

Check the pwd of the user it's mounted to the /home

-bash-4.2$ pwd
/home/test
-bash-4.2$ 

Check the df -kh the volume will be mounted

-bash-4.2$ df -kh 
Filesystem              Size  Used Avail Use% Mounted on
/dev/mapper/cl-root     6.2G  1.3G  5.0G  20% /
devtmpfs                908M     0  908M   0% /dev
tmpfs                   920M     0  920M   0% /dev/shm
tmpfs                   920M  8.5M  911M   1% /run
tmpfs                   920M     0  920M   0% /sys/fs/cgroup
/dev/vda1              1014M  181M  834M  18% /boot
tmpfs                   184M     0  184M   0% /run/user/0
192.0.2.68:/mnt/nfsvol  7.7G  128K  7.7G   1% /home/test

Troubleshooting Autofs

Enable logging, To do this, edit the file vi /etc/sysconfig/autofs and set LOGGING=debug and restart autofs service

All log message will be redirected to /var/log/messages

tail -f /var/log/messages
Jul  6 04:22:40 host-172-16-9-16 automount[20421]: mount_mount: mount(nfs): calling mkdir_path /home/test
Jul  6 04:22:40 host-172-16-9-16 automount[20421]: mount_mount: mount(nfs): calling mount -t nfs -s -o rw 192.0.2.68:/mnt/nfsvol /home/test
Jul  6 04:22:40 host-172-16-9-16 automount[20421]: spawn_mount: mtab link detected, passing -n to mount
Jul  6 04:22:40 host-172-16-9-16 automount[20421]: mount_mount: mount(nfs): mounted 192.0.2.68:/mnt/nfsvol on /home/test
Jul  6 04:22:40 host-172-16-9-16 automount[20421]: dev_ioctl_send_ready: token = 1
Jul  6 04:22:40 host-172-16-9-16 automount[20421]: mounted /home/test

Running automount in the foreground with verbose information

systemctl stop  autofs
Run automount in the foreground with verbose information sudo automount -f -v



Thanku for reading !!! Give a Share for Support

Asking for donation sound bad to me, so i'm raising fund from by offering all my Nine book for just $9


python Cryptography Topics
Topics
For Coffee/ Beer/ Amazon Bill and further development of the project Support by Purchasing, The Modern Cryptography CookBook for Just $9 Coupon Price

Kubernetes for DevOps

Hello Dockerfile

Cryptography for Python Developers

Cryptography for JavaScript Developers

Go lang ryptography for Developers