0

mount always requires an existing folder path as destination mounting directory.

But on macOS the /Volumes folder doesn't have most od the mountpoints and they are created at plug/mount time.

What makes this possible?

I put an entry in /etc/fstab (sudo vifs) but I'd like the specified non-existing mount folder to be created at mount, and be removed after the umount; the same way it usually happens with all the automatically mounted volumes on macOS.

1 Answer 1

1

Technically you can only mount a volume on an existing folder. The trick that nevertheless makes this possible for macOS in general is that a program makes sure to create the folder before performing the mount.

This kind of functionality is generally known (across operating systems) as an "auto mounter". And indeed macOS contains a program named automount that automatically creates folders and mounts according to the map setup in /etc/auto_master. This is mainly used with certain types of network shares.

The main automounter that most users will interact with is named diskarbitrationd. This program listens for events such as USB drives being connected, DVDs inserted, etc. and mounts any mountable file system on them.

diskarbitrationd uses information in /etc/fstab to determine any special options or mount point configuration that the user has set for a specific drive. Those mount points needs to exist in advance however, and they won't automatically be deleted after the file system is unmounted.

If you just want to chose a different folder name within /Volumes, you can simply open Disk Utility and right-click on the volume to choose "Rename". The next time you insert the drive, it will be mounted in a folder with that name.

If you want to do something completely different than the manual behavior, you could disable diskarbitrationd entirely, and create your own program for mounting drives automaticallly. Note however that it is a lot of work for something that sounds like it could be solved in a better wa.y

Finally a work around could be that you create a program (i.e. a small script) that is run whenever something is mounted. When your special drive is mounted, it could automatically unmount it, create the custom mount point and mount it there. You would need special handling to also delete the folder when the disk is unmounted again. If you can create small scripts, the trick to getting this working is to create a launchd daemon definition file for the script, and use the StartOnMount key. This makes launchd run your script every time something is mounted.

5
  • Actually.. the purpose for creating/deleting the mountpoint was exactly to trigger an Automator Folder-Action that I've written. — The FolderAction listens for changes inside the mountpoint's parent folder; but unfortunately the FolderAction doesn't trigger when something is mounted on the watched folder (it would trigger just if mountpoint didn't exist). Commented Apr 10, 2020 at 19:28
  • I assume Automator isn't able to listen for mounted folders then. Maybe using the StartOnMount key from launchd, as you suggested, is the way to go; even if I hoped to have just an easy-to install Automator workflow without dealing with (not installable) *.plist files. Commented Apr 10, 2020 at 19:32
  • You should probably have asked that question instead then - you can still open a new question with that! I’m not really sure what the problem is though. If you just set a FolderAction on /Volumes - that should do it. When you plug in the drive, a folder is automatically created in /Volumes, and your action should run?
    – jksoegaard
    Commented Apr 10, 2020 at 20:31
  • I am not mounting to the default /Volume but to another folder; to do that I add a mount entry into /etc/fstab. But as mentioned this has the problem that the entry must specify a mount point, so the FolderAction watching it won't be trigger. Commented Apr 10, 2020 at 20:41
  • Here more my other question, for more context: apple.stackexchange.com/questions/387565/… Commented Apr 10, 2020 at 20:42

You must log in to answer this question.

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