What Linux bind mounts is really doing

Source: Internet
Author: User

Lots of Unixes has some form of ' loopback ' mounts, where you can mount a bit of a existing filesystem somewhere else; They ' re called loopback mounts by analogy with the loopback interface.

The general idea behind them was that they was a more efficient (and easier to use) version of doing an NFS mount from .

Linux ' s bind mounts (so called because they mount --bind is done with, or by specifying as the bind filesystem Typ e in) look like any other /etc/fstab sort of loopback mounting. However, they actually operate in a-on-the-quite different from the usual idea of loopback mounting, and the Differe NCE has some important consequences.

What bind mounts was really doing is more or less mounting the filesystem again with a different ino The de as the root inode. Thus, if you do:

Mount/dev/md1/foomount--bind/foo/bar/bar

What really are /dev/md1 mounted twice, once with the root inode of the filesystem on MD1 as the Root of the mount point, and once with the inode for ' bar ' in the root of the filesystem on MD1 as the root of the mount Point.

mountThe command makes this hard-to-see by being misleading in its output, reporting things like ' /data/home on /home type none (rw,bind) .

Because they use /etc/mtab , which mount maintains, things like df Also More of the real state of affairs /proc/mounts is visible in, where the kernel itself reports:

/dev/md5/data ext3 rw,data=ordered 0 0/dev/md5/home ext3 rw,data=ordered 0 0

Unfortunately the kernel doesn ' t report which root inode /home is mounted with, which generally makes mount ' s Output more useful once your know what's really going on.

One consequence of this are that once your ' ve set up your bind mounts, you can unmount the original mount point, so Mething which I believe is not true of the things like Solaris's loopback mounts (and which definitely wouldn ' t be true of NFS Mounts from localhost). There might is a use of this in obscure situations.

Sidebar:deeper under the hood

Disclaimer:i am not sure I understand this correctly.

Under the hood, there is, things:actual mounts of filesystems from devices (or the network), and namespace-based view s of such filesystems. Rather than create new copies of both, bind mounts Create new views (' mounts ' or ' vfsmounts ') of the same underlying mount Ed FileSystem.

This explains one limitation of BIND mounts, which are that you can ' t change mount the flags when your do a bind mount (so you c An ' t has a bind mount that was a read-only version of part of a read-write filesystem). Currently, all mount flags is associated with the filesystem, and the with the view, so any views that have the S AME Mount flags.

What Linux bind mounts is really doing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.