Are there any drawbacks from using mount --bind as a substitute for symbolic links?

With mount --bind, a directory tree exists in two (or more) places in the directory hierarchy. This can cause a number of problems. Backups and other file copies will pick all copies. It becomes difficult to specify that you want to copy a filesystem: you'll end up copying the bind-mounted files twice. Searches with find, grep -r, locate, etc., will traverse all the copies, and so on.

You will not gain any “increased functionality and compatibility” with bind mounts. They look like any other directory, which most of the time is not desirable behavior. For example, Samba exposes symbolic links as directories by default; there is nothing to gain with using a bind mount. On the other hand, bind mounts can be useful to expose directory hierarchies over NFS.

You won't have any performance issues with bind mounts. What you'll have is administration headaches. Bind mounts have their uses, such as making a directory tree accessible from a chroot, or exposing a directory hidden by a mount point (this is usually a transient use while a directory structure is being remodeled). Don't use them if you don't have a need.

Only root can manipulate bind mounts. They can't be moved by ordinary means; they lock their location and the ancestor directories.

Generally speaking, if you pass a symbolic link to a command, the command acts on the link itself if it operates on files, and on the target of the link if it operates on file contents. This goes for directories too. This is usually the right thing. Some commands have options to treat symbolic links differently, for example ls -L, cp -d, rsync -l. Whatever you're trying to do, it's far more likely that symlinks are the right tool, than bind mounts being the right tool.


In addition to what @Gilles wrote earlier, it's worth noting that some utilities might consider a bind-mounted directory to be a separate file system. This may have performance or functionality implications if the program can no longer assume that the same inode number refers to the same file (which it doesn't, if they are on different file systems), a move cannot be optimized as link-at-target-then-unlink-source, etc.


You should also want to use bind mounts instead of symlinks when you are relying on a support that might not always be in place (for example an external disk) and you want to be sure that the original directory structure is in place even if the support fails or is removed.

For example if I want to keep /var/tmp in an sd card I will use the bind mount, since some programs will expect /var/tmp to be a valid directory even if the card is removed.

Tags:

Symlink

Mount