Linux Tips I Wish I Knew Long Ago – Mount bind

Mount –bind is one of those tricks you need when symlinks are not good enough and you need the same information in two locations. It basically mounts a disk or partition in an additional location. It doesn’t come up too often but every now and then it is key piece of knowledge.

Take this scenario for example: You have a webserver and a developer who needs regular access to the files, the data is on a separate disk that is mounted at /var/www/html but you don’t want to symlink his home directory there and you don’t want to setup some other way for him to access the information (like ftp). Simple solution, use mount –bind to have his public_html directory point at /var/www/html.

mount --bind /existingdir /newdirlocation

Another scenario that recently came up had to do with an NFS server. There was computing cluster of machines that all mount their data from a single NFS server at a location like /data. The NFS server was also part of the compute cluster but the NFS share was not at /data. The previous admin worked around this issue by placing a series of symlinks from the /data area into the NFS server area. The problem was that when the machine rebooted the symlinks caused loops that prevented the disks from being mounted in the correct way. However mount –bind did not leave broken symlinks on reboot so it solved the need of having the filesystem match the other nodes as well as not leaving remnants on a reboot that prevented the system from booting to the desired state.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.