Table of Contents

About

MacOS has autofs built into the system and can be thus leveraged in order to automatically mount shares when they are accessed. This guide is a collection of notes on how to make autofs work under MacOS.

Usage Scenarios

Automatically mounting shares can be useful, for:

Relevant Files

The /etc/ directory on MacOS contains an auto_master file that then uses slave files in order to mount the various filesystems. On a vanilla MacOS High Sierra machine, the /etc/auto_master file has the following contents:

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

As you can observe, the /net, /home and /Network/Servers are already used by MacOS.

In order to define a custom share, an entry has to be added to /etc/auto_master, specifying a slave file to use in order to mount a filesystem.

Mounting AFP / Netatalk Shares

Edit /etc/auto_master and append a line at the end:

/-                      auto_afp        -nobrowse,nosuid

Then, create or edit a new file at /etc/auto_afp and add an AFP / Netatalk share to mount:

PATH	-fstype=afp,rw afp://HOSTNAME:/music

where:

Notice that there are no credentials such as a username or password specified - this is due to MacOS being smart enough to look up the credentials in the keychain; however, the share has to be mounted at least once for the credentials to be stored in the keychain.

The following example, mounts the AFP share called Music on the NAS server with the address nas.home into /Users/joe/Music:

/Users/joe/Music    -fstype=afp,rw afp://nas.home:/Music

Mounting Samba (SMB) / Windows Shares

Edit /etc/auto_master and append a line at the end:

/-                      auto_smb        -nobrowse,nosuid

Then, create or edit a new file at /etc/auto_smb and add a Windows share to mount, for instance:

PATH    -fstype=smbfs,rw ://USERNAME:PASSWORD@HOSTNAME:/SHARE

where:

The following example, mounts the share called Music on the NAS server with the address nas.home into /Users/joe/Music by authenticating to the NAS server with the username joe and the password mypass:

/Users/joe/Music    -fstype=smbfs,soft,noowners,nosuid,rw ://joe:mypass@nas.home:/Music

More information on the parameters -fstype=smbfs,rw can be found by issuing mount_smb.

Mounting NFS Shares

NFS is natively supported on MacOS! Edit /etc/auto_nfs and append a line at the end:

/-                      auto_nfs        -nobrowse,nosuid

Then, create or edit a new file at /etc/auto_nfs and add a NFS share to mount:

PATH	-fstype=nfs,rw,bg,intr,soft,timeo=36000	nfs://HOSTNAME:/SHARE

where:

The following example, mounts the NFS export path /mnt/Music on the NAS server with the address nas.home into /Users/joe/Music:

/Users/joe/Music    -fstype=nfs,rw,bg,intr,soft,timeo=36000 afp://nas.home:/mnt/Music

More information on the mount options -fstype=nfs,rw,bg,intr,soft,timeo=36000 can be found by issuing in a terminal man mount_nfs.

The options given in this example have the following meaning (from man mount_nfs) and are there to prevent Finder complaining about timeouts:

Accessing the Share

Once the files have been modified, the command:

automount -cv

has to be issued in order to make the changes effective.

After that, the local path can be accessed and MacOS should just mount the share.

Supported Filesystems

MacOS High Sierra supports the following filesystems:

and more information on the various parameters can be obtained by consulting the manual pages on the command line. However, the autofs procedure remains the same, just parameters change depending on what is desired.