Bind mount

On this page 7

A bind mount is a Linux filesystem operation that makes an existing directory or file appear at a second location in the directory tree, so that both paths refer to the same underlying data. Nothing is copied and no new filesystem is created: the kernel simply attaches an already mounted subtree to another mount point, and every change made through one path is immediately visible through the other.

Bind mounts are a basic building block of containers, chroot environments and build sandboxes, and they are the standard way to expose host directories to Docker or Podman workloads. They are created with mount --bind, recorded in fstab with the bind option, and behave like any other entry in the mount table.

How a bind mount works in the kernel

A bind mount works by creating a new mount object that points to an existing dentry inside an already mounted filesystem. The Linux virtual filesystem layer (VFS) keeps a tree of mounts; a normal mount connects a block device or pseudo filesystem to a directory, whereas a bind mount connects a subtree of an existing mount to a directory. The inodes, the page cache and the on-disk structures stay exactly the same.

Because the source and the target share inodes, a file opened through /srv/data/report.txt and through /mnt/view/report.txt has the same inode number, the same permissions and the same contents. The bind mount is therefore not a copy and not a link: it is an additional view of the directory hierarchy that exists only in the mount table, not on disk.

The basic commands are short. mount --bind /srv/data /mnt/view mounts only the top mount at the source, while mount --rbind performs a recursive bind that also carries every submount below the source. The following table summarizes the core operations.

CommandEffectTypical use
mount --bind src dstBinds one mount subtreeExpose a single data directory
mount --rbind src dstBinds the subtree and all submountsPopulate a chroot with /dev or /proc
mount -o remount,bind,ro dstMakes the bind read-onlyProtect data from a sandboxed process
umount dstRemoves only the second viewTear down a temporary view
findmnt dstShows the source and optionsVerify what is actually mounted
Core bind mount commands

Mount options and propagation types

A bind mount has its own per-mount flags, independent of the source mount. Flags such as ro, nosuid, nodev and noexec can differ between the two views, which allows an administrator to export a directory read-only in one place and writable in another. A long-standing pitfall is that mount --bind -o ro historically ignored the read-only flag on the first call; on older util-linux versions a separate remount step was required, and verifying the result with findmnt remains good practice.

Mount propagation decides whether new mounts created under one view also appear under the other. It was introduced with shared subtrees in kernel 2.6.15 and matters greatly for containers, because systemd marks the root filesystem as shared by default. The four propagation types are compared below.

Propagation typeEvents receivedEvents sentCommon use
sharedYes, from peersYes, to peersDefault root on systemd hosts
slaveYes, from masterNoContainers that must see host mounts
privateNoNoIsolated sandboxes
unbindableNoNoPrevent recursive bind loops
Mount propagation types

Propagation is set with flags such as --make-private, --make-rslave or --make-shared, and Docker exposes the same choices as rprivate, rslave and rshared. Choosing the wrong mode can make a USB mount disappear inside a container or, conversely, leak container mounts back to the host.

A bind mount differs from a symbolic link, a hard link and OverlayFS in where the redirection lives and what it can cross. A symbolic link is a file containing a path; a hard link is an extra directory entry for the same inode; a bind mount is an entry in the kernel mount table. Each tool solves a different problem.

MechanismStored whereCrosses filesystemsWorks inside chrootSurvives reboot
Bind mountMount table in memoryYesYesOnly via fstab or unit
Symbolic linkOn disk as a pathYesOnly if the path resolvesYes
Hard linkOn disk as a directory entryNoYesYes
OverlayFSMount table with layersYesYesOnly via fstab or unit
Comparison with related mechanisms

The decisive difference appears inside a chroot or container: a symbolic link pointing to /srv/data resolves against the new root and usually breaks, whereas a bind mount is resolved by the kernel before the root changes. Unlike OverlayFS, a bind mount has no copy-up layer, so every write lands directly in the source directory.

Practical use and persistent configuration

Bind mounts are made persistent through fstab or systemd mount units; a mount made on the command line disappears at reboot. A typical fstab line reads /srv/data /var/www/data none bind 0 0, where the filesystem type is none and the option is bind or rbind. On systemd hosts the line is converted into a generated .mount unit, so ordering dependencies such as RequiresMountsFor= work as expected.

The following decision table maps common administrative situations to a recommended bind mount pattern.

SituationRecommended patternReason
Web server needs data from another volumeBind in fstab, read-onlyKeeps paths stable without copying
Repairing a system from rescue mediaRecursive bind of /dev, /proc, /sysTools inside the chroot need kernel interfaces
Container needs a host directoryBind with rprivate propagationAvoids mount leakage
Hide a directory from usersBind an empty directory over itMasks contents without deleting them
Build sandbox with read-only systemBind root read-only, tmpfs for workPrevents writes to the host
Choosing a bind mount pattern

Tools such as bubblewrap, systemd-nspawn and the BindPaths= and BindReadOnlyPaths= service options all rely on the same kernel mechanism, which makes the bind mount a standard technique for hardening individual services.

Limitations and common mistakes

Bind mounts are simple, but several behaviors regularly surprise administrators. Backup and search tools may traverse the same data twice, and disk usage reports can double-count directories unless options such as --one-file-system or -xdev are used.

SymptomCauseFix
Bind is writable despite roRead-only flag not applied on first callRemount with remount,bind,ro
Submounts missing in targetPlain bind instead of recursive bindUse rbind
umount reports target is busyA process has its working directory thereFind it with fuser or lsof
Mount loop or exploding mount tableRecursive bind of a shared parent into itselfMake the source private or unbindable
Container sees wrong ownershipUser namespace ID mappingUse idmapped mounts or adjust ownership
Symptoms, causes and fixes
  • A bind mount does not change permissions; the source mode bits and ACLs still apply.
  • Deleting files through the target deletes the original data, because there is only one copy.
  • A bind of a single file fails if the file is replaced by a rename, since the mount keeps the old inode pinned.

Stripped to the essentials

A bind mount is like adding a second door to the same room. The room and everything in it stay where they are, but people can now walk in through another hallway. Whatever someone moves or removes through one door is changed for everyone, because there is only one room.

Computers use this trick to show a folder in a new place without copying it. It is quick, uses no extra space and disappears when the computer restarts unless it is written into the startup settings.

Where it is applied

A hosting administrator runs a small Linux server where customer uploads live on a separate 2 TB disk mounted at /srv/uploads, while the web application expects them under /var/www/shop/public/media. Instead of moving data or editing the application, the administrator adds one fstab line that binds /srv/uploads to the media directory, and a second remount line makes a separate view under /var/www/preview/media read-only for the staging site.

Later, the server fails to boot after a kernel update. Booted from rescue media, the administrator mounts the root partition at /mnt, performs a recursive bind of /dev, /proc and /sys, enters the system with chroot and reinstalls the bootloader. The repair takes about fifteen minutes, no files are copied, and the shop keeps serving the same uploads from a single location.