💾 Archived View for cdaniels.net › posts › osx-autofs.gmi captured on 2022-06-03 at 23:00:32. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-01-08)
-=-=-=-=-=-=-
Published 2016-10-09
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.
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.
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 auto_master, except for the line "/mnt auto_data", which specifies the map auto_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[1] for more information). If you want to mount smb, try [2] (not tested), and if you want to mount afp, try [3] (not tested).
[2] - Create a Permanent SMB Mount in OSX
[3] - Mounting NAS Volumes in Mac OS X the Right Way
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.
Copyright 2016 Charles Daniels.