博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What Linux bind mounts are really doing
阅读量:5327 次
发布时间:2019-06-14

本文共 2684 字,大约阅读时间需要 8 分钟。

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 /foomount --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:

ext3 rw,data=ordered 0 0 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.

转载于:https://www.cnblogs.com/linuxbo/p/4303552.html

你可能感兴趣的文章
PHP再学习5——RESTFul框架 远程控制LED
查看>>
FL2440-学习记录(三)
查看>>
Amobea读写分离
查看>>
关于密码
查看>>
oracle创建表空间
查看>>
Keycloak服务器安装和配置
查看>>
C#委托之个人理解(转)
查看>>
retrofit2 上传图片
查看>>
Linux Shell流程例子
查看>>
jQuery的三种$()
查看>>
2017.6.4 入门组 NO.4——猜数
查看>>
Eclipse 下载安装
查看>>
WebSocket 时时双向数据,前后端(聊天室)
查看>>
关于cocoa 运行时runtime
查看>>
关于python中带下划线的变量和函数 的意义
查看>>
asp.net 写入excel时,不能更新。数据库或对象为只读。
查看>>
题1简化版
查看>>
linux清空日志文件内容 (转)
查看>>
jsp中对jstl一些标签的引用方式
查看>>
100. Same Tree
查看>>