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.
Automatically mounting shares can be useful, for:
Downloads
folder to ease up on the storage
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.
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:
PATH
is the path where the share should be mounted, for instance /Users/joe/Music
,HOSTNAME
is the hostname of the AFP server, andSHARE
is the shared mount point.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
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:
PATH
is the path where the share should be mounted, for instance /Users/joe/Music
,USERNAME
and PASSWORD
are the credentials used to mount the Windows share,HOSTNAME
is the hostname of the Samba / Windows server, andSHARE
is the shared mount point.
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
.
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:
PATH
is the path where the share should be mounted, for instance /Users/joe/Music
,HOSTNAME
is the hostname of the AFP server, andSHARE
is the shared NFS export.
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:
bg
- automatically try to remount the share in the background if the server cannot be contacted,intr
- makes the share interruptable,soft
- specify that the share is to be soft-mounted, andtimeo=36000
sets the timeout to one hour (timeo
is defined to take values in tenths of a second).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.
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.