Automatically Mount Network Drives using Autofs on MacOS

Update, 2020-04-08: I now use Arq with MinIO, which I find faster and more reliable.

I use Arq to backup my Mac both to Dropbox and to my Synology NAS, but I’ve had difficulty keeping the SMB network share mounted and available for Arq. The solution to this problem is Autofs (Apple White Paper).

Autofs is an automounter, a program for ‘automatically mounting directories on an as-needed basis’, that was first released in Solaris 2.0, and comes preinstalled on MacOS since 10.5. This means, once configured, Autofs will automatically mount network shares and reconnect them if my NAS is disconnected for whatever reason. Here’s how I setup Autofs (jamesramsay/dotfiles cf11730).

Create a mount point

The mount point is the directory where Autofs will mount the network share. We will mount the share in /mnt/Synology.

From the Terminal, create the /mnt directory:

sudo mkdir /mnt

Add a map to the master map

Each map in the master map consists of a mount point (/mnt/Synology) and a mount map file. We will create the mount map file (auto_synology) in the next step.

Add the map to the master map:

echo "/mnt/Synology		auto_synology" | \
  sudo tee -a /etc/auto_master

Refer to auto_master documentation for more details.

Create the mount map file

The mount map file must be located in the /etc directory. To open the new mount map file for editing, execute:

sudo $EDITOR /etc/auto_synology

The mount map file is a list of trigger folders and network shares that will be mounted automatically. Add a line for each share to be mounted automatically:

Arq    -fstype=smbfs,rw,noowners ://user:[email protected]/Arq

The mount map file above has only one mount. Autofs will mount our network share ://user:[email protected]/Arq at /mnt/Synology/Arq. The arguments between the trigger location and network share specify the SMB protocol (smbfs), to mount the share for read and write access (rw) and to mount the share with permissions inherited from the mount point (noowners).

Refer to the mount documentation for all the supported options.

Update automount

To finish setting up Autofs we need to flush the cache, which will cause Autofs to reload the /etc/auto_master file. Using automount, execute:

sudo automount -vc

The cache will be flushed and the share we configured should be mounted. Autofs will now automatically mount the network share at boot and whenever it is needed by Arq.