Moving a Directory to Another Disk Using Bind Mount in Linux

23 Oct 2026, 02:38:01
If the system disk is running out of space, you can move an individual directory to another disk without changing the path applications use to access it. Linux provides the bind mount mechanism for this purpose.
For example, you can move /var/lib/mysql, /var/www, or /var/log to a separate disk while preserving the original path. Applications will continue to access the directory at its previous location, while the data will physically reside on another partition.
This article explains how to prepare a disk, copy data, configure a bind mount, and ensure that it is automatically mounted after a reboot.

1. Checking Disks and Filesystems

First, identify the disks connected to the server and their mount points:
lsblk -f
Check disk space usage:
df -hTSuppose you need to move the /var/www/www-root/data/www/test.com directory to a separate disk mounted at /mnt/data.
Check the size of the source directory:
du -sh /var/www/www-root/data/www/test.comMake sure there is enough free space on the destination disk.
Important: In the following examples, /mnt/data is used as the mount point of the destination disk. Replace it with the actual path to your partition. If the disk has not been prepared yet, create a filesystem and configure its regular mount first. Do not format a disk that already contains data you need.

2. Creating a Directory on the Destination Disk

Make sure the destination disk is mounted:
findmnt /mnt/data
Create a directory where the data will be transferred:
mkdir -p /mnt/data/test.comAs a result, the original directory /var/www/www-root/data/www/test.com will correspond to the /mnt/data/test.com directory on the other disk.

3. Copying Data

Before starting the transfer, make sure that applications using the directory do not modify files during the copy process. For a website, you can temporarily stop the relevant services or put the application into maintenance mode.
To copy the data while preserving permissions, ownership, timestamps, hard links, and extended attributes, use rsync:
rsync -aHAXx --numeric-ids /var/www/www-root/data/www/test.com/ /mnt/data/test.com/Options:
  • -a — copies files recursively while preserving the main file attributes;
  • -H — preserves hard links;
  • -A — preserves ACLs;
  • -X — preserves extended attributes;
  • -x — does not cross filesystem boundaries;
  • --numeric-ids — preserves numeric user and group IDs.
The trailing / in /var/www/www-root/data/www/test.com/ means that the contents of the directory are copied rather than the directory itself as a nested directory.
Check the result:
du -sh /var/www/www-root/data/www/test.com /mnt/data/test.com
If necessary, perform an additional check for differences:
rsync -aHAXxni --numeric-ids /var/www/www-root/data/www/test.com/ /mnt/data/test.com/The -n option performs a dry run without actually copying any changes.
If the data changed during the initial copy, perform a final synchronization after stopping the application. This helps prevent discrepancies between the source and destination directories.

4. Moving the Directory Using Bind Mount

After copying the data, you need to make the destination directory accessible through the original path.
First, make sure that the applications using the directory are stopped. Then rename the original directory to preserve the ability to roll back the changes:
mv /var/www/www-root/data/www/test.com /var/www/www-root/data/www/test.com.oldCreate an empty directory to serve as the mount point:
mkdir -p /var/www/www-root/data/www/test.comPerform the bind mount:
mount --bind /mnt/data/test.com /var/www/www-root/data/www/test.comThe contents of /mnt/data/test.com are now accessible through /var/www/www-root/data/www/test.com.
Verify the result:
findmnt /var/www/www-root/data/www/test.com
Make sure the files are accessible:
ls -lah /var/www/www-root/data/www/test.com
If everything works correctly, start the previously stopped services and check that the application is functioning properly.
Note: After the bind mount, the original contents of /var/www/www-root/data/www/test.com.old remain on the system disk and continue to occupy space. Do not delete them until you have verified that the application works correctly and confirmed the integrity of the data.

5. Configuring Automatic Mounting via /etc/fstab

The mount --bind command remains in effect until the directory is unmounted or the system reboots. To restore the mount automatically, add an entry to /etc/fstab.
Open the file:
nano /etc/fstabAdd the following line:
/mnt/data/test.com /var/www/www-root/data/www/test.com none bind 0 0Here:
  • /mnt/data/test.com — the source directory on the destination disk;
  • /var/www/www-root/data/www/test.com — the path through which the directory will be accessible to applications;
  • none — the filesystem type is not specified for a bind mount entry;
  • bind — the mode used to mount an existing directory;
  • 0 0 — disables the standard dump utility and filesystem check for this entry.
Important: The destination disk must be mounted before the bind mount is activated. If /mnt/data is mounted through a separate entry in /etc/fstab, place that entry before the bind mount entry. If necessary, use systemd dependencies to ensure the correct startup order.
Verify the configuration:
findmnt --verifyThen try mounting the filesystems listed in /etc/fstab:
mount -av
If there are no errors, check the mount point:
findmnt /var/www/www-root/data/www/test.com

6. Verifying the Configuration After a Reboot

After configuring the mount, make sure the directory is mounted automatically.
A server reboot is not required for the initial check: you can verify the configuration and run mount -av. However, before rebooting, make sure the destination disk itself is configured to mount automatically.
After a scheduled reboot, run:
findmnt /mnt/data
findmnt /var/www/www-root/data/www/test.com
df -hT
Make sure that /mnt/data and /var/www/www-root/data/www/test.com are mounted and that the application is working correctly.
If the bind mount is missing, check the system journal:
journalctl -b --no-pager | grep -Ei 'mount|/var/www/www-root/data/www/test.com|mnt/data'A common cause of this problem is that the destination disk is not mounted or is mounted after the bind mount is attempted.

7. Removing the Old Copy

After successfully verifying the application and confirming that all required data is accessible from the new disk, you can remove the backup of the original directory:
rm -rf /var/www/www-root/data/www/test.com.oldWarning: The rm -rf command permanently deletes the specified directory. Before running it, carefully verify the path and make sure you no longer need the backup.
Before deleting the old copy, it is advisable to check file permissions, ownership, application functionality, and the availability of a current backup.

8. How to Undo a Bind Mount

If problems occur after the transfer, you can restore the original directory.
Stop the applications using /var/www/www-root/data/www/test.com and remove or comment out the corresponding entry in /etc/fstab.
Then unmount the directory:
umount /var/www/www-root/data/www/test.comIf the original directory /var/www/www-root/data/www/test.com.old still exists, restore it:
rmdir /var/www/www-root/data/www/test.com
mv /var/www/www-root/data/www/test.com.old /var/www/www-root/data/www/test.com
After that, start the applications and check that they are working correctly.
Do not delete the data on the destination disk until all checks have been completed. If umount reports that the filesystem is busy, identify the processes using the directory, for example:
fuser -vm /var/www/www-root/data/www/test.comIf necessary, stop the relevant processes gracefully and try unmounting the directory again.

Conclusion

A bind mount allows you to move a directory to another disk while preserving its original path for applications. This is useful when you need to free up space on the system partition without changing application configurations.
To perform the transfer safely, copy the data while preserving file attributes, verify the result, configure the bind mount, and add an entry to /etc/fstab. Before deleting the original files, make sure the application works correctly and the directory is mounted automatically after a reboot.