How to use bind mounts in linux
Have you ever dealt with a system that wasn’t partitioned properly when it was built and now it has gone into production? You’ll probably be hard pressed to find the time and patience to rebuild the system any time soon. Luckily there is a way to step around many of the limitations of a poorly partitioned system. How? With bind mounts.
Bind mounting is quite simple. Instead of mounting a block device (formatted with a file system) into a particular path you are mounting one path into another path.
For example: Let’s say you have a small /var but a very large /opt partition and you need additional space for your growing log files.
First, shut down the services writing to log files, then…
mv /var/log /opt/var_log mkdir /var/log mount -o bind /opt/var_log /var/log
You will now see this reflected when running the mount command:
# mount | grep var /opt/var_log on /var/log type none (rw,bind)
At this point you are ready to restart the previously stopped services.
If you want this to persist across reboots, you’ll just need to update your /etc/fstab with the bind mount as well.
# /etc/fstab /opt/var_log /var/log none bind 0 0
And there you have it! Its not beautiful, but it will help you keep the lights on until you can get a long-term fix in place.