Tuesday, June 21, 2016

autofs: automount nfs share

This small tool is designed to mount various types of filesystems, not only NFS shares. It watches for when you try to access defined mount point and auto-mount it right away. Then after specified timeout, it will unmount them.
Advantage: if you have many NFS clients, you may want to reduce active connections to the server and improve overall performance of the server. Or perhaps you are too lazy to mount NFS, as I am and just give it to the hands of autofs (:

The setup is pretty simple, you just need to have functional NFS shares and autofs installed.
In my example, I'll have two shares - v1, and v2 and I want them to be mounted at /mnt/synology.

First add the base mount folder for autofs in /etc/autofs/auto.master
# synology mount point
/mnt/synology         /etc/autofs/auto.synology --timeout 60
NOTE: you need to create the mount point folder.

Next file is /etc/autofs/auto.synology where you can see my two NFS shares

v1  -rw,soft,intr,rsize=8192,wsize=8192 synology:/volume1/v1
v2  -rw,soft,intr,rsize=8192,wsize=8192 synology:/volume2/v2
To explain the syntax: first you define where you want to mount (v1, v2), then there are mount parameters and finally you specify the server (synology:<path>). 
NOTE: the v1 and v2 folders will be autocreated by autofs.

Now the last step is to enable and start autofs:
systemctl enable autofs
systemctl start autofs
When you now list the mount point /mnt/synology, it'll be empty, but if you list/access /mnt/synology/v1 it'll be created and automounted by autofs.

No comments:

Post a Comment