Fact-checked by Grok 2 weeks ago

Union mount

A union mount is a filesystem mounting method used in various operating systems to overlay multiple directories or filesystems, creating a single, unified that transparently combines their contents as if they were stored in one location, with higher-priority layers overriding lower ones where conflicts occur. This technique enables read-write modifications to appear only in the upper layer, preserving the integrity of underlying read-only branches, and is particularly valuable for scenarios requiring layered or virtualized file access without data duplication. The concept originated in the Plan 9 operating system, where the bind and mount system calls support union directories through flags like MBEFORE and MAFTER, allowing a new directory to be prepended or appended to an existing one for name resolution, with MCREATE enabling selective writes to writable branches. It was later adopted and refined in Unix-like systems, including 4.4BSD-Lite, where union mounts merge the contents of a mounted filesystem with the existing directory at the mount point, avoiding the traditional hiding of underlying files and instead providing a logical merger visible to users and processes. In modern implementations, such as Linux's —introduced as a prototype union filesystem in kernel version 3.18—union mounts support multiple lower layers (e.g., read-only directories stacked as /lower1:/lower2), a single upper layer for changes, and mechanisms like "copy-up" for promoting files during modifications, along with whiteouts for deletions. FreeBSD's mount_unionfs utility similarly attaches an upper directory over a lower one, maintaining visibility of both trees while prioritizing the upper for lookups and updates.) These features make union mounts essential for applications like (e.g., images layering changes atop base filesystems), live operating system distributions that overlay temporary writable space on read-only media, and efficient testing environments that isolate modifications without full copies.

Overview

Definition and Purpose

A union mount is a filesystem technique in operating systems that combines multiple directories or filesystems into a single, unified virtual view, where the contents appear merged such that files and directories from all layers are visible simultaneously. In this setup, read operations prioritize the uppermost layer for matching names, falling back to lower layers if not found, while write operations—such as creating or modifying files—typically direct changes to the topmost writable layer to avoid altering underlying read-only components. The primary purpose of union mounts is to enable non-destructive overlays, allowing modifications to be applied atop immutable base filesystems without duplicating data or risking corruption of originals, which is particularly useful for maintaining system integrity during updates or customizations. This approach supports versioning by preserving historical layers, facilitates the creation of isolated virtual environments akin to , and simplifies merging directory trees for dynamic, live-updating systems. Key benefits include efficient resource use through avoidance of full copies, enhanced flexibility in namespace management, and support for read-only with layered changes, as seen in implementations across operating systems like Plan 9, Linux's , and BSD variants. For instance, union mounts can overlay user-specific configurations onto system-wide defaults, ensuring that personalized settings take precedence without editing core files, thereby streamlining administration in multi-user or distributed environments.

History

Union mounts originated in Plan 9 from Bell Labs, a distributed operating system developed in the late 1980s by a team including Ken Thompson and Rob Pike to address limitations in traditional Unix-like systems for networked environments. The feature, known as union directories, was implemented using the bind and mount commands to overlay multiple directories into a single namespace, allowing sequential searching of components for flexible resource access; it became operational as part of Plan 9's primary computing environment by 1989. The concept gained broader adoption in systems through its integration into 4.4BSD in 1994, where it was formalized as a union filesystem feature to support merged views of directories for applications like read-only media overlays and user-specific customizations. Developed by Jan-Simon Pendry and Marshall Kirk McKusick, this implementation emphasized namespace management in multi-user settings and influenced subsequent BSD variants. In , union mount development accelerated in the early 2000s with , an initial stackable effort developed around 2003–2004 by Erez Zadok and his team at to enable layered filesystems for tasks such as live CDs. This evolved with AUFS (Another Union Filesystem), a 2006 rewrite by Junjiro R. Okajima that enhanced performance and reliability over UnionFS version 1.x, becoming widely used in distributions for its multi-branch support. By 2014, was merged into the mainline in version 3.18 as a simpler, in-kernel union mount , marking the transition to a standardized feature in modern distributions.

Technical Details

Mechanism of Operation

Union mounts operate by stacking multiple filesystem branches or directories into a unified , typically organized as layers where an upper (writable) layer overlays one or more lower (often read-only) layers. The core mechanism presents a merged view to users and applications, allowing transparent access to files across layers without altering the underlying structures. This layering was first formalized in Plan 9's union directories, where multiple directories are bound into a list and searched in a specified order. For read operations, path resolution follows a priority-based search starting from the topmost (highest-precedence) layer and proceeding downward until a matching file or directory is found. If no match exists in upper layers, the system falls back to lower layers, ensuring that files in higher layers shadow equivalent names in lower ones. Directories are merged similarly, combining entries from all visible layers while eliminating duplicates based on name. A simple algorithmic outline for lookup can be described as follows:
function lookup(path):
    for layer in layers from top to bottom:
        if path exists in layer and not hidden by whiteout:
            return layer's entry
    return not found
This caches results in the filesystem's dentry structures for efficiency in repeated accesses. Write operations are directed exclusively to the uppermost writable layer to maintain the read-only nature of lower layers. When modifying a file present only in a lower layer, a is triggered: the file's data and are duplicated to the upper layer, after which the modification proceeds on the copy. This principle avoids altering immutable lower layers and ensures atomicity during the transition. For directory creations, intermediate directories in the upper layer are built as needed to support the new path. Deletions from lower layers are simulated using whiteout markers—special opaque files or entries (e.g., zero-length files with a .wh. prefix or special device nodes) placed in the upper layer to hide the corresponding lower entry from the merged view. Opaque directories serve a similar role for subtrees, preventing visibility of lower directories. Handling edge cases varies slightly across implementations but follows consistent principles. Symbolic links are resolved using the leftmost (top) occurrence, without requiring copy-up unless modification is needed. Hard links across layers typically necessitate copy-up to unify references in the upper layer. Permissions are evaluated against the effective layer's attributes, often with stashed credentials to reconcile differences between layers, ensuring consistent during operations like copy-up. Conflicts between file types (e.g., a in the upper layer shadowing a in the lower) are resolved by prioritizing the upper layer, potentially leading to errors if incompatible operations are attempted. Union mounts differ from overlay filesystems in their support for layering and write operations. While overlay filesystems like typically combine multiple read-only lower layers with a single writable upper layer, where modifications trigger copy-up operations to the upper layer, union mounts—such as those implemented in —allow for multiple read-write branches that can be dynamically inserted or deleted, enabling full merging across layers without restricting writability to one layer. In contrast to bind mounts, which simply remount an existing or subtree at a new location to provide an alternate view of a single filesystem without any merging or prioritization of contents, union mounts actively combine and prioritize elements from multiple distinct sources into a unified . Union mounts also diverge from snapshotting mechanisms in filesystems like or , which create point-in-time copies using to enable versioning and rollback without affecting the live system; unions instead facilitate live, non-forking overlays that merge active directories in , avoiding the storage overhead of full snapshots while supporting dynamic updates.
TechniqueLayering SupportWrite HandlingUse in Containers
Union MountMultiple layers, including multiple read-write branchesCopy-up or direct merge to prioritized branchesEarly implementations influenced layered storage; supports dynamic branch management for flexible isolation
OverlayFSMultiple read-only lower layers + one writable upper layerCopy-up from lower to upper on modificationPrimary driver for Docker images; enables efficient, immutable layer stacking
Bind MountSingle layer (no merging)Direct access to source filesystemHost-container directory sharing; no layering or prioritization
Snapshot (ZFS/Btrfs)Point-in-time fork of filesystemCopy-on-write for changes post-snapshotVersioning and rollback in container storage; higher overhead for live merges
The concept of union mounts has influenced modern container technologies, such as Docker's image layering, which relies on union filesystems like OverlayFS to stack immutable layers for efficient storage and deployment, though Docker layers emphasize persistence and immutability over the dynamic, multi-writable flexibility of traditional unions.

Implementations

Plan 9

Plan 9 from Bell Labs provided native support for union mounts as a core feature of its distributed operating system architecture, with the first edition released in 1992. This implementation was integrated into the 9P protocol, which serves as the foundational network-transparent file access mechanism, allowing union directories to seamlessly overlay local and remote filesystems across distributed environments. The design emphasized flexibility in resource aggregation, enabling users to combine directories from multiple sources without disrupting the overall namespace structure. Union mounts in Plan 9 are primarily achieved through the bind command and its underlying system call, which modify the current process's namespace and those of its group. For simple unions, bind replaces or aliases a target directory (old) with a source (new), while flags like -a (append after) and -b (before) extend existing union directories by adding the source's contents to the end or beginning of the search order, respectively. The -c flag enables file creation within the union, directing new files to the first writable component. These operations support multi-directory overlays, creating a unified view where files from overlaid directories are presented transparently, with search precedence determined by the binding order. In Plan 9's namespace-based system, such unions are handled per-process, inheriting across forks unless explicitly controlled, which allows dynamic reconfiguration without system-wide mounts. A key unique aspect of Plan 9's union mounts is their tight integration with per-process namespaces, permitting individualized overlays that do not affect other processes or require global configuration. For instance, users commonly bind remote filesystems under /n/ (for network sources) or /mnt/ (for mounted devices) to create unions, such as overlaying personal binaries onto system directories for customized environments. This approach supports seamless , where 9P transactions handle access to unioned components regardless of their local or remote origin. Developed at starting in the mid-1980s by the team behind Unix, these features were crafted to foster flexible, location-independent resource sharing in research-oriented distributed systems. Union mounts remain a fundamental, largely unchanged element in Plan 9 derivatives like 9front, an actively maintained fork with recent releases as of October 2025.

Unix and BSD Variants

The union mount was introduced in 4.4BSD-Lite in 1994 as the , a mount-centric mechanism for overlaying directories to form a unified without obscuring underlying content. This implementation, accessed via the mount_union command, allows stacking of filesystem branches where the upper layer serves as the writable component atop one or more read-only lower layers. Modifications to files in lower layers trigger a copy-up operation to the upper layer, while deletions are handled through whiteout files—special opaque entries that mask corresponding items below without altering the original filesystems. Early versions lacked support for recursive unions, restricting stacking to non-nested configurations and requiring manual management for deeper hierarchies. Adoption extended to modern BSD derivatives, including , , and , each with tailored variants emphasizing compliance and global mount tables. In , the mount_unionfs command provides the primary interface, often paired with nullfs for straightforward bind mounts that lack unioning semantics. NetBSD and OpenBSD retained the mount_union syntax from 4.4BSD, with NetBSD's kernel-integrated incorporating performance tweaks such as optimized caching for branch traversals to reduce lookup overhead in multi-layer setups. Command usage typically follows the form mount -t unionfs [options] upperdir uniondir, where options like -o below adjust visibility priorities across branches. Post-2000 releases addressed historical bugs, including conditions in locking and mount ordering issues that could lead to filesystem inconsistencies or escalations. For instance, fixed several ambiguities and concurrency problems persisting until version 6.2 in 2006. Similar refinements in and stabilized whiteout handling and copy-up reliability, enhancing robustness for production environments. These variants differ subtly: emphasizes tunable performance for high-load scenarios, while prioritizes security hardening in whiteout creation to prevent namespace leaks. continues to be maintained in , with an update to version 3.7 as of October 2025. A common usage example involves overlaying local customizations on a base system directory, such as mounting /usr/local atop /usr to add user binaries without modifying the original tree: mount -t [unionfs](/page/UnionFS) -o upper=/usr/local /usr /usr. This preserves access to base files while prioritizing local overrides, ideal for development or site-specific extensions. The BSD union mount's design, influenced by Plan 9's union directories, maintains Unix semantics in a , contrasting per-process approaches in other systems.

Linux

Union mount support in Linux began with out-of-tree kernel modules in the early 2000s, notably , which provided a stackable unification filesystem for merging multiple directories (branches) into a single view while preserving their physical separation. , initially released around 2004, operated as a loadable module that intercepted filesystem operations to enable features like read-write overlays on read-only branches. This implementation drew inspiration from earlier union mount concepts in BSD systems but adapted them for 's modular kernel architecture. In 2006, AUFS (Advanced Union Filesystem) emerged as a reimplementation and enhancement of , introducing improved branch management, dynamic policy-based selection of branches, and better performance for multi-layered stacking. AUFS supported arbitrary numbers of branches with read-write capabilities on upper layers and was widely adopted in distributions for live environments and storage before kernel mainline integration of alternatives. However, both and AUFS remained out-of-tree and were eventually deprecated in favor of in-kernel solutions; Unionfs development stalled, and AUFS was not merged due to maintenance concerns. The modern standard for union mounts in Linux is OverlayFS, which was merged into the kernel in version 3.18 in December 2014, providing a lightweight, native implementation focused on simplicity and efficiency. OverlayFS supports overlaying a read-only lower directory onto a writable upper directory, using copy-on-write semantics where modifications are stored only in the upper layer to avoid altering the lower one. Key features include whiteout support for hiding lower-layer files, implemented via extended attributes such as "trusted.overlay.whiteout" on zero-sized files or special character devices, and compatibility with diverse underlying filesystems. Mount options include "lowerdir" for specifying one or more read-only layers (separated by colons for multiples) and "upperdir" for the writable overlay, requiring a separate "workdir" on the same filesystem as upperdir for temporary operations. For user-space alternatives, tools like unionfs-fuse provide FUSE-based mounts, allowing flexible overlaying of directories without kernel modifications, though with potential overhead compared to in-kernel . is now the preferred implementation in major distributions, such as , where it is used via packages like overlayroot to create writable environments over read-only root filesystems. An example mount command is: mount -t overlay overlay -o lowerdir=/base,upperdir=/mods /union, which combines the read-only /base with writable modifications in /mods at the /union mount point.

Applications

Common Use Cases

Union mounts are frequently employed in system administration for overlaying patch directories onto read-only operating system images, enabling live upgrades without disrupting the base system, particularly in embedded environments where storage constraints and reliability are critical. For instance, in Linux-based embedded devices, OverlayFS—a union filesystem implementation—allows modifications to be stored in a writable upper layer while preserving the immutable lower layer, facilitating atomic updates and rollback capabilities. In modern DevOps, OverlayFS is used for efficient caching in tools like Terraform, enabling fast, reversible state management. This approach supports versioning by maintaining multiple overlay states that can be switched or merged as needed, ensuring system integrity during over-the-air updates in IoT devices. In embedded Linux, it pairs with SquashFS for read-only root filesystems overlaid with writable layers. In and , union mounts form the foundation for layering filesystem images, as seen in where merges read-only base layers with writable container-specific changes to avoid data duplication and optimize storage. This technique enables efficient image composition in setups, allowing multiple containers to share common lower layers while isolating modifications in upper layers. Development environments benefit from union mounts by providing temporary writable overlays on stable, read-only codebases, permitting developers to test changes without altering the original source tree. In Plan 9, stackable binds—precursors to modern union mounts—allow binding private directories containing modifications over a shared source hierarchy, supporting collaborative development across teams. For and , union mounts enable non-destructive file merges, where changes are isolated in an overlay to prevent overwriting originals, allowing easy restoration by discarding or reverting the upper layer. , an early implementation, leverages semantics for snapshotting, capturing filesystem states for without full duplication. Specific examples include live CDs like , which use union mounts to overlay a writable RAM disk () on a read-only ISO9660 filesystem, providing session persistence for users trying distributions or performing rescues without modifying the media. Similarly, in sandboxed environments, such as those using private namespaces, union mounts enable customized views by overlaying configuration directories, enhancing security for untrusted applications.

Advantages and Limitations

Union mounts offer significant space efficiency by storing only deltas or changes in upper layers rather than duplicating entire filesystems, allowing multiple instances to share read-only base layers without full copies. This approach is particularly beneficial in layered setups, such as those used in , where shared lower layers can reduce overall storage requirements substantially compared to traditional mounts that require independent copies. Additionally, union mounts provide flexibility in dynamic environments by enabling the stacking of read-only and writable layers, facilitating easy experimentation and modification without altering underlying data. is straightforward, as changes can be discarded simply by unmounting or replacing the upper layer, restoring the original state without complex recovery processes. Despite these benefits, union mounts introduce performance overhead due to layer traversal during lookups and the copy-up mechanism, which copies files from lower to upper layers on modification, potentially increasing I/O latency. For instance, benchmarks on show typical overheads of 2-3% for user workloads but up to 27.5% in write-intensive scenarios involving copy-ups. is complicated by hidden files in lower layers obscured by upper-layer whiteouts or deletions, making it challenging to trace issues across the stack. In multi-writer scenarios, where multiple upper layers attempt concurrent modifications, inconsistencies can arise if is not properly managed, leading to potential data races or unexpected behavior. Implementations like have faced security issues, including vulnerabilities (e.g., CVE-2023-0386 exploited as of 2025), highlighting the need for timely kernel updates in containerized deployments. Key trade-offs in union mounts include that while some microbenchmark operations exhibit linear scaling with stack depth, demonstrates good overall scalability with constant overhead up to 16 branches in typical workloads. Security risks emerge from obscured lower-layer files, which may hide malicious content or sensitive data from users interacting only with the merged view, potentially exposing vulnerabilities if direct access to branches is possible. Compared to traditional mounts, union mounts achieve notable storage reductions through layer sharing—often avoiding full duplications—but at the cost of elevated lookup times due to merging operations, with overheads typically in the low single-digit percentages for standard accesses. To mitigate these issues, strategies such as limiting stack depth to shallow configurations or leveraging optimized implementations like , which includes features like metacopy for deferred data copying and improved caching, can balance efficiency and performance.

References

  1. [1]
    Overlay Filesystem - The Linux Kernel documentation
    This document describes a prototype for a new approach to providing overlay-filesystem functionality in Linux (sometimes referred to as union-filesystems). An ...
  2. [2]
    Managing the union file system (UFS) - IBM
    The union file system (UFS) provides a merged view of two or more directories. This merged view is obtained by accessing the mount point of the union file ...
  3. [3]
    Plan 9 /sys/man/2/bind
    After an MBEFORE bind or mount, the new directory will be searched first when evaluating file names in the union directory. MAFTER Like MBEFORE but the new ...
  4. [4]
    Union mounts in 4.4BSD-Lite - FreeBSD Presentations and Papers
    Unlike a traditional mount that hides the contents of the directory on which it is placed, a union mount presents a view of a merger of the two directories.
  5. [5]
    [PDF] Plan 9 from Bell Labs - MIT CSAIL Computer Systems Security Group
    When a directory is added to the union, a flag to bind or mount enables create permission (a property of the name space) in that directory. When a file is ...<|control11|><|separator|>
  6. [6]
    A brief history of union mounts - LWN.net
    Jul 14, 2010 · This helps us to uniformly define offsets across all the directories of the union irrespective of the type of filesystem involved. Also this is ...
  7. [7]
    AUFS - SourceForge
    ... Junjiro R. Okajima 0. Introduction ---------------------------------------- In the early days, aufs ... aufs.5 for aufs1 · tips from users · history of aufs1.<|control11|><|separator|>
  8. [8]
    Overlay Filesystem — The Linux Kernel documentation
    ### Summary of OverlayFS Core Mechanism
  9. [9]
    Plan 9 /sys/man/1/bind
    When a new file is created in a union directory, it is placed in the first element of the union that has been bound or mounted with the –c flag. If that ...
  10. [10]
    Versatility and Unix Semantics in a Fan-Out Unification File System
    Nov 9, 2004 · We designed a unification file system called Unionfs which uses a promising fan-out stacking technique rarely used before.3 Design Details · 3.7 Readdir · 6.3 Micro Benchmarks
  11. [11]
  12. [12]
    Unioning file systems: Architecture, features, and design choices
    Mar 18, 2009 · Plan9 has formalized union mount semantics in quite clear and simple but completely non-POSIX way. Overall, it has dropped a lot of POSIX ...
  13. [13]
    mount(8) - Linux manual page - man7.org
    The mount command compares filesystem source, target (and fs root for bind mount or btrfs) to detect already mounted filesystems. The kernel table with ...<|separator|>
  14. [14]
    OverlayFS storage driver - Docker Docs
    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 ...
  15. [15]
    Plan 9 from Bell Labs — Overview
    Plan 9 has had four major releases over its lifetime. The first edition, released in 1992, was made available only to universities.<|separator|>
  16. [16]
    Plan 9 from Bell Labs
    Plan 9 began in the late 1980's as an attempt to have it both ways: to build a system that was centrally administered and cost-effective using cheap modern ...
  17. [17]
    [PDF] The Unix Spirit set Free: Plan 9 from Bell Labs - Huihoo
    The history of Plan 9​​ Started in the mid 1980's at Bell Labs by the same team that created Unix. First full time users in 1989, in production since then.<|control11|><|separator|>
  18. [18]
    Union Mounts in 4.4BSD-Lite - USENIX
    Union Mounts in 4.4BSD-Lite ... Abstract: This paper describes the design and rationale behind union mounts, a new filesystem-namespace management tool available ...
  19. [19]
    mount_unionfs - FreeBSD Manual Pages
    EXAMPLES The commands mount -t cd9660 -o ro /dev/cd0 /usr/src mount -t unionfs -o noatime /var/obj /usr/src mount the CD-ROM drive /dev/cd0 on /usr/src and ...
  20. [20]
    The new unionfs implementation for FreeBSD and status of merging
    There were several known problems in unionfs implementation of FreeBSD up until 6.2-RELEASE. The specification is ambiguous and its locking implementation ...Missing: 2000 | Show results with:2000
  21. [21]
    FreeBSD-SA-96:10.mount_union
    The union filesystem code had problems with certain mount ordering problems. By executing a certain sequence of mount_union commands, an unprivileged local user ...
  22. [22]
    Kernel Korner - Unionfs: Bringing Filesystems Together - Linux Journal
    Dec 1, 2004 · Because Unionfs presents a filesystem view to the kernel, it can be employed by any user-level application or from the kernel by the NFS server.
  23. [23]
    [PDF] and Community-Oriented Development of a Unification File System
    Jul 22, 2006 · Unionfs is a stackable file system that virtually merges a set of directories (called branches) into a single logical view.
  24. [24]
    aufs - advanced multi layered unification filesystem. version 5.x-rcN ...
    Aufs is a stackable unification filesystem such as Unionfs, which unifies several directories and provides a merged single directory. ... By default (since linux- ...<|separator|>
  25. [25]
    Unionfs vs Aufs vs Overlayfs vs mhddfs, which one do I use
    Jul 28, 2017 · Use overlayfs for simple layering with one RW layer "on top", mergerfs as an alternative to LVM/RAID0 for combining multiple disks into one logical file system.Build AUFS/UnionFS driver for Linux 6.6.31Querying an overlayfs - Unix & Linux Stack ExchangeMore results from unix.stackexchange.comMissing: history | Show results with:history
  26. [26]
    unionfs-fuse(8) - Linux man page - Die.net
    unionfs-fuse overlays several directories into one mount point, accessing files from top to lower branches, and copying on write if enabled.
  27. [27]
    chroot into the lower filesystem in a writable mode - Ubuntu Manpage
    overlayroot-chroot is a program that sets up bind mounts for /proc, /run, and /sys, remounts the lower directory in an overlayfs with write capabilities and ...
  28. [28]
    Improving data integrity in Linux embedded systems with OverlayFS
    May 2, 2024 · Behind the scenes, OverlayFS uses the “trusted” extended attribute class or namespace to record “whiteouts” and “opaque directories.” Linux file ...
  29. [29]
    New Patch Series Allows OverlayFS To Work With Casefolding
    May 20, 2025 · New Patch ... The OverlayFS union mount file-system is commonly used for live Linux images, IoT/embedded devices, and similar purposes.
  30. [30]
    [PDF] Glen or Glenda - The Linux Kernel Archives
    Another use of stackable binds in PLAN 9 is within a development environment. You can bind directories (or even individual files) with your changes over ...<|control11|><|separator|>
  31. [31]
    [PDF] Versatility and Unix Semantics in a Fan-Out Unification File System
    Copyup-on-write: Plan 9 union directories do not support copyup. 3DFS, TFS, BSD Union Mounts, and Unionfs can copy a file from a read-only branch to a higher- ...