23

In linux, one of the great things you could do (for developers, in particular) was to mount a folder and locally bind it to another folder on the system.

This had the advantage over symlinks due do the fact tools like Git didn't detect it as being a different type of node, and you didn't need to remove the original contents. When you were done, you could simple unmount and you were left with the original filesystem contents.

However, mount -bind or mount.local don't seem to exist on Mac (as of OS X 10.10.2, Yosemite).

How do you go about this?

2 Answers 2

16

As mentioned by another user on StackOverflow, you can use an NFS mount do to this. However, it requires a little bit of one-time setup.

First, you'll need to set up an /etc/exports file (if you haven't done so already).

$ sudo tee -a /etc/exports <<< "/ -alldirs -mapall=$USER localhost"

Secondly, you'll need to start the rpc and nfsd services.

$ sudo launchctl start com.apple.rpcbind
$ sudo nfsd start

From there, give NFSd a little bit to wake up and get breakfast, and you should be good to mount:

$ sudo mount localhost:/path/to/target ./mnt

To restore the original contents, just do

$ sudo umount ./mnt
11
  • I tried to mount my exfat usb drive $ sudo mount localhost:/Volumes/Aren/Movies /Users/me/Movies/
    – Necktwi
    Feb 11, 2017 at 17:19
  • 2
    mount_nfs: can't mount /Volumes/Aren/Movies from localhost onto /Users/me/Movies: No such file or directory
    – Necktwi
    Feb 11, 2017 at 17:20
  • Its working good If I do it the other way!
    – Necktwi
    Feb 11, 2017 at 17:21
  • If you get "No such file or directory", try making a folder to mount to on the destination first. If you get a "Permission Denied" error, try "sudo nfsd restart" (for me, nfsd was already started, so it needed restarting to pickup the new exports line, I think)
    – Nick
    Oct 3, 2018 at 10:09
  • 1
    @JayGee I am OP. It worked for me at the time, what error does Git have? Have you cded out and then back in before using Git? Shells tend to work with file descriptors which are tied to inodes, not full string paths - so if you mount and stay in the "same" directory, the shell will still operate using the underlying directory instead of the mounted one. There's no reason Git should see anything as mounted - mounting doesn't work like that. For all intents and purposes it's the same type of filesystem. Jul 10, 2019 at 8:26
9

There is another option - bindfs. It requires you to install macFUSE first but provides an alternative to using NFS.

You can compile bindfs from source but it's available in MacPorts, Homebrew and pkgsrc too.

4
  • 4
    Homebrew: Install osxfuse, then brew install homebrew/fuse/bindfs (Tested on El Capitan; no need for sudo before bindfs for user-oriented mounts)
    – dhchdhd
    Mar 5, 2016 at 1:05
  • 1
    Disadvantage of fuse is that it do not support inotify events. If source updated, while App watching for updates in destination, it will not receive updates.
    – diimdeep
    Apr 25, 2018 at 12:18
  • 1
    Also it's a bit wonky for me when compiling things inside a bindfs volume. In particular I consistently get "too many open files" for one particular project in Xcode for no apparent reason. If I just copy the contents without mounting, it builds fine.
    – Grishka
    Dec 12, 2018 at 17:02
  • Nowadays it's called macfuse again. But it's a ton of effort to get running, requires you to disable SIP and is generally a lot of pain (thanks, Mr. Apple).
    – Paul
    Jan 6, 2023 at 18:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .