After finishing my blog post “Automount with launchd” I talked about it with my friend Herman. The launchd solution had a code-smell which usually is not a good sign. It works fine but it has too much dependencies.
The launchd
path and just running a script to mount the NFS shares seemed a better solution. At least no longer a workaround.
I tried mounting NFS with the mount
command but the results were somewhat unexpected.
Another search-result brought me to Will Haley’s page “Mount an NFS Share on a Mac using the Terminal”
On that page Will describes how to make the NFS mount persistent, in other words surviving reboots.
Persistance through /etc/fstab
To make the NFS mount point persistent you only need to edit the file /etc/fstab
. Do not edit the file directly, use sudo vifs
to edit the file. As you might have guessed vifs
uses the vi
syntax.
The different fields of an fstab
line:
- field 1: fs_spec, the remote filesystem
- field 2: fs_file, the mountpoint for the filesystem
- field 3: fs_vfstype, the type of the filesystem
- field 4: fs_mntops, the mountoptions in a comma separated list
Detailed information is available via man fstab
.
My /etc/fstab
after adding my mount points with vifs
:
$ cat /etc/fstab
#
# Warning - this file should only be modified with vifs(8)
#
# Failure to do so is unsupported and may be destructive.
#
192.168.200.200:/volume1/calibre /System/Volumes/Data/Nandi/calibre nfs rw,nolockd,resvport,hard,bg,intr,rw,tcp,nfc,rsize=65536,wsize=65536
192.168.200.200:/volume1/docker /System/Volumes/Data/Nandi/docker nfs rw,nolockd,resvport,hard,bg,intr,rw,tcp,nfc,rsize=65536,wsize=65536
192.168.200.200:/volume1/web /System/Volumes/Data/Nandi/web nfs rw,nolockd,resvport,hard,bg,intr,rw,tcp,nfc,rsize=65536,wsize=65536
Triggering the NFS mount points:
sudo automount -cv
Checking the mount points:
$ mount
...
map -static on /System/Volumes/Data/Nandi/web (autofs, automounted, nobrowse)
map -static on /System/Volumes/Data/Nandi/docker (autofs, automounted, nobrowse)
map -static on /System/Volumes/Data/Nandi/calibre (autofs, automounted, nobrowse)
If you are looking for a way to mount SMB shares I did not see a way to add it via fstab
. For that I suggest to go for the launchd solution.
Conclusion
It took me a long time to get to this solution but the final result is very satisfying, no more code smell!