Comments
You can use your Mastodon account to reply to this post.
Tuesday, April 11, 2023
Reading time 4 minutes
MergerFS is a delight for all those of us who, for one reason or another, need to unify several hard drives into a single directory. This tool is only available for Linux, although for Windows there are other applications that do the same. This software allows creating a virtual file system (using fuse for it), integrating all the contents present on one or more hard drives. This gives us a directory containing all the files present on our disks, which makes things much easier when it comes to maintaining order between 2 or more units. Among its main features, it allows adding content to your disks following various policies when creating files or folders. All of this is explained in its documentation, although here I’ll simply detail the way I use it.
In Debian, MergerFS is available in the package repositories, although it’s more advisable to download the deb package from its GitHub repository, as it will always be in the latest version. Being a package in DEB format, it’s just a matter of downloading it, using curl or wget, and installing it with dpkg, with a couple of commands similar to the following:
wget https://github.com/trapexit/mergerfs/releases/download/2.35.1/mergerfs_2.35.1.debian-bullseye_amd64.deb
sudo dpkg --install mergerfs_2.35.1.debian-bullseye_amd64.deb
If during installation, dpkg complains about some dependency problem (for example, if components for fuse are missing), it’s easy to install the missing packages with this command:
sudo apt-get install -f
And basically that’s all you need to have MergerFS installed on the system. It’s a good idea, anyway, to update the software from time to time, as it constantly receives improvements and optimizations.
There are many ways to use this software, most of them are collected in the documentation, which is found in the project repository. Basically you can execute the tool directly from the command line, specify its configuration in the fstab file, or run it with systemd. I particularly think it’s easier to configure the fstab file to mount the file system when the operating system starts, so that’s what I ended up doing. It’s important to note that the hard drives to be unified must already be mounted by the time the file system is created, so naturally they’ll also have to be configured within the same fstab file.
Before continuing, there are two things to keep in mind about how we’re going to configure mergerfs. The file cache and the file creation policy. The former will help us if we have an application that uses SQLite databases (like some torrent clients), or writes files atomically (like apps for downloading things, for example). If so, we need to enable mmap support, therefore, activate the file cache. If we don’t need that, then we can work without the file cache. As for file creation policies, MergerFS supports an interesting variety of things when it comes to creating a file within the directory where the unified disk system is. That is, it can place all files on a single hard drive until it fills up, and then continue with the other; it can distribute files in a balanced way among the disks, so that all fill up in the same proportion, and 18 other different configurations. In my case, I’m clear that I don’t need mmap support, and also the policy to use for creating files, which is “mfs” (creates files on the disk that has the most free space). So, my fstab line looks very much like this, also taking into account that all my disks are mounted in /mnt/drive*, where * is the unit number:
/mnt/drive* /mnt/storage fuse.mergerfs defaults,nonempty,allow_other,use_ino,cache.files=off,moveonenospc=true,category.create=mfs,dropcacheonclose=true,minfreespace=250G,fsname=mergerfs 0 0
This will create, on the next operating system restart, the file system called Mergerfs. The application will combine all the disks that are mounted in a directory that begins with /mnt/drive, and the result can be seen in the /mnt/storage directory. When writing files it will take care of filling the disks proportionally. If more disks are added later, they’ll only have to be mounted within /mnt/drive* to be automatically included in MergerFS.
Finally, you have to remember something obvious. MergerFS is not a raid, and raid is not the same as backup. So it’s always a good idea to keep everything considered important or of high value stored in more than just one location.
NAS Server Hard drive mergerfs