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

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

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

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

mount /dev/md1 /foo
mount --bind /foo/bar /bar

what you really have is /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.

The mount 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 report like this. More of the real state of affairs is visible in /proc/mounts, 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 that what root inode /home is mounted with, which generally makes mount's output more useful once you know what is really going on.

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

Sidebar: Deeper under the hood

Disclaimer: I am not sure I understand this correctly.

Under the hood, there are two things: actual mounts of filesystems from devices (or the network), and namespace-based views of such filesystems. Rather than create new copies of both, bind mounts create new views ('mounts' or 'vfsmounts') of the same underlying mounted filesystem.

This explains one limitation of bind mounts, which is that you can't change mount flags when you do a bind mount (so you can't have a bind mount that is a read-only version of part of a read-write filesystem). Currently, all mount flags are associated with the filesystem, not with the view, so all views have to have the same mount flags.

What Linux bind mounts are really doing的更多相关文章

  1. docker从零开始 存储(三)bind mounts

    使用bind mounts 自Docker早期以来bind mounts 一直存在.与volumes相比,绑定挂载具有有限的功能.使用bind mounts时,主机上的文件或目录将装入容器中.文件或目 ...

  2. Docker 基础知识 - 使用绑定挂载(bind mounts)管理应用程序数据

    绑定挂载(bind mounts)在 Docker 的早期就已经出现了.与卷相比,绑定挂载的功能有限.当您使用绑定挂载时,主机上的文件或目录将挂载到容器中.文件或目录由其在主机上的完整或相对路径引用. ...

  3. docker 应用数据的管理之bind mounts

    创建容器使用bind mounts 挂载文件系统.宿主机文件系统会覆盖掉容器里初始数据 [root@localhost ~]# mkdir /www/htpm -pv mkdir: 已创建目录 &qu ...

  4. Bind Mounts and File System Mount Order

         When you use the bind option of the mount command, you must be sure that the file systems are m ...

  5. `docker数据持久化volume和bind mounts两种方式

    将数据从宿主机到容器的三种方式: ,volumes:docker管理宿主机文件系统的一部分(/var/lib/docker/volumes)保存数据的最佳方式 ,bind mounts 将宿主机上的任 ...

  6. Linux就这个范儿 第10章 生死与共的兄弟

    Linux就这个范儿 第10章 生死与共的兄弟 就说Linux系统的开机.必须经过加载BIOS.读取MBR.Boot Loader.加载内核.启动init进程并确定运行等级.执行初始化脚本.启动内核模 ...

  7. linux namespace note

    --------------------------------- from http://oldwiki.linux-vserver.org/Namespaces //开源不只是代码,还有思想 Na ...

  8. [转帖]Docker的数据管理(volume/bind mount/tmpfs)

    Docker(十五)-Docker的数据管理(volume/bind mount/tmpfs) https://www.cnblogs.com/zhuochong/p/10069719.html do ...

  9. Linux mount 命令进阶

    笔者在<Linux mount 命令>一文中介绍了 mount 命令的基本用法,本文我们接着介绍 mount 命令的一些高级用法,比如 bind mounts(绑定挂载)和 shared ...

随机推荐

  1. iOS-UIScrollView+UIPageControl简单实现

    #import "MJViewController.h"#import "RootViewController.h" @interface MJViewCont ...

  2. Docker从入门到动手实践

    一些理论知识,我这里就不累赘了 docker 入门资料,参考:https://yeasy.gitbooks.io/docker_practice/content/ Dockerfile常用命令,图片来 ...

  3. Win 10环境下6sV2.1模型编译心得

    最新版本6sV2.1模型是通过FORTRAN95编写的,2017年11月代码编写完成,2018年11月发布在模型官网上.通常我们在使用过程中都是调用模型的.exe可执行文件,而下载下来的是FORTRA ...

  4. java基础系列(一):Number,Character和String类及操作

    这篇文章总结了Java中最基础的类以及常用的方法,主要有:Number,Character,String. 1.Number类 在实际开发的过程中,常常会用到需要使用对象而不是内置的数据类型的情形.所 ...

  5. vue时间戳转换(10位数)/(13位)

    <template> <!-- time为时间戳 --> <div>{{time | formatDate}}</div> <!-- 结果为 20 ...

  6. 【谷歌浏览器】修改和添加Cookie

    一.使用谷歌浏览器 1.1.修改ookie 方法一:直接用开发者工具修改: 操作如图:   参考: 检查和删除 Cookie · Chrome 开发者工具中文文档 http://www.css88.c ...

  7. python中文编码 - python基础入门(5)

    python到目前为止,一共有两个版本,分别是2.x和3.x版本,根据官方正式通知2020年停止对python更新和维护,距离今天还有110天左右,所以正在学习python的小伙伴应该暗中庆幸一波. ...

  8. 我叫Tomcat:一款web服务器

    我叫Tomcat:一款web服务器 如何将我们的 Java 代码,运行在网络上,初学时,首先接触到的一般都是Servlet以及Jsp(或略过Jsp)而 Tomcat 就是这两者的容器,帮你处理动态网页 ...

  9. SQL-锁-事物级别

    一.锁 锁是一种安全机制,控制并发操作,防止用户读取其他用户正在更改的数据,或者多用户同时修改一个数据,从而保证事物的完整性和数据库的一致性.SQLserver 会自动强制执行锁,但是用户可以通过对锁 ...

  10. java源码 -- HashSet

    概述 HashSet是基于HashMap来实现的, 底层采用HashMap的key来保存数据, 借此实现元素不重复, 因此HashSet的实现比较简单, 基本上的都是直接调用底层HashMap的相关方 ...