How to mount NFS share on Mac

To mount NFS in our OS X the first thing we need is know where is the server and where is the directory, to do that we can use the command showmount:

showmount -e server-name-or-ip

Example:

leprosys@daenerys ~ % showmount -e merlin.lan
Exports list on merlin.lan:
/tmp/mnt/HD1

Note: merlin.lan is my router name with NFS.

Mount NFS share on Mac OS X:

The first step is to create a mount point, in this case, we will use /private/nfs:

sudo mkdir /private/nfs

Now we can mount the NFS share in the path create previously:

sudo mount -t nfs merlin.lan:/tmp/mnt/HD1 /private/nfs

You also can use the IP instead of the hostname, for example:

sudo mount -t nfs 192.168.1.1:/tmp/mnt/HD1 /private/nfs

If you see an error similar to this one:

192.168.1.1:/tmp/mnt/HD1 Operation not permitted

You can try mount the NFS share with this option -o resvport:

sudo mount -t nfs -o resvport 192.168.1.1:/tmp/mnt/HD1 /private/nfs
man 8 mount_nfs

resvport
    Use a reserved socket port number.  This is useful for mounting servers that require clients
    to use a reserved port number on the mistaken belief that this makes NFS more secure. (For
    the rare case where the client has a trusted root account but untrustworthy users and the
    network cables are in secure areas this does help, but for normal desktop clients this does
    not apply.)

Another useful option is to write on the NFS share rw and not only read the files:

sudo mount -t nfs -o resvport,rw 192.168.3.1:/mp3 /private/nfs

Very that is working

mount
ls -l /private/nfs

Automount NFS share

Edit the file /etc/auto_master and add to the end of the file /- auto_nfs -nobrowse,nosuid:

#
# 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

Now we have to create a file on /etc/auto_nfs:

/private/nfs   -fstype=nfs,noowners,nolockd,resvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.1:/tmp/mnt/HD1

Is possible use /Volumes as a mount point, we only need to create the directory this way:

/../Volumes/HD1   -fstype=nfs,noowners,nolockd,resvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.1:/mnt/HD1

Note: the /../ before Volumes is because the system deletes everything inside /Volumes every time the system start.

Execute this command to apply the updates:

sudo automount -cv

Extras

One thing that is annoying are the hidden files generated by OS X .DS_Store to prevent the creation of this files is possible to disable for all network devices and for one user with this command:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

To disable for all users:

sudo defaults write /System/Library/User\ Template/English.lproj/Library/Preferences/com.apple.desktopservices DSDontWriteNetworkStores true

And if we want delete the files already generated:

find . -iname '.DS_Store' -exec rm -rf {} \;
dot_clean .