NFS shares over local network with autofs

Wanting to share files over my home network to other devices, I settled on the NFS protocol. Specifically, I decided to use the program autofs as it automatically mounts shares of local files on-demand (thus reducing system overhead when the shared files aren’t needed). I wanted to write myself a concise guide for easy set-up in the future, so here goes:

Firstly, install autofs and nfs-kernel-server. Then, create a directory to map your shares to with sudo mkdir /export.

In my instance, I appended the following to /etc/auto.master:

/export	/etc/auto.export --timeout=60

and the following to /etc/auto.export (a file I’ve designated to handle mounts to the /export directory):

jacobbrett \
	/Movies		-fstype=nfs4,ro	:/home/jacobbrett/Videos/Movies \
	/Music		-fstype=nfs4,ro	:/home/jacobbrett/Music \
	/Music\ Videos	-fstype=nfs4,ro	:/home/jacobbrett/Videos/Music\ Videos \
	/TV\ Series	-fstype=nfs4,ro	:/home/jacobbrett/Videos/TV\ Series

Finally, I appended the following to /etc/exports:

"/export/jacobbrett/Music Videos",async,subtree_check)
"/export/jacobbrett/TV Series",async,subtree_check)

This ensures that only computers on my local network can access the shares (specified by; async is also a significant option. Additionally, you may wish to add the option insecure so that shares may be accessed via XBMC.

Now, start your NFS server with sudo start nfs-kernel-server and the autofs service with sudo start autofs (alternatively, use the command restart if either are already running). Congratulations.

showmount -a should output all client devices and shares they’ve mounted. e.g. (where is a device on my local network):

To enumerate: autofs first reads auto.master. My reference to /etc/auto.export is discovered, with a timeout of 60 seconds—that is, Any file (or directory) referenced within /etc/auto.export will automatically unmount after 60 seconds of no access (this lessens server overhead). I’ve set files referenced within /etc/auto.export to be mounted within /export, as per the above output of showmount seen above.

Further reading:

This entry was posted in Linux and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.