How does the overlay filesystem work in Linux?

How does the overlay filesystem work in Linux?

In case the underlying inode number does overflow into the high xino bits, overlay filesystem will fall back to the non xino behavior for that inode. The “xino” feature can be enabled with the “-o xino=on” overlay mount option.

What kind of driver do I need for OverlayFS?

Note: If you use OverlayFS, use the overlay2 driver rather than the overlay driver, because it is more efficient in terms of inode utilization. To use the new driver, you need version 4.0 or higher of the Linux kernel, or RHEL or CentOS using version 3.10.0-514 and above.

How many OverlayFS layers does overlay2 support?

OverlayFS refers to the lower directory as lowerdir and the upper directory a upperdir. The unified view is exposed through its own directory called merged. The overlay2 driver natively supports up to 128 lower OverlayFS layers.

What do you call two directories in OverlayFS?

OverlayFS layers two directories on a single Linux host and presents them as a single directory. These directories are called layers and the unification process is referred to as a union mount. OverlayFS refers to the lower directory as lowerdir and the upper directory a upperdir.

How is readdir handled in an OverlayFS file?

Readdir on directories that are not merged is simply handled by the underlying directory (upper or lower). When renaming a directory that is on the lower layer or merged (i.e. the directory was not created on the upper layer to start with) overlayfs can handle it in two different ways:

How does an overlay filesystem support RM and rmdir?

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.

How is a file copied from the lower filesystem to the upper?

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.