Operations 6 min read

Mastering mount --bind: Seamless Directory Redirection on Linux

Learn how to replace cumbersome symlinks with Linux’s mount --bind command, covering basic usage, step‑by‑step examples, underlying VFS mechanics, persistence via /etc/fstab, and advanced scenarios such as temporary configuration testing and read‑only mounts.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering mount --bind: Seamless Directory Redirection on Linux

During Linux system administration, storage directories can fill up unexpectedly, and expanding the original disk may be impossible. A common quick fix is to create symbolic links, but multi‑level symlinks become confusing and error‑prone. This guide introduces mount --bind as a cleaner alternative.

What is mount --bind ?

The mount command is familiar to sysadmins. Using the --bind option, you can remount an existing directory onto another location, making the target directory a mirror of the source. All accesses to the target are transparently redirected to the source.

Basic Example

First, create two directories and place different files in each:

mkdir /tmp/test1
mkdir /tmp/test2
echo "data in test1" > /tmp/test1/file1.txt
echo "data in test2" > /tmp/test2/file2.txt

Check their inodes to see they are distinct:

ls -i /tmp/test1
ls -i /tmp/test2

Now bind /tmp/test1 onto /tmp/test2: mount --bind /tmp/test1 /tmp/test2 After the bind, the inode numbers and file contents under /tmp/test2 match those of /tmp/test1. Any modification made through /tmp/test2 actually changes the files in /tmp/test1.

Creating a new file in /tmp/test2 also creates it in /tmp/test1: echo "new file" > /tmp/test2/new.txt Listing both directories shows the same files, confirming the bind relationship.

How It Works

When mount --bind /tmp/test1 /tmp/test2 runs, the kernel hides the original entry of /tmp/test2 and records a mapping in a VFS vfsmount object. This object stores a hash‑based relationship between the source and target paths. Subsequent accesses to /tmp/test2 are redirected to the inode of /tmp/test1, while the underlying data remains unchanged.

Persistence

The bind relationship exists only in memory; a reboot clears it. To make it permanent, add an entry to /etc/fstab:

/tmp/test1  /tmp/test2  none  bind  0 0

Advanced Uses

Temporary configuration testing : Create a test config file in /tmp and bind‑mount it over the real config path. Run the application to verify behavior, then unmount to revert without touching the original file.

Read‑only bind mounts : Provide read‑only access to a directory while keeping the source writable. Use the ro option: mount --bind,ro /path/source /path/readonly This is useful for giving developers or auditors view‑only access to configuration files.

These examples illustrate the flexibility of mount --bind for managing storage constraints, testing scenarios, and access control without the pitfalls of deep symbolic‑link chains.

Conclusion

mount --bind

offers a reliable way to redirect directory accesses, preserve inode consistency, and maintain clear, reversible mappings. Remember to persist bindings in /etc/fstab if you need them across reboots, and explore the advanced options for temporary or read‑only mounts.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxSysadminFilesystemdirectory managementmount bind
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.