fuoa-g
Last Updated: May 02, 2018
·
60.82K
· larrywilliamson
Ceef79191efd23932c20696353d44bd2

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

Say Thanks
Respond

19 Responses
Add your response

12353
Img 0719

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

over 1 year ago ·
12403
Dd5dd4d85b37e6dcbd4b982946502afa

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

over 1 year ago ·
12496
187f3356c852d3962517834d20aa18f7 normal

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 ·
12529
Ceef79191efd23932c20696353d44bd2

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

over 1 year ago ·
12855
Martijn normal

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 ·
12870
Ceef79191efd23932c20696353d44bd2

@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 ·
14297
Default profile 0 normal

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 ·
14298
Ceef79191efd23932c20696353d44bd2

@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 ·
16420
5d7031cae1f36c2cbbd4b812a24709d9

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 ·
16431
Ceef79191efd23932c20696353d44bd2

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

over 1 year ago ·
17057
Default profile 2 normal

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 ·
17087
Ceef79191efd23932c20696353d44bd2

@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 ·
17963
None

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 ·
18295
1vjtcvdl normal

@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 ·
25294
None

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 ·
25306
None

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 ·
28761

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 ·
29193
04ed2b23acc1400315dd1fb5f364b065

Gist link is broken

9 months ago ·
29856

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.

7 days ago ·