Overlayfs (Overlay Filesystem) is an in-kernel attempt at providing union file system capabilities on Linux. OverlayFS differs from other union filesystem implementations in that after a file is opened all operations go directly to the underlying, lower or upper, filesystems. This simplifies the implementation and allows native performance in these cases.
The option to enable OverlayFS exists in Linux kernels 3.18 and higher.
File systems ---> [*] Overlay filesystem support
Once enabled in the kernel OverlayFS can be controlled using the mount command.
mount -t overlay overlay -o lowerdir=lowerdir,upperdir=upperdir,workdir=workdir mountpoint
To mount an overlay filesystem using the following example of a structure on an ext4 base filesystem.
Create the following folder structure
tree test_folder test_folder ├── low ├── my_overlay └── up
On the folder low, create a file with a clear and recognizable name. Repeat the step on the folder up to get a structure similar to the following:
tree test_folder test_folder ├── low │ └── low_file ├── my_overlay └── up └── up_file
Having that tree, the following command will create an overlay structure with the up folder above the low folder and that structure will be on the my_overlay folder.
mount -t overlay overlay -o lowerdir=/test_folder/low,upperdir=/test_folder/up,workdir=/test_folder/my_overlay /test_folder/my_overlay/
After inspecting the tree structure of the test_folder, this will be printed
tree test_folder test_folder ├── low │ └── low_file ├── my_overlay │ ├── low_file │ └── up_file └── up └── up_file
A file can be created using the normal filesystem structure, like the following
and will generate the following tree
tree test_folder test_folder ├── low │ └── low_file ├── my_overlay │ ├── low_file │ ├── my_overlay_file │ └── up_file └── up ├── my_overlay_file └── up_file
The overlay working dir can be unmounted with the umount command
After unmounting the overlay folder, a new subfolder will appear on the directory where the operation was conducted
tree test_folder test_folder ├── low │ └── low_file ├── my_overlay │ └── work └── up ├── my_overlay_file └── up_file
That folder will have the following properties
d--------- 2 root root 4,0K sep 6 09:54 work
Multiple lowerdir entries, colon (:) separated, can be used. When doing so, upperdir and workdir can be omitted to make a read-only mount.
When included, both upperdir and workdir have to reside within the same filesystem.
- Aufs — an advanced multi-layered unification filesystem.
- SquashFS — an open source, read only, extremely compressible filesystem.
- Wikipedia:UnionFS — The original union filesystem.
- http://lwn.net/Articles/447650/ - A LWN article written by Jonathan Corbet in June 2011 covering vises and virtues of OverlayFS.
- An informative AskUbuntu.com thread.
- Overlay fs in the Linux git repository.