Last Updated: September 15, 2020
·
103.7K
· larrywilliamson

Automounting NFS share in OS X into /Volumes

(you may want to read this on GitHub @ https://gist.github.com/l422y/8697518, since syntax formatting on coderwall is a bit wonky)

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:
bash 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".
bash $ 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 in 10.8.5 (Mountain Lion) and 10.9.1 (Mavericks)

I KNOW, RIGHT?

Feel free to send me large checks and/or high five the screen (and hit the big red upvote button on top of this page)
hitmeup@l422y.com

HERETIC - DESIGN + TECHNOLOGY + MARKETING

L422Y.com

21 Responses
Add your response

I tried to up vote you but CoderWall sucks and it wouldn't work. So here's a +1 comment.

over 1 year ago ·

Thank you for this. I couldn't up-vote either :/

over 1 year ago ·

Awesome, I have been using Automator scripts at the moment to get this done, which sucks, because they are launched when the user logs in instead of when the machine boots.

Tried to upvote to, but no dice there.

over 1 year ago ·

@depl0y: yeah. i was actually using launchctl and shell scripts right before i figured this out.

over 1 year ago ·

It works, if done manually from the terminal, after my Mac has booted.
I get:

automount: /Volumes/Public: mountpoint unavailable

But, when I (recreate) the /Volumes/Public folder and then execute sudo automount -cv, my folder is mounted:

automount: /Volumes/Public mounted

Why is the /Volumes/Public folder deleted when I reboot ?

over 1 year ago ·

@goudkamp are you sure you are using "/../Volumes/Public" in your auto_nfs? This is what the whole work-around is about. If you just use "/Volumes/Public", you have to manually create the mount point and it won't work automatically.

** OSX Mavericks deletes any user created folders in /Volumes on restart. **

over 1 year ago ·

Could not believe how simple a solution this was, nor why Apple felt the need (assuming it was intentional) to change the behaviour. Thanks for the workaround.

over 1 year ago ·

@gaz_stephens i know. i could hardly believe it myself! after weeks of custom scripts and solutions (with their own issues, of course) ... reverting to simple path obfuscation is what finally did it. and it's just a three character difference!

over 1 year ago ·

If you're having any weird issues with your mounts timing out or constantly disconnecting try disabling jumbo frames on both your mac and the server, that solved the problem for me!

over 1 year ago ·

also, sometimes forcing version 3 NFS connectivity helps, by using vers=3

over 1 year ago ·

Hi, Thanks for this solution. But what if I wanted to mount my nfs mount under / and not /Volumes. Would I just be using /../ instead of /../Volumes? Thanks in advance.

over 1 year ago ·

@bio_chemist -- I don't know that you need to use /../ in the case of mounting outside of Volumes, but /../ should work.

over 1 year ago ·

hello
Thanks for your post
However with your solution, the mounted drive is not available on desktop,nor finder
I can access only with terminal !

any hints ?
Thanks

over 1 year ago ·

@dahouet
Finder > Go > Go To Folder
Type in "/Volumes" enter,
Finder window pops up with the mounted volume. You can then drag it into your Favourites bar for quick access.

over 1 year ago ·

Great! Just what I needed.
I can make it work, but the folder under /Volumes is empty! How come? Does this work under OS X 10.10 El Capitan?

over 1 year ago ·

I made it work. It works under El Capitan also. Misconfigured "auto_nfs"... I referenced the wrong folder on my NAS...

over 1 year ago ·

OK, I followed your instructions, but when I try to access any of the mountpoints I get no results. An "ls" from the terminal says "ls: : Operation not permitted".

I've checked the permissions on the NFS server side and they are fine; in fact, I can connect to it just fine with my Linux servers.

Any suggestions? I'm on macOS Sierra.

over 1 year ago ·

Gist link is broken

over 1 year ago ·

Is still working on 10.13.4
I am mounting for a OD network user home on a 10.10.4 server. Client iMac is 10.13.4. Automounting still works but the preferences syncing is not there. It suppose to follow the setting from another machine which I login as network user. Any ideas? I tried launchd method but your way is so far the simplest and working. Thank you.

over 1 year ago ·

This no longer seems to work in macOS Catalina (10.15)

over 1 year ago ·

To make this work in Catalina, replace /..Volumes/my_mount with /System/Volumes/Data/Volumes/my_mount . The / mount in Catalina is read-only now. All update have to be done to an overplayed FS mount. Additionally, you will need to create the my_mount folder before resetting the auto mounter. And I have noticed that periodically I have to recreated the folder after a restart (though not always).

over 1 year ago ·