What is Linux OverlayFS? Understanding upper/lower merging and copy-up
Linux OverlayFS is a kernel filesystem that presents a lower directory tree and an upper tree as one merged filesystem view. The lower tree can be read-only; writes go to the upper tree. If the same path exists in both, the upper object takes precedence, and a lower file is copied to upper on its first modification (copy-up). This arrangement is useful for container images and other systems that need a read-only base with isolated changes.
What is Linux OverlayFS? Understanding upper/lower merging and copy-up
Linux OverlayFS is a kernel filesystem that presents a lower directory tree and an upper tree as one merged filesystem view. The lower tree can be read-only; writes go to the upper tree. If the same path exists in both, the upper object takes precedence, and a lower file is copied to upper on its first modification (copy-up). This arrangement is useful for container images and other systems that need a read-only base with isolated changes.
This article covers the kernel filesystem, not Docker’s overlay2 storage driver. Docker and containerd can use OverlayFS, but runtime image management and the filesystem’s mount rules are different layers. Kernel options and some behavior vary by Linux version and configuration. Use the lab below only in a disposable test directory.
How does the merged view select files?
At mount time, OverlayFS combines lowerdir, upperdir, and workdir into a merged view. Lower and upper need not be different filesystems, but when a writable upper is used, upperdir and workdir must be on the same filesystem. OverlayFS uses workdir for internal operations.
Merged path accessed by a process
▲
┌────────┴────────┐
│ upper: changes and new files │ ← write target
├─────────────────┤
│ lower: base files │ ← may be read-only
└─────────────────┘If an ordinary file with the same name exists in both trees, the upper file is visible and the lower one is hidden. If both paths are directories, their name lists are merged. Only the directory entry names are merged: when an upper directory exists, its metadata and extended attributes are reported, while the lower directory’s corresponding attributes are hidden. A merged directory therefore does not mean ownership or all metadata are combined.
Writes use copy-up; deletes use whiteouts
Reading a lower file uses it as-is. When a process first changes the file contents or some metadata, OverlayFS creates the needed parent directories in upper, copies the lower file and its metadata there, then applies the change. This is copy-up; the lower source remains unchanged. A large file may therefore incur a copy cost on its first modification.
Deletion also leaves the shared lower tree untouched. OverlayFS can create a whiteout marker in upper so the matching lower name is hidden in the merged view. An opaque-directory marker can hide a same-named lower directory and its contents. These are implementation details, not evidence that lower files were physically erased. Do not create or remove whiteouts or their extended attributes by hand.
Mount prerequisites and common constraints
A writable upper filesystem must support the extended attributes (trusted.* or user.*) required by OverlayFS and provide valid d_type values in readdir responses. The kernel documentation says NFS is unsuitable as an upper filesystem. Lower does not need to be writable; read-only overlays have broader filesystem choices. Verify support with the kernel and filesystems actually in use.
Renaming a directory that originates in lower or is merged can return EXDEV by default. The redirect_dir feature can change this behavior, but defaults and accepted options depend on kernel version and configuration. If applications rename directories, test on the target kernel.
OverlayFS presents objects from underlying filesystems through a hybrid view. As a result, stat fields such as st_dev and st_ino can reflect underlying objects and may not be consistent or persistent in every configuration. Verify backup, search, and file-watching tools that rely on inode identity. Features such as xino can improve consistency under documented conditions, but have prerequisites.
Do not mistake it for an isolation boundary
OverlayFS merges files and records changes in upper; by itself it does not create container isolation or a security boundary. It checks access using the current task’s permissions and credentials saved when the mount is created. Permission outcomes can surprise you, so do not treat OverlayFS as a security control; test with the actual user, mount options, and kernel.
The kernel documents an override_creds option for certain uses of the new mount API. It does not have the same meaning with the old mount API. Do not enable it casually; consult the documentation for the running kernel and the requirements of the software creating the mount.
Verify behavior with a temporary directory
The following example is for a disposable Linux test host with root privileges. Do not run it on existing system or application data. It creates empty upper and work directories under one temporary directory, so they share a filesystem.
set -eu
lab=$(mktemp -d)
cleanup() {
if mountpoint -q "$lab/merged"; then
sudo umount "$lab/merged" || {
printf 'Could not unmount; leaving temporary path for manual recovery: %s\n' "$lab" >&2
return 1
}
fi
sudo rm -rf -- "$lab"
}
trap cleanup EXIT
sudo mkdir -p "$lab/lower" "$lab/upper" "$lab/work" "$lab/merged"
printf 'lower original\n' | sudo tee "$lab/lower/message.txt" >/dev/null
sudo mount -t overlay overlay \
-o "lowerdir=$lab/lower,upperdir=$lab/upper,workdir=$lab/work" \
"$lab/merged"
cat "$lab/merged/message.txt"
printf 'upper change\n' | sudo tee "$lab/merged/message.txt" >/dev/null
cat "$lab/merged/message.txt"
cat "$lab/lower/message.txt"
sudo test -f "$lab/upper/message.txt"Expected: the first cat shows the lower file; after the write, the merged path shows the upper content while the lower source is unchanged. The final test checks that copy-up created the upper file. When the shell exits, the trap unmounts and removes the temporary directory. If unmount fails, the script leaves the path in place; inspect it with findmnt "$lab/merged" and resolve the mount before cleanup.
Practical takeaway
OverlayFS preserves lower files while recording changes in upper and exposing both through a merged view. Copy-up can make the first write more expensive; whiteouts hide lower files rather than deleting them. Mount compatibility depends on upper filesystem features, the workdir location, permissions, and rename behavior. Validate the target kernel and filesystems with a small disposable experiment before relying on the behavior in production.
References
[Linux kernel documentation: Overlay Filesystem](https://docs.kernel.org/filesystems/overlayfs.html)
[Linux man-pages: mount(8)](https://man7.org/linux/man-pages/man8/mount.8.html)
Kernel documentation checked on 2026-11-23. Details can vary with kernel version and configuration; use the documentation for the target system.