When working with Linux systems, the mount --bind
command creates a powerful way to mirror directories, but these mounts don't persist across reboots by default. This behavior is actually by design - bind mounts are considered temporary runtime operations in the same category as regular filesystem mounts.
The canonical way to make any mount persistent is through the /etc/fstab
file. For bind mounts, the syntax differs slightly from regular filesystem mounts:
# Persistent bind mount example
/source/directory /target/mountpoint none bind 0 0
Alternatively, you can use the more explicit syntax:
/source/directory /target/mountpoint none rbind,x-systemd.automount 0 0
For systems using systemd, you have additional options through mount units:
# /etc/systemd/system/mnt-target.mount
[Unit]
Description=Bind mount for /target
[Mount]
What=/source/directory
Where=/target/mountpoint
Type=none
Options=bind
[Install]
WantedBy=multi-user.target
After creating this file, enable it with:
systemctl enable --now mnt-target.mount
Common issues you might encounter include:
- Mount ordering problems (solution: add
_netdev
orx-systemd.requires=
options) - Permission issues (ensure source directory exists before mounting)
- Boot-time failures (check system logs with
journalctl -b
)
For more complex scenarios, consider:
# Recursive bind mount
mount --rbind /oldroot /newroot
# Read-only bind mount
mount --bind -o ro /source /target
# Making /proc appear in a chroot
mount --bind /proc /chroot/proc
When working with Linux filesystems, mount --bind
creates a mirror of one directory structure at another location. Unlike traditional mounts, bind mounts don't involve physical devices - they're purely virtual directory mappings. This makes them incredibly useful for:
- Creating alternative paths to the same data
- Isolating processes with chroot environments
- Maintaining legacy path compatibility
By default, bind mounts are temporary and don't persist across reboots because they're not recorded in /etc/fstab
. The common workaround of using rc.local
is problematic because:
- It executes late in the boot process
- May conflict with systemd services
- Creates race conditions with other mounts
Method 1: /etc/fstab Entry
# Syntax: source-path target-path none bind 0 0 /home/user/data /mnt/data none bind 0 0
Method 2: Systemd Mount Unit (Recommended for modern systems)
# /etc/systemd/system/mnt-data.mount [Unit] Description=Bind mount for /mnt/data [Mount] What=/home/user/data Where=/mnt/data Type=none Options=bind [Install] WantedBy=multi-user.target
Then enable with: systemctl enable --now mnt-data.mount
After implementing either solution, verify with:
mount | grep bind findmnt --verify systemctl list-units --type=mount
Common issues include:
- Source directory not existing at boot time (use
x-systemd.requires=
in fstab) - Permission conflicts (consider
x-gvfs-show
for GUI visibility) - Mount ordering problems (use
After=
in systemd units)
Read-only bind mount:
mount --bind -o ro /source /destination # fstab equivalent: /source /destination none bind,ro 0 0
Recursive bind (subtree):
mount --rbind /original /copy # systemd unit option: Options=rbind