OverlayFS

From Gentoo Wiki
Jump to:navigation Jump to:search
Other languages:

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.[1]

The option to enable OverlayFS exists in Linux kernels 3.18 and higher.[2]

Installation

Kernel

KERNEL Enable OverlayFS (OVERLAY_FS) support
File systems  --->
   [*] Overlay filesystem support

Usage

Once enabled in the kernel OverlayFS can be controlled using the mount command.

root #mount -t overlay overlay -o lowerdir=lowerdir,upperdir=upperdir,workdir=workdir mountpoint

Example

To mount an overlay filesystem using the following example of a structure on an ext4 base filesystem.

Create the following folder structure:

user $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:

user $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.

root #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:

user $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

root #touch my_overlay/my_overlay_file

and will generate the following tree

user $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

root #umount /test_folder/my_overlay/

After unmounting the overlay folder, a new subfolder will appear on the directory where the operation was conducted

user $tree test_folder
|
test_folder
├── low
│   └── low_file
├── my_overlay
│   └── work
└── up
    ├── my_overlay_file
    └── up_file

That folder will have the following properties

CODE
d--------- 2 root root 4,0K sep  6 09:54 work
Note
Multiple lowerdir entries, colon (:) separated, can be used. When doing so, upperdir and workdir can be omitted to make a read-only mount.
Important
When included, both upperdir and workdir have to reside within the same filesystem.

See also

  • Aufs — an advanced multi-layered unification filesystem.
  • SquashFS — an open source, read only, extremely compressible filesystem.
  • Wikipedia:UnionFS — The original union filesystem.

External resources

References