10

I feel confused about mount options such as: --bind, --make-unbindable and --make-shared and could you please help me explain the below commands?

sudo "mount --bind #{vm_bind_mount} #{vm_bind_mount}"
sudo "mount --make-unbindable #{vm_bind_mount}"
sudo "mount --make-shared #{vm_bind_mount}"

EDIT: In fact, I wonder why there are duplicate #{vm_bind_mount} in mount --bind? In other words, does mount --bind /tmp/foo /tmp/foo make sense?

2 Answers 2

12

mount --bind replicates a mount at another location. For example, after

mount --bind /foo /bar

then /foo/something and /bar/something are the same file (accessed through different paths). You can use mount --bind to replicate a subtree: /foo doesn't have to be a mount point.

An example where this is useful is to make parts of the directory tree available under a chroot. For example, if you run a web server chrooted in /srv, but you want to serve files under /home/bob, then you can replicate (part of) Bob's home directory under the server root:

mount --bind /home/bob/public_html /srv/home/bob

The options --make-private, --make-shared, --make-slave and --make-unbindable provide some control over bind mounts and over what happens if you mount another filesystem under /foo or /bar after doing mount --bind /foo /bar.

  • By default, all mounts are private: if you mount a filesystem under /foo or /bar, this doesn't affect what is visible through the other path.
  • If /foo has been declared shared before doing mount --bind, then if you later mount something either under /foo or /bar, it's visible through the other path as well.
  • A slave mount is shared only in one direction: if /foo is shared and /bar is slave, then mounting something under /bar affects the view under /foo but the converse is not true.
  • If /foo is declared unbindable, then mount --bind /foo /bar will fail.
6
  • Does mount --bind /tmp/foo /tmp/foo make sense? Mar 3, 2014 at 2:48
  • 1
    @user2886717 Not really. It's an edge case. It can be observable (unless shared), but it would be confusing. Mar 3, 2014 at 2:56
  • Could you please explain the commands chain of my question in your answer? In my question, the arguments of option --bind are the same. Mar 3, 2014 at 6:26
  • 1
    systemdchanged the default so that now "by default, all mounts are shared".
    – Totor
    Sep 12, 2016 at 18:47
  • 1
    @user2886717, "Does mount --bind /tmp/foo /tmp/foo make sense?" does make sense indeed. It turns this dir into a mount-point. Sometimes it matters.
    – poige
    Sep 10, 2019 at 9:08
4

From the mount(8) manpage:

Since Linux 2.6.15 it is possible to mark a mount and its submounts as shared, private, slave or unbindable. A shared mount provides ability to create mirrors of that mount such that mounts and umounts within any of the mirrors propagate to the other mirror. A slave mount receives propagation from its master, but any not vice-versa. A private mount carries no propagation abilities. A unbindable mount is a private mount which cannot cloned through a bind operation. Detailed semantics is documented in Documentation/sharedsubtree.txt file in the kernel source tree.

The text file referred to is actually Documentation/filesystems/sharedsubtree.txt; here's a link to that file in the current stable kernel.

1
  • thank you for your answer and I have looked up the documentation. However, I still feel confused about mount --bind /cdrom /cdrom mount --make-shared /cdrom What does duplicated /cdrom mean? Mar 2, 2014 at 5:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .