Operations 6 min read

Replace Symlinks with mount --bind: A Practical Linux Storage Trick

When a Linux application's data directory runs out of space, using mount --bind instead of layered symlinks lets you transparently redirect the directory to a larger disk, with clear steps, underlying principles, and advanced read‑only or temporary configurations.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Replace Symlinks with mount --bind: A Practical Linux Storage Trick

During Linux operations, a filled storage directory often forces administrators to create a symbolic link (using ln) to a larger disk, but multi‑level symlinks quickly become confusing. The article introduces mount --bind as a cleaner alternative.

What mount --bind does

The familiar mount command can also bind one directory to another. It re‑mounts the source directory onto the target path, so every access to the target is actually an access to the source.

Step‑by‑step example

1. Create two directories and files:

mkdir /tmp/test1
mkdir /tmp/test2
echo "data1" > /tmp/test1/file1
ls -i /tmp/test1 /tmp/test2

2. Check the inode numbers of the files (they differ at this point).

3. Bind /tmp/test1 to /tmp/test2: mount --bind /tmp/test1 /tmp/test2 4. Re‑check the inode numbers; the files under /tmp/test2 now show the same inode as those in /tmp/test1, confirming that they are the same underlying files.

5. Modify a file through /tmp/test2; the change is reflected in /tmp/test1 because both paths refer to the same inode.

Underlying mechanism

When mount --bind test1 test2 runs, the kernel hides the original directory entry of test2 and records the source directory ( test1) in a vfsmount object stored in memory. The VFS uses this object (a hash table mapping paths to mount points) to resolve any access to /test2 by redirecting it to the inode of /test1. No data is moved or duplicated; only the namespace entry changes.

Persistence

Bind mounts exist only until the system is rebooted. To make them permanent, add an entry to /etc/fstab:

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

Advanced usages

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

Read‑only bind mount : Provide developers read‑only access to configuration files by mounting with the ro option: mount --bind,ro /path/source /path/readonly. The source remains writable, while the bind‑mounted view is protected.

These techniques give administrators fine‑grained control over filesystem layout without the pitfalls of deep symbolic links.

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.

SysadminFilesystemStorage 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.