In this lesson, you will learn how OverlayFS structurally organizes upper, lower, and work directories to create a unified view of the filesystem.
The Anatomy of an Overlay Mount
OverlayFS functions as a union mount, merging multiple directory trees into a single, cohesive filesystem. To achieve this, it relies on three distinct directory roles provided during the mount operation:
- Lowerdir (Read-only): The base layer. This typically contains the "immutable" portion of a container image (like the OS binaries). It can be composed of multiple stacked directories, allowing for efficient image layer reuse.
- Upperdir (Read-Write): The "diff" layer. Any file modification, creation, or deletion occurring within the container happens here. If you modify a file that exists in the
lowerdir, OverlayFS performs a "copy-up" operation, moving the file to theupperdirbefore applying changes. - Workdir (Hidden/Internal): A scratch space required by the filesystem to ensure atomic operations. Before a file is moved to the
upperdir, it is prepared in theworkdirto prevent inconsistencies in case of a system crash or power failure during the move.
Structural Visualization
You can think of this as a transparency stack:
[ Unified View (Merged) ] <-- What the process sees
-------------------------
[ Upperdir (RW Layer) ] <-- Changes/Copies of files
[ Workdir (Internal) ] <-- Transaction staging area
[ Lowerdir (RO Layer) ] <-- Base filesystem image
When a process requests a file, the kernel checks the upperdir first. If the file isn't found, it traverses down to the lowerdir layers. If you create a new file, it lands directly in the upperdir. If you delete a file that originated in the lowerdir, the kernel creates a "whiteout" file (a character device with 0/0 device numbers) in the upperdir, effectively masking the existence of the file in the lower layer without actually modifying the read-only base.
By separating these components, OverlayFS enables lightweight container snapshots where multiple containers can share the same lowerdir while maintaining their own unique upperdir states.
Key Takeaway: The OverlayFS architecture uses the upperdir for mutations, the lowerdir as an immutable foundation, and the workdir as an atomic staging ground to present a single unified view to user-space processes.