首页

/

友链

/

分享

/

内推

/

关于


耍耍OverlayFS

自Linux3.4之后,就可以使用overlay了。来,耍耍。

[email protected]:~/playoverlay$ mkdir lower{1,2,3} upper work merged  # 创建文件夹
[email protected]:~/playoverlay$ touch lower1/l1.txt lower2/l2.txt lower3/l3.txt  # 创建文件
[email protected]:~/playoverlay$ tree  # 这是目前的结构
.
├── lower1
│   └── l1.txt
├── lower2
│   └── l2.txt
├── lower3
│   └── l3.txt
├── merged
├── upper
└── work

6 directories, 3 files
[email protected]:~/playoverlay$ sudo mount -t overlay overlay -o lowerdir=./lower1:./lower2:./lower3,upperdir=./upper,workdir=./work ./merged/ # 挂载
[email protected]:~/playoverlay$ tree  # 这是目前的结构
.
├── lower1
│   └── l1.txt
├── lower2
│   └── l2.txt
├── lower3
│   └── l3.txt
├── merged
│   ├── l1.txt
│   ├── l2.txt
│   └── l3.txt
├── upper
└── work
    └── work [error opening dir]

7 directories, 6 files
[email protected]:~/playoverlay$ touch merged/hahahahhha  # 创建一个文件
[email protected]:~/playoverlay$ rm merged/l1.txt  # 删除一个文件
[email protected]:~/playoverlay$ tree
.
├── lower1
│   └── l1.txt
├── lower2
│   └── l2.txt
├── lower3
│   └── l3.txt
├── merged
│   ├── hahahahhha
│   ├── l2.txt
│   └── l3.txt
├── upper
│   ├── hahahahhha
│   └── l1.txt
└── work
    └── work [error opening dir]

7 directories, 8 files
[email protected]:~/playoverlay$

解释两点:

[email protected]:~/playoverlay$ tree
.
├── lower1
│   └── l1.txt
├── lower2
│   └── l2.txt
├── lower3
│   └── l3.txt
├── merged
│   ├── hahahahhha
│   ├── l2.txt
│   └── l3.txt
├── upper
│   ├── hahahahhha
│   └── l1.txt
└── work
    └── work [error opening dir]

7 directories, 8 files
[email protected]:~/playoverlay$ rm lower2/l2.txt
[email protected]:~/playoverlay$ tree
.
├── lower1
│   └── l1.txt
├── lower2
├── lower3
│   └── l3.txt
├── merged
│   ├── hahahahhha
│   └── l3.txt
├── upper
│   ├── hahahahhha
│   └── l1.txt
└── work
    └── work [error opening dir]

7 directories, 6 files
[email protected]:~/playoverlay$
当然是上边就看不到了。

实现,就去看下边的 overlay.txt,用法,就看ArchWiki和Docker那个文档,就不赘述了。另外: