Ln -s vs mount –bind

fstabmountpartitionsymbolic-link

Is there any practical difference between using ln -s or mount --bind?

I want to move some folders to another partition, without changing their daemon setting, and wonder what approach I should take.

I prefer ln -s as it requires minimum setup (no /etc/fstab modifications), but perhaps there is a reason why it's not common?

Best Answer

Hell yes. If you execute the ln -s you create a symbolic link, which is an inode pointing to a certain filesystem object, which is why symlinks can traverse filesystems and hard links cannot: hard links do not have their own inode.

If you mount a filesystem with --bind, you create a second mountpoint for a device or filesystem.

If you envision a symlink as a redirect, then envision a --bind mounted filesystem as creating another gateway to data.

Symlinks and bind mounts are a whole different ballgame.

The --bind mount seems a bit more robust to me and it probably is a bit faster than working with a symlink. On the other hand, there are no serious drawbacks to using the symlink, as the performance hit will be small (if it at all exists).

Edit: I've been thinking about this, and the performance hit might be a bit bigger than I originally thought. If you have an application that reads a lot of different files, then every new file that is opened will require an extra read. Some research here suggests that my assumption is correct, so if you have an IO heavy application running there, consider the --bind option to mount above the symlink solution.

The reason it is not common, is probably the fact that a symlink is visible in an ls, whereas a bind mount is only visible when looking at /proc/mounts or /etc/mtab (which is what the mount command does, if it is executed without parameters). Other than that, I don't think there are any issues. I'd be interested if there are, though.

Addition: another issue with ln -s is that for some applications, when the path gets dereferenced, it may cause the application to balk if it "expects" certain items to be in specific places.