Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automounting NFS share in OS X into /Volumes

I have spent quite a bit of time figuring out automounts of NFS shares in OS X...

Somewhere along the line, Apple decided allowing mounts directly into /Volumes should not be possible:

/etc/auto_master (see last line):

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

/etc/auto_nfs (this is all one line):

/Volumes/my_mount    -fstype=nfs,noowners,nolockd,noresvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.1:/exports/my_share

Make sure you:

sudo chmod 644 /etc/auto_nfs

Otherwise the automounter will not be able to read the config and fail with a ... parse_entry: getmapent for map failed... error in /var/log/messages

This will not work (anymore!) though it "should".

$ sudo automount -cv
...
automount: /Volumes/my_mount: mountpoint unavailable

Note that, if you manually create the mount point using mkdir, it will mount. But, upon restart, OS X removes the mount point, and automounting will fail.

What's the solution?

It's so easy my jaw dropped when I figured it out. Basically, we trick OS X into thinking we're mounting somewhere else.

When you're talking about paths in just about any environment, the root folder is the highest path you can reach, whether it's C:\ (windows) or / (*nix)

When you're at this path, attempting to reach the parent path, via .. will keep you at the root path.

For example: /../../../../ is still just /

By now, a few of you have already figured it out.

TL;DR / Solution:

Change your /etc/auto_nfs config from (this is all one line):

/Volumes/my_mount    -fstype=nfs,noowners,nolockd,noresvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.1:/exports/my_share

To (this is all one line):

/../Volumes/my_mount    -fstype=nfs,noowners,nolockd,noresvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.1:/exports/my_share

And re-run the automounter:

$ sudo automount -cv
...
automount: /Volumes/my_mount: mounted

..... there you go! Technically /../Volumes is still /Volumes, but the automounter does not see things that way ;)

This configuration persists the mount across restarts, and creates the mountpoint automatically.

I KNOW, RIGHT?

Feel free to send me large checks and/or high five the screen. hitmeup@l422y.com

@Leland

This comment has been minimized.

Copy link

Leland commented Aug 13, 2014

You, sir, are a prince. Also, this still works in Yosemite

@ershler

This comment has been minimized.

Copy link

ershler commented Aug 20, 2014

OK, now I freely admin that I am a dumb shit. I followed your instructions and sudo automount -cv successfully mounts my_mount. So I end up with the following from a df command.
map auto_home 0 0 0 100% 0 0 100% /home
rex.cvrti.utah.edu:/Volumes/NETDIR/people 15625000000 6692736432 8932263568 43% 418296025 558266473 43% /home/.hidden
map /etc/auto_nfs 0 0 0 100% 0 0 100% /Volumes/people
155.100.140.16:/Volumes/NETDIR/people 15625000000 6692736432 8932263568 43% 418296025 558266473 43% /Volumes/people

But, I'd like to use your ideas to auto mount NFS network home directories. Now my OS X server that holds the network home directories exports
/Volumes/NETDIR/people
All the user directories are under people.

In my OD master, my user home directories are just described as /people. How do I get your auto_nfs to mount things so that the user sees his/her network home directories? As it is now, if I log some into this Yosemite machine I end up with a people directory created on / and a user directory with the correct name with an new "empty" OS X directory.

dhcp-155-100-140-105:~ bridge$ pwd
/people/bridge
dhcp-155-100-140-105:~ bridge$ ls -l
total 0
drwx------+ 3 bridge cvrti 102 Aug 19 19:01 Desktop
drwx------+ 3 bridge cvrti 102 Aug 19 19:01 Documents
drwx------+ 4 bridge cvrti 136 Aug 19 19:01 Downloads
drwx------@ 37 bridge cvrti 1258 Aug 19 19:02 Library
drwx------+ 3 bridge cvrti 102 Aug 19 19:01 Movies
drwx------+ 3 bridge cvrti 102 Aug 19 19:01 Music
drwx------+ 3 bridge cvrti 102 Aug 19 19:01 Pictures
drwxr-xr-x+ 4 bridge cvrti 136 Aug 19 19:01 Public

Your help to lead this dumb shit out of the darkness would be very much appreciated. Right now all my users are running 10.8.5 and are screaming to get to Mavericks.

@ershler

This comment has been minimized.

Copy link

ershler commented Aug 20, 2014

Never mind. All I had to do was remove the /people directory and replace it with soft link to /Volumes/people. At that point everything works perfectly. Many, many thanks for your efforts!

@kai-h

This comment has been minimized.

Copy link

kai-h commented Aug 25, 2014

This works - except although I get the required device mounted in /Volumes/sharepoint, it doesn't show up on the desktop as a mounted server volume. It is mounted as AFP, using /../Volumes/sharepoint -fstype=afp afp://username:password@server.example.com/sharepoint in my auto_afp file (chmod'd 600 as I've got a password in it)

@L422Y

This comment has been minimized.

Copy link
Owner Author

L422Y commented Aug 31, 2014

you can just create a link to the /Volumes/sharepoint folder, and place it on your desktop.

@RJVB

This comment has been minimized.

Copy link

RJVB commented Nov 21, 2014

So this worked for me for a while (in a VM, even), but now I get something very weird.

First, my auto_master:

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

and auto_nfs:

/../Volumes/patux-home/bertin      -fstype=nfs,nolocks,locallocks,intr,soft,wsize=32768,rsize=32768,noauto,rw,tcp,nfc      nfs://patux.local/home/bertin
/../Volumes/patux-home/nsynced  -fstype=nfs,nolocks,locallocks,intr,soft,wsize=32768,rsize=32768,noauto,rw,tcp,nfc      nfs://patux.local/home/nsynced
> sudo automount -cv
automount: /net updated
automount: /home updated
automount: /Volumes/patux-home updated
automount: /../Volumes/patux-home/bertin: Can't convert to real path: Permission denied
automount: /../Volumes/patux-home/nsynced: Can't convert to real path: Permission denied
automount: no unmounts

Nowhere do I tell the system to mount anything on /Volumes/patux-home (or so I think). And worse, even root cannot read nor delete /Volumes/patux-home . It's only when I boot under 10.6 that I can see that that directory indeed contains the two actual mountpoints ...

>  mount
/dev/disk2s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
zVMS/VM on /Volumes/VMS (zfs, local, noatime)
zVMS/VM/zLinux on /Volumes/VMS/VM/Linux (zfs, local, noatime, nobrowse)
zVMS/VM/zhostside on /Volumes/VMS/VM/hostside (zfs, local, noatime, nobrowse)
zVMS/VM/zvirtSim36 on /Volumes/VMS/VM/virtSim36_zVMS (zfs, local, noatime, nobrowse)
zVMS/OPT/crossdevel on /opt/cross (zfs, local, noatime, nobrowse)
zVMS/OPT/MacPorts-10.9/varBuild on /Volumes/Debian/MP9/var/macports/build (zfs, local, noatime, nobrowse)
map -static on /Volumes/patux-home (autofs, automounted, nobrowse)

Thoughts?

@6twenty

This comment has been minimized.

Copy link

6twenty commented Dec 16, 2014

Everyone, heads up: if you automount to /Volumes (aka /../Volumes) you may have issues mounting any other filesystems. This includes external USB drives and disk images (DMG, ISO, etc). I experienced this in Yosemite, and it was due to autofs deleting the /Volumes directory and re-creating it as a mount point which has different permissions that can't be changed.

@breu

This comment has been minimized.

Copy link

breu commented Feb 9, 2015

You can also use /net/hostname/path if using NFS. Not sure about other protocols. Works on my Yosemite.

@bjuren

This comment has been minimized.

Copy link

bjuren commented Sep 18, 2015

Have anyone tried adding Volumes to the Dock? The name of the shares are somewhat not correct accordlingly to the Shares in the mount file.

@timkelty

This comment has been minimized.

Copy link

timkelty commented Oct 29, 2015

The problem I'm still having with all this is that my volume gets mounted owned by root:wheel. Therefore, I can't even cd into them.

@13eastie

This comment has been minimized.

Copy link

13eastie commented Nov 1, 2015

Many thanks, lawrencealan – I've been suffering from this issue since upgrading to a long-forgotten version of OS X ( (I'm now using El Capitan) to connect to a shared drive on my faithful home Ubuntu server.

On my MacBook:

sh-3.2# stat -f %Mp%Lp /etc/auto_nfs
0644
sh-3.2# cat /etc/auto_nfs
/../Volumes/share -fstype=nfs,noowners,nolockd,noresvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.0.10:/home/share
sh-3.2# mount
/dev/disk1 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
map -hosts on /net (autofs, nosuid, automounted, nobrowse)
map auto_home on /home (autofs, automounted, nobrowse)
map auto_nfs on /Volumes/share (autofs, nosuid, automounted, nobrowse)
localhost:/yu3ZQ6yl2KH4XIseZSXEWK on /Volumes/MobileBackups (mtmfs, nosuid, read-only, nobrowse)
sh-3.2# ls -l /Volumes/
total 26
-rw-r--r--@ 1 502   admin  6148 18 Mar  2012 .DS_Store
lrwxr-xr-x  1 root  admin     1  1 Nov 15:23 Macintosh HD -> /
drwxrwxrwx  0 root  wheel     0  1 Nov 15:23 MobileBackups
dr-xr-xr-x  2 root  wheel     1  1 Nov 15:23 share
sh-3.2# ls -l /Volumes/share
ls: share: Operation not permitted
sh-3.2# mount -t nfs -o resvport 192.168.0.10:/home/share /mnt/share
sh-3.2#

Only after the issue of the final command does the shared folder actually become accessible (which is why I've been running a script to this effect for years).

Salient points here are:

  1. The behaviour of NFS can be sensitive to port numbers being used. The message "Operation not permitted" in response to the ls command indicates that this may be the problem.
  2. If you are getting this error message, then the solution is to alter your entries in /etc/auto_nfs to include resvport rather than noresvport (see here for a bit more explanation).
  3. This approach will mount your shares automatically at boot-time, but will not make the sharing server visible in the side-bar of Finder (like AFP shares are, like NFS shares do if they are mounted manually, and like how I'm sure NFS shares used to be when configured straightforwardly using Disk Utility under older versions of OS X), which is what I really would like. My view is that auto-mounted shares should look and behave exactly the same as if they had been mounted manually – I'd be very grateful for any pointers as to how to make this happen, cheers.

Aside
There is a lot of banter around about Apple continuing to favour SMB over other sharing protocols which seems to me to be at odds with the reality that "home" (almost, by definition, Apple) users are, like me, very often running open-source UNIX-like OS's as headless media servers. Even if they are using Plex clients or DNLA (or whatever) they still need to manage their content somehow and CIFS and AFP seem to be rather clumsy compared to NFS as a means of doing this.

@prologic

This comment has been minimized.

Copy link

prologic commented Dec 29, 2015

Did anyone fix the issue with the share not being visible in Finder?

@robmoggach

This comment has been minimized.

Copy link

robmoggach commented Jan 11, 2016

using the nobrowse option will probably hide mounts as volumes in the finder - try without that

if you want a full list of options...

Mac OS Documentation: auto_master -- automounter master map

@RJVB

This comment has been minimized.

Copy link

RJVB commented Jan 27, 2016

After somehow getting rid of the error message (and "ghost" directory) mentioned in a previous commit this has been working almost flawlessly for me.
Now, after upgrading to kernel 3.14.59 on my Kubuntu box, I noticed

  • kernel console messages about nfs on Kubuntu (about a tainted module as far as I could see)
  • messages in system.log that my nfs server wasn't responding, and the corresponding symptoms when trying to access the mounts.

I could still do parallel mounts of the same shares, so the underlying issue must have had to do with Apple's automounting service. Since I already had one of the shared configured via /etc/fstab (the automounter doesn't accept nested mount points) I have now moved everything into /etc/fstab. In the end I prefer reliable functioning (and the possibility to -force- unmount the shares if required) over all the hassles that come with trying to get them mounted automatically.

@gvn

This comment has been minimized.

Copy link

gvn commented Feb 16, 2016

Like @6twenty, I also experienced other USB devices being clobbered (specifically a USB Blu-Ray drive), so I switched to using /Mount/NAME for my nfs share instead.

So far, so good!

@Patrick1610

This comment has been minimized.

Copy link

Patrick1610 commented Mar 28, 2016

Hi,

Can you limit the automount function to a specific network?
I would like it if my MacBook mounts my NAS drives when I am at home, but without trouble on other networks.

@TomKaltz

This comment has been minimized.

Copy link

TomKaltz commented Mar 28, 2016

When does the user-created mount directory get deleted by OSX? Can we use launchd to recreate the directory and run automount?

@MichalMMac

This comment has been minimized.

Copy link

MichalMMac commented May 20, 2016

@timkelty

To prevent automounting with root 700 permissions use indirect map instead of direct (See AutoFS whitepaper)

@exenza

This comment has been minimized.

Copy link

exenza commented Jul 8, 2016

Another solution a little bit more hacky is to leverage Applescript for the mount, the cons are that you need to use a custom script and is a little more tedious to setup, the advantages are that the credentials are stored in keychain and this solution should be more resistant to apple updates, I believe fooling the Volumes path is a bug which may be addressed at some point.

Here the whole explanation: http://nas-ho.me/?p=234

@MrBobb

This comment has been minimized.

Copy link

MrBobb commented Sep 5, 2016

Many thanks for the clearly detailed steps!
I think I replicated all of them but I must be doing something wrong because in the end I'm not able to see the content of my mounted NFS share.

My auto_nfs file looks like this:
/../Volumes/VideoEditing -fstype=nfs,noowners,nolockd,noresvport,hard,bg,intr,rw,tcp,nfc nfs://192.168.1.104:/exports/VideoEditing

From what I can judge, "VideoEditing" share is mounted. I see it in Finder under Shared / Servers / nfs / VideoEditing. Problem is that no file appears here. The "VideoEditing" share is located on a QNAP NAS where read/write permissions are set.

It looks like no rights are set to access sub-folders in the share.
Did anyone encounter a similar problem?

@zxfrank

This comment has been minimized.

Copy link

zxfrank commented Sep 16, 2016

Hello, I used your trick to mount my nfs share. It mount but I can't list or access it.
I always end with "ls: : Permission denied" as a user and with sudo

OSX ElCapitan v10.11.6
My nfs server is OpenFiler

(could be the same issue as MrBobb)
thanks for your help

@DaveAlton

This comment has been minimized.

Copy link

DaveAlton commented Dec 17, 2016

Every new folder created within my share is "read only" and I have to 'chmod' every time I create a folder. Is there a way to set permissions of new folders?

@MacBadger

This comment has been minimized.

Copy link

MacBadger commented Aug 20, 2017

You might find this useful:
http://blog.grapii.com/2015/06/keep-network-drives-mounted-on-mac-os-x-using-autofs/

It also addresses' the 'Volumes' issue without causing problems.

@aidyw

This comment has been minimized.

Copy link

aidyw commented Nov 16, 2018

Regarding getting mounts visible in Finder even across reboots. Here is a 'workaround'
Firstly dont mount directly into /Volumes. Instead create a suitable directory somewhere you are happy with. I choose the root of the mac's harddrive and named according to the server I was connecting to.
eg.

sudo mkdir /My_Server

Then use the autofs facility as described at the top of this post to create a set of mount points within this directory

/My_Server/my_mount1     -fstype=nfs,nfsvers=4,rw mx.shared-sun.com:/mnt/shared_sun_NAS/Music
/My_Server/my_mount2     -fstype=nfs,nfsvers=4,rw mx.shared-sun.com:/mnt/shared_sun_NAS/Pics

Of course if it is an NFS3 share you need to use the appropriate mount option in this autofs stanza.

Now mount them:

automount -cv

Now they are mounted. Open Finder and browse to the mount points. You can then use Finder to drag the individual mount point directories into the Devices side bar area.
An important note here. You may drag a directory called, in this example, 'my_moun1' BUT it will appear in the Devices sidebar as 'Music'. This is upside down. The only name that appears in the devices side bar is the name of the actual export directory on the server. Go figure? But hey, at least you can tell one server apart from another by placing all the mount points from a common server in the same root directory. I have no idea what Finder will do if you have 2 servers with identically named exports.

I would suggest shuffling the mounts in the side bar up to the top, they are then mounted before any other slower devices like for example USB sticks.
Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment