Course contentsShow
← Linux
Lesson 1505 of 1,81913. Containerization Primitives and NamespacesFree lesson

OverlayFS Multi-Lower Support

Stack multiple image layers efficiently to optimize binary distribution and deployment.

In this lesson, you will learn how to leverage OverlayFS multi-lower support to stack multiple read-only image layers, enabling efficient binary distribution and granular container updates.

Beyond the Single Layer

In our earlier lessons on Union Mounts, we focused on the basic upper (writable) and lower (read-only) relationship. However, modern container runtimes rarely use a single base layer. Instead, they use a sequence of layers—a base OS image, a runtime environment, and application dependencies—stacked on top of each other. OverlayFS handles this through the lowerdir mount option, which accepts a colon-separated list of directories.

Ordering and Precedence

When you provide multiple directories to the lowerdir parameter, OverlayFS treats the order as a stack. The first directory listed is the "highest" priority (closest to the upper layer), and the last directory listed is the "lowest" priority (the base).

If a file exists in multiple lower directories, the version in the higher-precedence directory masks the others. This is the foundation of image layering: you can replace a single library in a higher layer without modifying the massive base image underneath.

Practical Implementation

To mount multiple layers, you define the lowerdir by chaining your paths from top to bottom:

# Structure: /upper, /work, /lower3, /lower2, /lower1
mount -t overlay overlay \
  -o lowerdir=/mnt/lower3:/mnt/lower2:/mnt/lower1,\
upperdir=/mnt/upper,\
workdir=/mnt/work \
  /mnt/merged

In this setup, /mnt/lower3 is the top-most read-only layer. If app.bin exists in both /mnt/lower3 and /mnt/lower1, the kernel will present the version from /mnt/lower3 to the user in /mnt/merged.

Efficiency Gains

This architecture is critical for storage optimization. Because lower layers are immutable, you can share them across multiple containers. If ten containers share the same lower1 (e.g., a Debian base image), the kernel loads it into the page cache only once. Furthermore, when distributing images over the network, you only need to transfer the missing layers, significantly reducing bandwidth and storage overhead during deployment.

Key Takeaway: Multi-lower support allows you to stack read-only filesystem layers in a prioritized sequence, enabling deduplication of common files and efficient, modular container image distribution.