- The Problem: Managing multiple drives dedicated to media for my Plex server is annoying
- The Solution: using
mergerfs, a union file system to “merge” the drives and make storage management easier
And now for the sob story, that no real
cooking tech blog can go without:
Since my homelab is running on a budget, I don’t quite have the resources to create a proper RAID setup. The drives are being added one by one when the previous one got filled, and each physical hard drive is configured as a separate virtual drive in PERC. This is incredibly dumb, not at all safe to do, and I am absolutely certain that at one point will bite me in the ass. But unfortunately I also don’t have ~2000€ to drop to get all the hardware needed to back up the ~12TB of data I have and reconfigure the whole thing properly, so I mitigate the risk by not keeping anything important on these drives.
This also created a bit of a headache with incoming media: keeping it organized between the drives was becoming a hassle I didn’t quite have the patience for. I looked into a couple of different solutions, then decided to go with
mergerfs, a union filesystem. I had a handful of reasons for picking it: it allowed the merging of drives with data on them, adding new drives on the fly, and differently sized drives without limiting them.
And most importantly, it also had the most compehensive answer to “how do I set this up?” on stackoverflow.
The syntax is simple:
mergerfs [options] <srcpaths> <destpath>
The drives need to be mounted first, then you can combine them using their mountpoints separated by colons.
mergerfs /mountpoint1:/mountpoint2:/mountpoint3 /mergedmountpoint
The tool also has a number of options. I’ll only go through the ones I’ve used, but both the
--help flag and the
entry for it explains the other options well.
The syntax I ended up using is:
mergerfs -o defaults,allow_other,use_ino,category.create=mfs,moveonenospc=true,minfreespace=1M /drv1:/drv2:/drv3:/drv4 /merged
The resons for them are:
defaults– it auto-uses a handful of other options that optimizes performance
allow_other– allows other users to access the filesystem
– allows mergerfs to generate inode values. This way linked files will share inode values, preventing the inode monster from eating up free space
category.create=mfs– sets the policy to mfs (most free space). The exact details on this are a bit outside of the scope of this writeup, but this can help avoid a couple of issues that can stem from cross-device linking. There are more details on this on the mergerfs repo for a quick explanation.
moveonenospc=true– enables the moving of files to a different drive if the original write fails with “No space left on device”. I think this is redundant when using mfs, but I’ve set it just in case.
minfreespace=1M– The minimum space value used by the create policies for filtering. The default is 4G, which I found a bit too high for my use-case
After running this, the separate unioned drives were be shown under the new, merged mount point.
Header image credit: Freeimageslive