Can we just use symbolic link instead of 'mount --bind'?

Recently I came to know about the mount --bind command but there is something that I can't understand clearly. Suppose I have a disk partition and I mounted it to a mount point /bkup using this command.

sudo mount /dev/sdd1 /bkup

If I want to make that /home/bkup directory appear as ~/bkup, I could do

sudo mount --bind /bkup ~/bkup

But how is it different from

ln -s /bkup ~/bkup

in effect? Why should I use mount --bind when I can do the same thing with ln -s command?


Solution 1:

mount --bind is more like an equivalent of a "hard link" to a directory (well, you cannot create hard links to directories, but this is closest you can get), while symbolic link is... well, a symbolic link.

Myself I found two cases where the difference may be important:

  1. running some service in a chroot. Symbolic links from inside a chroot jail to outside of a chroot jail don't work, while mount --bind works.

  2. sharing some directory over a network. You cannot share a symbolic link, but you can share directory mounted over mount --bind.

You must also be very careful with programs that by design distinguish between symbolic links and actual directories, like rsync. Trying to run rsync on a symbolic link to a directory may give you completely other results than you expect.