12

Why do you have to create a directory before you can mount a share to it?

Eg: I've never understood why mkdir is needed here:

mkdir /Volumes/foo
mount -t afp afp://username:[email protected]/foo /Volumes/foo

5 Answers 5

3

On unix and unix like systems which includes Mac OS X filesystems are laid out logically very different to how they are on Windows. There is no such thing as a drive like C or D etc. There is just a single filesystem which is laid out as a hierarchy (tree structure). This filesystem can be made up of one physical drive or a number of physical drives in a machine. It can also be made up of memory and shares from another machine via protocols like NFS, CIFS etc. Because there is no drives per se you need to have somewhere on the filesystem that you can attach or mount this additional storage to so you create a directory and then mount the other filesystem there.

Linux systems for instance have either a /mnt directory or a /mnt hierarchy with directories like cdrom etc. in it. In this case you do not need to make a directory first you can use one of these but you are not required to as the mount point can be anywhere on the filesystem. This benefit can be really useful if you need more space soemwhere as you can add another drive, move the data onto it and then mount it where the old directory was and everything will keep working without any change.

2
  • Thanks for spotting that one. Missed it when I checked the message. Post correct. May 21, 2009 at 20:30
  • allright, killed my comment :)
    – lImbus
    May 22, 2009 at 13:06
5

Because nobody submitted a patch to add the --create-dir option to mount yet? :)

2
  • I am very certain that NEXTSTEP's behavior was as your --create-dir option would be. I have spent the last hour searching the internet for evidence either way but alas without success! Oct 16, 2014 at 19:26
  • The second patch would be "When unmounting or shutting down remove the directory automatically" May 10, 2018 at 1:30
5

It's because when you mount a directory, you're saying to your system, "Act as though the files at <network share> are really at <local folder>." If the system doesn't have that local folder, it can't place those network files there.

2

most disturbing is IMHO that creating a link somewhere does NOT need to touch/mkdir, and a mount (even if -bind locally) needs.

But it probably goes in the same section as "why are hard-links the default when everybody only needs symlinks and has to ln -s.

2

The directory entry needs to be created in /volumes (in this particular example) before the kernel can hook into the directory path.

3
  • 1
    Technically that's incorrect. You can mount a filesystem at any place in your hierarchy - it's standard practice to mount it in /Volumes/ (and is auto done by the OS) but there are times when mounting it somewhere specific makes sense.
    – Chealion
    May 20, 2009 at 18:23
  • Oh, I only meant /volumes in this specific case. :) Not in general.
    – MikeyB
    May 20, 2009 at 18:51
  • That makes more sense. :-)
    – Chealion
    May 20, 2009 at 19:00

You must log in to answer this question.

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