Easy storage expansion with mergerfs & bind

So this is a nice easy trick I use to expand my storage on Linux in two major steps. Pre-req is to run this as root.

mergerfs

mergerfs is a unionfs filesystem that allows you to add disks to a pool under a directory that is seen as one disk on a given mountpoint.

In my case I mount my drives under /media/drives. I looks something like this:

Each disk is mount under a given numbered folder. The cool thing is that you add external network mounts under the structure like for instances SMS, NFS or cloud storage.

After the folder structure is defined the next steps is to mount your drives on /etc/fstab (I won’t touch here the mount options). This is how I have mine:

Ok, now mergerfs, easy-peasy on Debian/Ubuntu based ditros. This includes raspbian BTW 🙂

apt update
apt -y install mergerfs

Although this is the easiest way to install mergerfs the recommended method is always to use the most updated version hosted on github. Compiling and installing mergerfs is not difficult.

Final steps are to edit /etc/fstab and mount the mergerfs filesystem. I have mine under /mnt/virtual.

mkdir -p /mnt/virtual
nano /etc/fstab

then add the following to /etc/fstab:

#MergerFS
/media/drives/* /mnt/virtual fuse.mergerfs defaults,allow_other,func.getattr=newest,use_ino,minfreespace=5G,fsname=USBPool 0 0

and now mount the /mnt/virtual filesystem:

mount /mnt/virtual

I have 7 disks that are in 1TB in size. Check it out:

mergerfs has several mount options. It is a very well documented project and I strongly suggest checking their documentation.

bind

Mounting filepaths using bind is a quick and easy way of mounting a path on another path in your filesystem. In my case it comes quite handy given my home server is an ODROID-N2.

This nifty singleboard computer is fast, silent and energy-efficient. The problem is that it’s main root storage although it is based on a very fast eMMC drive is only 32GB in size. This obviously limits the amount of data I can store with it. I use Nextcloud as my personal cloud/backup platform for myself + my family and 32GB is far from enough.

This is where bind comes in to save my day. I setup bind on my /etc/fstab so my server mounts my nextcloud data folder on boot. Check it out:

So now I can make use of the 7TB of storage I have on my pool with mergerfs.

Another example of what you can do with bind is for example if your /var/log folder is running out of space.

mv /var/log /mnt/virtuak/var_log
mkdir /var/log
mount -o bind /mnt/virtual/var_log /var/log

The example above uses the cli to mount the paths. If you need this to be a permanent fix I strongly suggest adding the bind mount to the /etc/fstab file.

Good SysOping/coding!

Leave a Reply

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