0

I need to seamlessly mount (and automount, e.g. via fstab) a directory (folder) on one drive to appear at the commandline and GUI level as a directory on another, on the same machine. This is to defeat some "smart" software that detects that symlinks and aliases are not "real" directories and refuses to act on them.

In Linux, this would be trivially easy, with:
mount --bind /path1/source_dir /path2/target_dir
However, Mac OS's version of mount does not support this bind functionality (in any form, including mount -o bind, or mount -B), as far as I can determine. It also appears that none of Macports, Homebrew, or Fink supply a ported version of mount with such an option. Some available more specialized mounting tools don't seem to relate, either (e.g. xmount is for disk images, and djmount is for network volumes).

To be clear, I'm not trying to mount a disk or partition as a volume or as a local directory, nor to create a share to be mounted arbitrarily by various users on various machines. Rather, I want to mount a folder, owned and writable only by a particular user, on an HFS+ disk as if it were a folder on another HFS+ disk, locally, in a way that is effectively transparent, with the same permissions and no security/integrity issues.

A sloppy workaround is to create a CIFS share of the folder to be mounted, and (calling a custom, one-shot variant of smb.conf) limit its permissions in Samba just-so, such that it is not public, and has the same permissions as the target location, exactly the right file and directory mask, etc.; then mount it that way. But this would be inefficient, since it would be using the bletcherous Windows filesharing protocol, plus creating a visible share that shows up as a mountable volume from the SMB server, to anyone who can access this machine though SMB/CIFS (even if they cannot actually mount it). The Mac GUI will probably also represent it as a volume being shared.

  • "...as if it were a folder on another HFS+ disk..." – IconDaemon Jun 12 '16 at 10:59
  • Yes. I don't understand why you're quoting this back to me. – S. McCandlish Nov 22 '18 at 21:04
  • Two and a half years later, I have no idea. – IconDaemon Nov 23 '18 at 2:45
  • Weird, mount problem though, huh? This seems like it should be trivial to resolve. At this point I wonder whether compiling a GNU (or whatever) mount utility from source would even work, since it may be some kind of filesystem-level limitation. – S. McCandlish Nov 23 '18 at 20:21
0

To mount a hard drive on a custom mountpoint:

You can do this with diskutil mount and the -mountPoint option. From the man page:

mount [readOnly] [-mountPoint path] device

Mount a single volume. If readOnly is specified, then the file system is mounted read-only, even if the volume's underlying file system and/or device and/or media supports writing; even the super-user may not write to it; this is the same as the rdonly option to mount (8). If a -mountPoint is specified, then that path, rather than the standard path of /Volumes/VolumeName, will be used as the view into the volume file con- tent; a directory at that path must already exist.

From man diskutil, section 'Verbs'.

The syntax to mount to a custom mountpoint is as follows:

diskutil mount -mountPoint /path/to/custom/mountpoint [volume (identifier/UUID/label)]

Bear in mind that /path/to/custom/mountpoint must be a directory, just like with mount, and that your identifier/UUID/label are specific to the volume (i.e. /dev/diskXsY not /dev/diskX). Mounting to a custom mountpoint cannot be done with diskutil mountDisk, and only works with a single volume at a time.

From my answer to How to mount disk by UUID or LABEL in OS X El Capitan.

I've tested this by "mounting" a USB stick on an external hard drive. As an example,

$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh SSD           499.4 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
/dev/disk1 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *1.0 TB     disk1
   1:                        EFI EFI                     209.7 MB   disk1s1
   2:                  Apple_HFS HDD-1T                  999.8 GB   disk1s2
/dev/disk2 (external, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *31.6 GB    disk2
   1:               Windows_NTFS USB-32                  31.6 GB    disk2s1

As you can see, /dev/disk2s1, or USB-32 is the name of the USB stick I am going to mount on the hard drive, /dev/disk1s2, or HDD-1T. To do so, make use of the -mountPoint option. But first, make sure there is a landing directory to mount onto:

$ mkdir /Volumes/HDD-1T/mountpoint

And now, to mount:

$ diskutil mount -mountPoint /Volumes/HDD-1T/mountpoint /dev/disk1s2

The mounted disk will appear in the following locations: /Volumes, and /Volumes/HDD-1T/mountpoint as USB-32 and mountpoint respectively.

Be sure to unmount (diskutil umount) your USB-32 equivalent before remounting on your HDD-1T equivalent.

  • Yes, I already do that all the time (and those are well-written instructions). However, this doesn't relate to the question: "I need to seamlessly mount ... a directory (folder) on one drive to appear ... as a directory on another, on the same machine." Mounting an actual volume hasn't been any kind of problem. – S. McCandlish Nov 22 '18 at 21:08
  • May I suggest you consider using a disk image? Although it might be cumbersome and definitely not a "real directory", it's pretty close to one and can be mounted as a volume. – perhapsmaybeharry Nov 23 '18 at 3:04
  • Doesn't suit the use case. It's a directory that another app requires to be exactly where it "lives". I basically need two apps to share data, and they both have hard-coded (different) directory locations, and will not accept symlinks or aliases. The only solution I know of is to fake them out with a mount point (i.e., have the filesystem tell them it's a directory). Well, that or do the bletcherous CIFS thing I already mentioned. Or rely on some kind of always-running polling script that copies a changed file from one location to another upon a change, but that would be breakage-prone. – S. McCandlish Nov 23 '18 at 20:16
  • I'm not joking that I really do actually need to create a drive/directory to drive2/directory2 mount. It's completely routine in every other *n*x-based OS, it's just been senselessly disabled in MacOS for no known reason (other than more of Apple's "presume our users are stupid" stuff). :-) – S. McCandlish Nov 23 '18 at 20:16
  • In that case, I'm afraid I can't help you with this. In fact, I would consider this to be more of an issue with the software you are using (hardcoded paths) instead of with MacOS. – perhapsmaybeharry Nov 24 '18 at 9:30

You must log in to answer this question.

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