An existing directory is needed as a mount point.$ ls$ sudo mount /dev/sdb2 ./datadiskmount: mount point ./datadisk does not exist$ mkdir datadisk$ sudo mount /dev/sdb2 ./datadisk$I find it confusing since it overlays existing contents of the directory. There are two possible contents of the mount point directory which may get switched unexpectedly (for a user who is not performing the mount).Why doesnt mount happen into a newly created directory? This is the way how graphical operating systems display removable media. It would be clear if the directory is mounted (exists) or not mounted (does not exist). I am pretty sure there is a good reason but I havent been able to discover it yet.
Why does mount happen over an existing directory?
mount
This is a case of an implementation detail that has leaked.In a UNIX system, every directory consists of a list of names mapped to inode numbers. An inode holds metadata which tells the system whether it is a file, directory, special device, named pipe, etc. If it is a file or directory it also tells the system where to find the file or directory contents on disk. Most inodes are files or directories. The -i option to ls will list inode numbers.Mounting a filesystem takes a directory inode and sets a flag on the kernel's in-memory copy to say actually, when looking for the contents of this directory look at this other filesystem instead (see slide 10 of this presentation). This is relatively easy as it's changing a single data item.Why doesn't it create a directory entry for you pointing at the new inode instead? There are two ways you could implement that, both of which have disadvantages. One is to physically write a new directory into the filesystem - but that fails if the filesystem is readonly! The other is to add to every directory listing process a list of extra things that aren't really there. This is fiddly and potentially incurs a small performance hit on every file operation.If you want dynamically-created mount points, the automount system can do this. Special non-disk filesystems can also create directories at will, e.g. proc, sys, devfs and so on.Edit: see also the answer to What happens when you 'mount over' an existing folder with contents?