23

Is it possible to mount a local directory into another one? Using Perforce, I want to do something equivalent to symlinking a directory, but in a way that fools it into thinking it's really just another directory in the project.

I would like to do something like:

mount /foo/bar /home/foo/bar

Is this possible, and if so what options do I need to give it?

Cajunluke
  • 3,103
  • 28
  • 28

5 Answers5

8

bindfs seems like what you're after...

Stobor
  • 44,246
  • 6
  • 66
  • 69
  • 4
    This is old, but for the sake of posterity, thought I'd add that I've had problems with data corruption with bindfs. And performance issues. – smparkes Dec 11 '10 at 21:50
  • 3
    (Dang sorry for the added comment; I accidentally hit return which committed the comment and then waited more than five minutes to update it. Sigh). Anyway, wanted to note that as mentioned below, HFS+ supports hard-links between directories (with limitations) and while the native ln command won't do it, the gnu link command (in macports as well as elsewhere) will. – smparkes Dec 11 '10 at 21:58
  • Thanks smparkes, I'm not a mac user, so it's good to have more authoritative feedback. – Stobor Dec 12 '10 at 22:28
  • 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 '18 at 12:17
  • I can't get bindfs to work with MacOS Catalina (https://github.com/mpartel/bindfs/issues/83) – Thomas Mar 22 '20 at 14:06
  • @Thomas works fine for me using macOS 10.15.3, though I note you have to use absolute paths when mounting. I installed via the homebrew cask. Performance issues make it unusable in practice though, long delays just doing `ls` from the terminal: --multithreaded helps with that but any directory searching inside is also impractically slow. Even nfs performs far better. – David Nugent Mar 23 '20 at 03:34
  • @DavidNugent, I will try with absolute paths; thanks – Thomas Mar 24 '20 at 13:44
5
mount localhost:/path1 /path2

will use NFS.

There is a lot of things that may go wrong with NFS, it would be insane to handle them in this answer, better ask on apple.stackexchange.com and read man mount_nfs(8).

Community
  • 1
  • 1
ignis
  • 8,692
  • 2
  • 23
  • 20
  • Getting "Connection refused", any idea how to fix this? – Norswap May 15 '14 at 13:43
  • @Norswap Please open your question on apple.stackexchange.com aka [Ask Different](http://apple.stackexchange.com/) – ignis May 15 '14 at 14:48
  • 2
    @Norswap I know this is a bit old, but this works. I went ahead and investigated, and [posted my findings here](http://apple.stackexchange.com/questions/197029/how-do-you-mount-bind-a-local-directory/197030#197030). NFS is the answer; just a matter of a little configuration. – Qix - MONICA WAS MISTREATED Jul 22 '15 at 21:55
3

You can only mount different filesystems under the directory tree. You may be able to achieve what you're looking to do by hard linking the directories. OS X allows hard linking directories and to perforce it would like like different directories

ennuikiller
  • 46,381
  • 14
  • 112
  • 137
  • 4
    It should be noted this won't work anymore in APFS, which is currently the default filesystem. Since macOS Mojave, all drives are upgraded to APFS. Only HFS+ supports hard link. – Bernardo Ferrari Aug 25 '19 at 17:27
2

The BSD (and thus Darwin/OSX) method of achieving this is nullfs. It's not in a standard build of OS X, but perhaps it's possible to build from source if you have the time to play around with it.

Cajunluke
  • 3,103
  • 28
  • 28
Dan Walters
  • 527
  • 4
  • 6
-6

To make a hard link from one directory to another, run:

$ ln /foo/bar /home/foo/bar

It is important to note that from the OS's perspective, both links are treated equally. You can delete /foo/bar and /home/foo/bar will remain a valid reference to the data on disk.

David
  • 1,101
  • 2
  • 9
  • 11
  • 1
    Hardlinking directories is evil!!! (Unless you're very careful...) – Stobor Jul 04 '09 at 04:54
  • 11
    you can _not_ hardlink directories in OSX via 'ln' –  Jul 04 '09 at 05:20
  • Whoops. Shame on me for not actually running the command. Point taken. – David Jul 04 '09 at 17:17
  • Time Machine actually uses hard links to directories, so it must somehow be possible. – Michael Kuhn Jul 06 '09 at 12:07
  • 2
    It can be done, but you have to write code to do it... Some example code (as well as the conditions placed on directory hard links) is about halfway down on this page: http://www.osxbook.com/blog/2008/11/09/hfsdebug-40-and-new-hfs-features/ (search for the word "experimentation") – Stobor Jul 07 '09 at 03:04