原文:https://www.kernel.org/doc/Documentation/filesystems/overlayfs.txt

Written by: Neil Brown
Please see MAINTAINERS file for where to send questions.Overlay Filesystem
==================This document describes a prototype for a new approach to providing
overlay-filesystem functionality in Linux (sometimes referred to as
union-filesystems).  An overlay-filesystem tries to present a
filesystem which is the result over overlaying one filesystem on top
of the other.The result will inevitably fail to look exactly like a normal
filesystem for various technical reasons.  The expectation is that
many use cases will be able to ignore these differences.This approach is 'hybrid' because the objects that appear in the
filesystem do not all appear to belong to that filesystem.  In many
cases an object accessed in the union will be indistinguishable
from accessing the corresponding object from the original filesystem.
This is most obvious from the 'st_dev' field returned by stat(2).While directories will report an st_dev from the overlay-filesystem,
all non-directory objects will report an st_dev from the lower or
upper filesystem that is providing the object.  Similarly st_ino will
only be unique when combined with st_dev, and both of these can change
over the lifetime of a non-directory object.  Many applications and
tools ignore these values and will not be affected.Upper and Lower
---------------An overlay filesystem combines two filesystems - an 'upper' filesystem
and a 'lower' filesystem.  When a name exists in both filesystems, the
object in the 'upper' filesystem is visible while the object in the
'lower' filesystem is either hidden or, in the case of directories,
merged with the 'upper' object.It would be more correct to refer to an upper and lower 'directory
tree' rather than 'filesystem' as it is quite possible for both
directory trees to be in the same filesystem and there is no
requirement that the root of a filesystem be given for either upper or
lower.The lower filesystem can be any filesystem supported by Linux and does
not need to be writable.  The lower filesystem can even be another
overlayfs.  The upper filesystem will normally be writable and if it
is it must support the creation of trusted.* extended attributes, and
must provide valid d_type in readdir responses, so NFS is not suitable.A read-only overlay of two read-only filesystems may use any
filesystem type.Directories
-----------Overlaying mainly involves directories.  If a given name appears in both
upper and lower filesystems and refers to a non-directory in either,
then the lower object is hidden - the name refers only to the upper
object.Where both upper and lower objects are directories, a merged directory
is formed.At mount time, the two directories given as mount options "lowerdir" and
"upperdir" are combined into a merged directory:mount -t overlay overlay -olowerdir=/lower,upperdir=/upper,\
workdir=/work /mergedThe "workdir" needs to be an empty directory on the same filesystem
as upperdir.Then whenever a lookup is requested in such a merged directory, the
lookup is performed in each actual directory and the combined result
is cached in the dentry belonging to the overlay filesystem.  If both
actual lookups find directories, both are stored and a merged
directory is created, otherwise only one is stored: the upper if it
exists, else the lower.Only the lists of names from directories are merged.  Other content
such as metadata and extended attributes are reported for the upper
directory only.  These attributes of the lower directory are hidden.whiteouts and opaque directories
--------------------------------In order to support rm and rmdir without changing the lower
filesystem, an overlay filesystem needs to record in the upper filesystem
that files have been removed.  This is done using whiteouts and opaque
directories (non-directories are always opaque).A whiteout is created as a character device with 0/0 device number.
When a whiteout is found in the upper level of a merged directory, any
matching name in the lower level is ignored, and the whiteout itself
is also hidden.A directory is made opaque by setting the xattr "trusted.overlay.opaque"
to "y".  Where the upper filesystem contains an opaque directory, any
directory in the lower filesystem with the same name is ignored.readdir
-------When a 'readdir' request is made on a merged directory, the upper and
lower directories are each read and the name lists merged in the
obvious way (upper is read first, then lower - entries that already
exist are not re-added).  This merged name list is cached in the
'struct file' and so remains as long as the file is kept open.  If the
directory is opened and read by two processes at the same time, they
will each have separate caches.  A seekdir to the start of the
directory (offset 0) followed by a readdir will cause the cache to be
discarded and rebuilt.This means that changes to the merged directory do not appear while a
directory is being read.  This is unlikely to be noticed by many
programs.seek offsets are assigned sequentially when the directories are read.
Thus if- read part of a directory- remember an offset, and close the directory- re-open the directory some time later- seek to the remembered offsetthere may be little correlation between the old and new locations in
the list of filenames, particularly if anything has changed in the
directory.Readdir on directories that are not merged is simply handled by the
underlying directory (upper or lower).Non-directories
---------------Objects that are not directories (files, symlinks, device-special
files etc.) are presented either from the upper or lower filesystem as
appropriate.  When a file in the lower filesystem is accessed in a way
the requires write-access, such as opening for write access, changing
some metadata etc., the file is first copied from the lower filesystem
to the upper filesystem (copy_up).  Note that creating a hard-link
also requires copy_up, though of course creation of a symlink does
not.The copy_up may turn out to be unnecessary, for example if the file is
opened for read-write but the data is not modified.The copy_up process first makes sure that the containing directory
exists in the upper filesystem - creating it and any parents as
necessary.  It then creates the object with the same metadata (owner,
mode, mtime, symlink-target etc.) and then if the object is a file, the
data is copied from the lower to the upper filesystem.  Finally any
extended attributes are copied up.Once the copy_up is complete, the overlay filesystem simply
provides direct access to the newly created file in the upper
filesystem - future operations on the file are barely noticed by the
overlay filesystem (though an operation on the name of the file such as
rename or unlink will of course be noticed and handled).Multiple lower layers
---------------------Multiple lower layers can now be given using the the colon (":") as a
separator character between the directory names.  For example:mount -t overlay overlay -olowerdir=/lower1:/lower2:/lower3 /mergedAs the example shows, "upperdir=" and "workdir=" may be omitted.  In
that case the overlay will be read-only.The specified lower directories will be stacked beginning from the
rightmost one and going left.  In the above example lower1 will be the
top, lower2 the middle and lower3 the bottom layer.Non-standard behavior
---------------------The copy_up operation essentially creates a new, identical file and
moves it over to the old name.  The new file may be on a different
filesystem, so both st_dev and st_ino of the file may change.Any open files referring to this inode will access the old data and
metadata.  Similarly any file locks obtained before copy_up will not
apply to the copied up file.On a file opened with O_RDONLY fchmod(2), fchown(2), futimesat(2) and
fsetxattr(2) will fail with EROFS.If a file with multiple hard links is copied up, then this will
"break" the link.  Changes will not be propagated to other names
referring to the same inode.Symlinks in /proc/PID/ and /proc/PID/fd which point to a non-directory
object in overlayfs will not contain valid absolute paths, only
relative paths leading up to the filesystem's root.  This will be
fixed in the future.Some operations are not atomic, for example a crash during copy_up or
rename will leave the filesystem in an inconsistent state.  This will
be addressed in the future.Changes to underlying filesystems
---------------------------------Offline changes, when the overlay is not mounted, are allowed to either
the upper or the lower trees.Changes to the underlying filesystems while part of a mounted overlay
filesystem are not allowed.  If the underlying filesystem is changed,
the behavior of the overlay is undefined, though it will not result in
a crash or deadlock.Testsuite
---------There's testsuite developed by David Howells at:git://git.infradead.org/users/dhowells/unionmount-testsuite.gitRun as root:# cd unionmount-testsuite# ./run --ov

overlay filesystem相关推荐

  1. docker容器虚拟化技术_Docker,虚拟机和容器的全面介绍

    docker容器虚拟化技术 by shota jolbordi 通过Shota Jolbordi Docker has been a buzzword for tech people for the ...

  2. Google和Facebook为什么不用Docker?

    点击关注公众号,Java干货及时送达 写作本文的起因是我想让修改后的分布式 PyTorch 程序能更快的在 Facebook 的集群上启动.探索过程很有趣,也展示了工业机器学习需要的知识体系. 200 ...

  3. 你猜,为什么Google和Facebook不用Docker?

    前言 本文涉及的所有技术细节都在开源软件和论文中. 写本文的起因是我想让分布式 PyTorch 程序更快的在 Facebook 的集群上启动.探索过程很有趣.也展示了工业机器学习需要的知识体系. 20 ...

  4. SigmaStar SSD202 openwrt 系统下ubi根文件系统挂载过程

    关于UBI介绍可以参考官方文档 http://www.linux-mtd.infradead.org/doc/ubifs.html 下面是一张简介图,大概的介绍就是UBIFS依赖kernel UBI子 ...

  5. Docker映像存储在哪里? Docker容器路径介绍

    Docker has been widely adopted and is used to run and scale applications in production. Additionally ...

  6. 嵌入式linux只读保护,如何使用squashfs只读文件系统制作Linux系统文件

    在使用嵌入式Linux 系统的时,会出现由于设备意外断电引起文件系统损坏而最终使该设备无法启动的现象.为了应对这种情况,通常会从硬件设计如采用备用电源,无论是锂电池还是超级电容等,或者从系统软件设上加 ...

  7. Docker学习总结(55)——Google和Facebook为什么不用Docker?

    2007 年我刚毕业后在 Google 工作过三年.当时觉得分布式操作系统 Borg 真好用. 从 2010 年离开 Google 之后就一直盼着它开源,直到 Kubernetes 的出现. Kube ...

  8. cloud-utils

    cloud-utils 官方下载:https://launchpad.net/cloud-utils rpm包下载地址:http://rpmfind.net/linux/rpm2html/search ...

  9. Linux 3.10内核锁瓶颈描述以及解决-overlayfs的性能缺陷

    又是一个假期,早早早退,然而高速公路离家最近的出口封闭,无奈只能穿越景区,就为了去吃顿饭.饭罢了,该思考和总结了. 大量线程争抢锁导致CPU自旋乃至内核hang住的例子层出不穷. 我曾经解过很多关于这 ...

最新文章

  1. Visual C# .NET 2003 语言的改变
  2. LeetCode-106-Construct Binary Tree from Inorder and Postorder Traversal
  3. 梭子鱼智能安全透视平台揭穿精密伪装威胁
  4. 机器学习第二篇:详解KNN算法
  5. java 共享锁 独占锁_java中的公平锁、非公平锁、可重入锁、递归锁、自旋锁、独占锁和共享锁...
  6. 软件手游app介绍推广页html
  7. 7-227 寻找大富翁 (25 分)
  8. Oracle的 MODEL 查询
  9. HDU1290 重建希望小学【递推+打表】
  10. Handler机制使用时候一些问题记录
  11. 微信小程序 云函数 Date时间不对+8小时 设置北京时间
  12. 第七章软件项目资源管理
  13. easypr4android,EasyPR的基本使用
  14. vm8.0下安装mac
  15. 微信支付商户平台,企业付款,企业向个人付款接口总结
  16. 网络编程学习笔记之TCP_01(帅帅老师讲堂)
  17. 多副本和raid技术
  18. 如何去除 Win11 Dev 通道版本的右下角水印
  19. 经纬财富:新乡怎么炒白银能挣到钱?
  20. CET eve 看星星

热门文章

  1. 3B+树梅派SD卡安装Ubuntu系统
  2. Mapper 文件中SQL不等于的写法
  3. 腾讯 优图实验室 日常实习面经
  4. Java后端接口开发详细教程
  5. 如何抢救恢复 rm -rf 误删除的文件?
  6. NoC(Network on Chip)基础 (6):Oblivious Routing 和 Adaptive Routing
  7. asus rt-ac68u b1在电信天翼网关下用一个千兆口实现拨号和IPTV桥接
  8. URLDecoder和URLEncoder的使用
  9. 【Redis】主从、哨兵、集群各自架构的优点和缺点对比
  10. 编写一收款程序,计算购买某物品的总金额,该物品单价为5元/公斤,购买5公斤以上打9折,购买10公斤以上打8折,购买20公斤以上打7折,购买 50公斤以上打6折,购买100公斤以上打5折