In this lesson, you will learn how OverlayFS handles the deletion of files in a layered filesystem without modifying the underlying read-only base image.
The Deletion Challenge
In a layered architecture like OverlayFS, we have a lower layer (the read-only image) and an upper layer (the writable container layer). Because the lower layer is immutable, you cannot simply "delete" a file from it. If you issue a rm command on a file that exists in the lower layer, the kernel needs a way to signal that the file should appear as if it is gone, while keeping the original file intact on the disk.
The Whiteout Mechanism
OverlayFS achieves this using whiteout files. When you delete a file that exists in the lower layer, the kernel creates a special character device file in the upper layer with a major device number of 0 and a minor number of 0. This is the "whiteout."
When the filesystem attempts to access a file, the OverlayFS driver checks the upper layer first. If it encounters a whiteout character device with the same name as the target file, it treats that name as non-existent, effectively "masking" the version present in the lower layer.
Practical Visualization
If you have a file /base/app.log and you delete it inside your container, your upper directory will end up looking like this:
$ ls -c /upper/dir
c--------- 1 root root 0, 0 Jan 01 00:00 app.log
The presence of this 0,0 character device tells the VFS layer: "Do not look for app.log in the lower layers; for all intents and purposes, this file does not exist." Even though the actual data for app.log still consumes space in your base image, the container runtime successfully hides it from the user and the application, maintaining the illusion of a single, mutable filesystem.
This mechanism allows containers to be ephemeral and disposable; we can delete any file from the read-only image without needing to rebuild or alter the base image itself.
Key Takeaway: Whiteout files are special character devices created in the upper layer that mask the existence of files in lower layers, allowing for "deletions" without modifying the read-only base image.