2

This is similar like How do I do a bind mount over a symlink?

But here the question is how to do a mount --bind from a symlink?

I have /linux-4.13.0 and a symlink linux pointing to that: /linux -> /linux-4.13.0

No I like to do a mount --bind /linux /current but that actually mounts the target /linux-4.13.0 and not the symlink. That means changing the symlink later doesn't have any effect on the mount anymore. Is there any way to change that?

migrated from serverfault.com Oct 1 '17 at 12:57

This question came from our site for system and network administrators.

4

Unfortunately, what you want can't be done due to the fundamental principles of mounts.

Calling "mount A B" takes the directory "A" and attaches it into the in-kernel directory hierarchy in place of "B". In the common case where "A" is a block device containing a filesystem, the root directory of this FS is attached at "B". Bind mounts just simply grab the "A" directory. (Move mounts are essentially the same as bind mounts, they just additionally detach "A" from its original place.)

So whatever paths you supply as "A" and "B" are first resolved by walking all symlinks and relative components to get the two actual directories. The kernel simply does not have the original paths anymore. (That's also why some systems use a file - /etc/mtab - to remember what exactly was the "mount" command called with.)

All of this also applies when mounting a non-directory (like a regular file) onto another non-directory. You just cannot mount a directory onto a non-directory or vice versa.

  • This answer is not entirely correct. You can bind mount regular files and device inodes as well. It does not have to be directories. – kasperd Oct 1 '17 at 13:08
  • Good catch. I was trying hard to avoid going into too much detail on kernel internals and I oversimplified things a bit. – TooTea Mar 22 '18 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy