Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@L422Y
Last active March 22, 2024 13:44
Show Gist options
  • Save L422Y/8697518 to your computer and use it in GitHub Desktop.
Save L422Y/8697518 to your computer and use it in GitHub Desktop.
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

For pre-Catalina: 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

For Catalina and up: To (this is all one line)

/System/Volumes/Data/../Data/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

@AdamCBernstein
Copy link

AdamCBernstein commented Jul 10, 2020

My "struggle" with getting MacOS Catalina NAS NFS shares was quite simple, once I got the right information. Configuration files.

/etc/auto_master:

#
# Automounter master map
#
# Literal mount point for filesystems described in "auto_resources"
#
/System/Volumes/Data/Volumes auto_resources
+auto_master		# Use directory service
    ... the rest is just boiler plate...

/etc/auto resources:

share1 -fstype=nfs,resvport,locallocks,soft,intr,rw,rsize=16384,wsize=16384,fnc 192.168.10.12:/mnt/share1
share2 -fstype=nfs,resvport,locallocks,soft,intr,rw,rsize=16384,wsize=16384,fnc 192.168.10.12:/mnt/share2

Afterwards: sudo automount -vc

One point: Make sure you can manually mount your NFS shares, and have proper access to the mounted filesystem before configuring automount.

@dmlane
Copy link

dmlane commented Aug 23, 2020

Does anyone have a solution to /etc/auto_master being overwritten on Catalina updates>

@Michelasso
Copy link

Does anyone have a solution to /etc/auto_master being overwritten on Catalina updates>

Make a copy and copy it over the new /etc/auto_master after each update. Or restore it from a backup (Time Machine or else) after the update. That's what I used to do, nothing automatic I'm afraid.

@dmlane
Copy link

dmlane commented Aug 24, 2020

Does anyone have a solution to /etc/auto_master being overwritten on Catalina updates>

Make a copy and copy it over the new /etc/auto_master after each update. Or restore it from a backup (Time Machine or else) after the update. That's what I used to do, nothing automatic I'm afraid.

Thanks - that's what I do, but it's really annoying if there's an automatic update while I'm away as I have some jobs which will fail.
Debian has a autofs.master.d folder which allows custom config to be included which doesn't get clobbered - it's a shame there's nothing similar on Catalina.

@tIsGoud
Copy link

tIsGoud commented Oct 28, 2020

I struggled with the same "overwritten" problem but found a solution. My first attempt was rewriting auto_master with launchd. Works fine but it feels like a workaround. My "proper" solution is by using vifs and fstab.

The solution is described in "Persistent NFS Mountpoints on macOS".

@dmlane
Copy link

dmlane commented Oct 28, 2020

I struggled with the same "overwritten" problem but found a solution. My first attempt was rewriting auto_master with launchd. Works fine but it feels like a workaround. My "proper" solution is by using vifs and fstab.

The solution is described in "Persistent NFS Mountpoints on macOS".

Thank you - that's really useful - I didn't know about vifs.
On Linux systems, fstab mounts the entries permanently on reboot. I saw that fstab is referenced in auto_master but it hadn't clicked that it was only used by automount on Catalina. Thanks again - I'll do some tests.

@albertovm
Copy link

albertovm commented Sep 27, 2023

Do you still using NFS with Monterey? It was working fine to me until latest 12.7 update. Regards.

It was working fine with:

/etc/auto_master:
#
# Automounter master map
#
+auto_master        # Use directory service
#/net           -hosts      -nobrowse,hidefromfinder,nosuid
/home           auto_home   -nobrowse,hidefromfinder
/Network/Servers    -fstab
/-          -static
/Users/Share        auto_nfs
/etc/auto_nfs:
mntp    -noowners,nolockd,noresvport,hard,bg,intr,rw,tcp,nfc server:/share

@L422Y
Copy link
Author

L422Y commented Sep 27, 2023

Honestly I haven't used NFS in probably five or six years :)

@homonto
Copy link

homonto commented Oct 18, 2023

for the latest OS - Sonoma - the command in /etc/auto_nfs that works for me is:
/System/Volumes/Data/../Data/Volumes/truenasnfs -fstype=nfs,noowners,nolockd,hard,bg,intr,rw,tcp,nfc,resvport nfs://192.168.100.4:/mnt/pool/truenasnfs

without "resvport" it was:
ls: /Volumes/truenasnfs: Operation not permitted

@L422Y
Copy link
Author

L422Y commented Oct 23, 2023

without "resvport" it was:

Interesting, I wonder if it's (inadvertently?) using the privileged access it needs for the privileged port (resvport) to access the filesystem as well

@albertovm
Copy link

for the latest OS - Sonoma - the command in /etc/auto_nfs that works for me is: /System/Volumes/Data/../Data/Volumes/truenasnfs -fstype=nfs,noowners,nolockd,hard,bg,intr,rw,tcp,nfc,resvport nfs://192.168.100.4:/mnt/pool/truenasnfs

without "resvport" it was: ls: /Volumes/truenasnfs: Operation not permitted

Unfortunately... not working for MacOS 12.7. Not yet.
/System/Volumes/Data/Users/Share/SSD -fstype=nfs,noowners,nolockd,hard,bg,intr,rw,tcp,nfc,resvport nfs://iomega-nas.local:/SSD

This works:
sudo mount -o resvport,soft,intr,rsize=8192,wsize=8192 iomega-nas.local:/SSD /Users/Share/SSD

@RJVB
Copy link

RJVB commented Oct 24, 2023 via email

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