Skip to main content

Automounting NFS Shares on macOS With autofs

A little known tool baked into OSX is autofs, also available for Linux, which automatically mounts filesystems when they become available. This is useful for several reasons. Namely, it saves you from having to open the terminal and type a mount command, or mounting through finder’s connect to server dialog. Additionally, autofs should make OSX more fault tolerant in the event that the device becomes unreachable, although I have yet to test this in real world applications.

Setup

On my home network, I have a computer at 192.168.88.100, exporting /data to my LAN over nfsv4. No authentication is used, ldap, nis, kerberos, or otherwise (indeed, all users are squashed to the owner of /data anyway). Perhaps not the most secure setup, but it gets the job done. My macbook (running OSX 10.10 Yosemite) is connected to the network via an access point, bridged at layer 2 with my router, meaning my setup should be functionally identical to someone with a typical wifi router. No other netowrk services or appliances are on this network that would be relevant to nfs.

Execution

Using autofs is relatively simple, although it is poorly documented, and can be a little fidgety to get going. The first step is to edit /etc/auto_master. Mine looks like this:

#
# Automounter master map
#
/mnt	 auto_data
+auto_master		# Use directory service
/net			-hosts		-nobrowse,hidefromfinder,nosuid
/home			auto_home	-nobrowse,hidefromfinder
/Network/Servers	-fstab
/-			-static

This is pretty much the default audo_master, except for the line /mnt auto_data, which specifies the map audo_data should be mounted onto /mnt. For a different mount point, replace /mnt with the desired mount point. Keep in mind that autofs, at least on mac, does not directly mount the export to the mountpoint, but rather to a subfolder. For example, mounting myserver:/export to /mnt, would result in myserver:/export being mounted on /mnt/export.

To define our automount map, edit /etc/auto_data (or /etc/auto_$yourmapname if you want a different name). Mine looks like this:

data	-fstype=nfs,resvport,rw,bg,soft,intr,tcp	192.168.88.100:/data

The first column specifies the subfolder onto which the export will be mounted under the mountpoint (in my case, this results in /mnt/data). The second specifies mount options. If you are mounting an nfs share, your mount options should look about the same, however you may wish to replace soft option with hard depending on use case (read the nfs manpage for more information). If you want to mount smb, try this link (not tested), and if you want to mount afp, try this one (not tested).

Finally, run sudo automount -vc to mount your shares. The output should look something like this:

automount: /mnt updated
automount: /net updated
automount: /home updated
automount: no unmounts

However, if you mess up with your automounter maps, it is liable to fail silently.

Notes

  • You can navigate to your mount point with finder with Go->Go to Folder, then drag it to your finder side panel for easy access later.
  • If you do not use authentication, or your nfs export does not squash all users to the export’s owner, you may encounter permissions issues, as your OSX UID will usually be different than your Linux, *BSD, or freeNAS UID.

Further Resources