Automounting NFS shares in OSX
Trying to get a NFS mount mounted under /Volumes/
in OSX is more difficult than it sounds.
You basically have to trick OSX into allowing you to mount the NFS share in /Volumes/
by using ../
in the directory listing.
Example:
cd /System/Volumes/Data/Volumes
pwd
/System/Volumes/Data/Volumes
Using the ../
trick, which goes to the same directory:
cd /System/Volumes/Data/../Data/Volumes
pwd
/System/Volumes/Data/Volumes
Add the auto_nfs to the /etc/auto_master file:
#
# Automounter master map
#
+auto_master # Use directory service
#/net -hosts -nobrowse,hidefromfinder,nosuid
/home auto_home -nobrowse,hidefromfinder
/Network/Servers -fstab
/- -static
/- auto_nfs -nobrowse,nosuid
Create the /etc/auto_nfs file
With my NFS server being 192.168.1.204, and the NFS share from that server being /mnt/nfsdir2share, this would be the content of the /etc/auto_nfs file:
/System/Volumes/Data/../Data/Volumes/my_mount -fstype=nfs,noowners,nolockd,resvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.204:/mnt/nfsdir2share
Options explained:
-
nfs
: Self explanatory -
noowners
: Ignore ownership on this volume. -
nolockd
: All locks will be local and not seen by the server and likewise not seen by other NFS clients for NFSv3 mounts. -
resvport
: Use a reserved socket port number. This flag is obsolete, but on OSX, the mounting will fail without it. -
hard
: Circular explanation from the man page: "Same as not specifying soft".soft
: A soft mount, which implies that file system calls will fail after retrycnt round trip timeout intervals. -
bg
: If an initial attempt to contact the server fails, fork off a child to keep trying the mount in the background. Useful for fstab, where the file system mount is not critical to multiuser operation. -
intr
: Make the mount interruptible, which implies that file system calls that are delayed due to an unresponsive server will fail with EINTR when a termination signal is posted for the process. -
rw
: Mount with read/write access. -
tcp
: Use TCP transport. -
nfc
: Convert name strings to Unicode Normalization Form C (NFC) when sending them to the NFS server.
You can reboot at this point, and the NFS share will be mounted, or you can use the automount
command:
sudo automount -cv
. . .
automount /Volumes/my_mount: mounted
GitHub Gist - osx_automount_nfs.md https://gist.github.com/L422Y/8697518
manpagez: man pages & more - man mount_nfs(8) http://www.manpagez.com/man/8/mount_nfs/osx-10.7.php
FreeBSD Manual Pages https://www.freebsd.org/cgi/man.cgi?mount_nfs(8)
TrueCrypt mount permissions -- noowner https://discussions.apple.com/thread/1798390