> For the complete documentation index, see [llms.txt](https://xiaohanliang.gitbook.io/xiaohanliang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaohanliang.gitbook.io/xiaohanliang/docker/storage-driver/union-mounting.md).

# 1. 什么叫联合挂载

> Unifying filesystems with union mounts
>
> 本文译自 → [这里](https://lwn.net/Articles/312641/) , 并加上了一些我的理解

联合挂载的概念是指, 想要在同一个挂载点上挂载好几个文件系统, 呈现出来的效果是: 一个挂载点下同时出现了不同文件系统里的东西. 显然, 这说的是Docker, 所有人都知道镜像分成好多层, 将这些层做一次"融合"(merge)就形成了我们在容器里看到的东西. 我们从这个现象开始讨论.

在一次普通的挂载过程中, 比如你把目录A挂到挂载点B上, 那么B目录下的东西直接就会被隐藏起来, 进入B目录只能看到A的东西, B的东西不是说不存在了, 而是说被**隐藏起来了**. 只有在解除A挂载以后才能看到了.

在内核里, 几个文件系统按照他们被挂载的顺序被一层层的摞(stack)起来, 最先被挂载的文件系统会被放在最下层, 最后被挂载的则处在最上层, 很不幸, 在普通挂载模式下, 你只能访问最上层的文件系统. 但如果你用了联合挂载的功能, 那么上上下下所有文件你都是能看到的. (如果出现了重名文件, 只展示上面的)

我提一个有意思的场景, 我们都知道远古时代的DVD是一次性写入的, 没有修改的道理, 写错了这批货就废了. 假设你DVD里是红警的安装包. 过段时间游戏更新成v1.1了, 这种情况下, 你手上的v1.0该怎么卖呢? 如果用联合挂载的办法, 我们在碟片空白的地方写上一些重名文件作为更新包, 读碟的时候把v1.0与更新包摞起来, v1.0放在下面, 更新包放在上面, 这样重名文件就能覆盖老文件, 达到更新的效果


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaohanliang.gitbook.io/xiaohanliang/docker/storage-driver/union-mounting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
