MergerFS neat tricks

Trapexit’s MergerFS is awesome. He has some great documentation on the README, but I just wanted to share a couple of quick examples I use all the time. Let’s say you have a MergerFS pool mounted at /storage. You can view the current setup by using xattrs to view the pseudo .mergerfs file.

apt-get install python-xattr
cd /storage
xattr -l .mergerfs

It will output something like this. Note that there are currently 5 disks shown under the srcmounts value.

user.mergerfs.srcmounts: /mnt/data/disk01:/mnt/data/disk02:/mnt/data/disk03:/mnt/data/disk04:/mnt/data/disk05
user.mergerfs.minfreespace: 21474836480
user.mergerfs.moveonenospc: true
user.mergerfs.policies: all,eplfs,eplus,epmfs,erofs,ff,lfs,lus,mfs,newest,rand
user.mergerfs.version: 2.13.1
user.mergerfs.pid: 91089
user.mergerfs.category.action: all
user.mergerfs.category.create: eplfs
user.mergerfs.category.search: ff
user.mergerfs.func.access: ff
user.mergerfs.func.chmod: all
user.mergerfs.func.chown: all
user.mergerfs.func.create: eplfs
user.mergerfs.func.getattr: ff
user.mergerfs.func.getxattr: ff
user.mergerfs.func.link: all
user.mergerfs.func.listxattr: ff
user.mergerfs.func.mkdir: eplfs
user.mergerfs.func.mknod: eplfs
user.mergerfs.func.open: ff
user.mergerfs.func.readlink: ff
user.mergerfs.func.removexattr: all
user.mergerfs.func.rename: all
user.mergerfs.func.rmdir: all
user.mergerfs.func.setxattr: all
user.mergerfs.func.symlink: eplfs
user.mergerfs.func.truncate: all
user.mergerfs.func.unlink: all
user.mergerfs.func.utimens: all

All of these options above can be set in realtime without unmounting and re-mounting the mergerfs pool via the runtime options.

Removing Disks
The first example could be removing a couple of disks from the pool.

xattr -w user.mergerfs.srcmounts '-/mnt/data/disk04:/mnt/data/disk05' .mergerfs

This modifies the pool in realtime (no need to unmount, or stop services like samba/plex). It just works. Afterwards, we are left with this. Note that disk04 and disk05 have been removed from the pool.

user.mergerfs.srcmounts: /mnt/data/disk01:/mnt/data/disk02:/mnt/data/disk03
user.mergerfs.minfreespace: 21474836480
user.mergerfs.moveonenospc: true
user.mergerfs.policies: all,eplfs,eplus,epmfs,erofs,ff,lfs,lus,mfs,newest,rand
user.mergerfs.version: 2.13.1
user.mergerfs.pid: 91089
user.mergerfs.category.action: all
user.mergerfs.category.create: eplfs
user.mergerfs.category.search: ff
user.mergerfs.func.access: ff
user.mergerfs.func.chmod: all
user.mergerfs.func.chown: all
user.mergerfs.func.create: eplfs
user.mergerfs.func.getattr: ff
user.mergerfs.func.getxattr: ff
user.mergerfs.func.link: all
user.mergerfs.func.listxattr: ff
user.mergerfs.func.mkdir: eplfs
user.mergerfs.func.mknod: eplfs
user.mergerfs.func.open: ff
user.mergerfs.func.readlink: ff
user.mergerfs.func.removexattr: all
user.mergerfs.func.rename: all
user.mergerfs.func.rmdir: all
user.mergerfs.func.setxattr: all
user.mergerfs.func.symlink: eplfs
user.mergerfs.func.truncate: all
user.mergerfs.func.unlink: all
user.mergerfs.func.utimens: all

Adding Disks
Now, let’s show you an example to add a couple disks. Let’s say you got some nice shiny 8TB data disks that you’d like to add to your pool. You can get them all setup and mounted via /etc/fstab (including adding them to the mergerfs line there), but you don’t want to have to offline your pool right now because your kids are watching a movie in Plex. No problem, mergerfs pseudo file to the rescue!

xattr -w user.mergerfs.srcmounts '+>/mnt/data/disk04:/mnt/data/disk05' .mergerfs

The above will append disk04 and disk05 onto the end of the current srcmounts.

user.mergerfs.srcmounts: /mnt/data/disk01:/mnt/data/disk02:/mnt/data/disk03:/mnt/data/disk04:/mnt/data/disk05
user.mergerfs.minfreespace: 21474836480
user.mergerfs.moveonenospc: true
user.mergerfs.policies: all,eplfs,eplus,epmfs,erofs,ff,lfs,lus,mfs,newest,rand
user.mergerfs.version: 2.13.1
user.mergerfs.pid: 91089
user.mergerfs.category.action: all
user.mergerfs.category.create: eplfs
user.mergerfs.category.search: ff
user.mergerfs.func.access: ff
user.mergerfs.func.chmod: all
user.mergerfs.func.chown: all
user.mergerfs.func.create: eplfs
user.mergerfs.func.getattr: ff
user.mergerfs.func.getxattr: ff
user.mergerfs.func.link: all
user.mergerfs.func.listxattr: ff
user.mergerfs.func.mkdir: eplfs
user.mergerfs.func.mknod: eplfs
user.mergerfs.func.open: ff
user.mergerfs.func.readlink: ff
user.mergerfs.func.removexattr: all
user.mergerfs.func.rename: all
user.mergerfs.func.rmdir: all
user.mergerfs.func.setxattr: all
user.mergerfs.func.symlink: eplfs
user.mergerfs.func.truncate: all
user.mergerfs.func.unlink: all
user.mergerfs.func.utimens: all

You can also do all sorts of other things like change the create mode, or the moveonenospc value, or even the minfreespace option all without remounting.

Zack

I love learning new things and trying out the latest technology.

You may also like...

15 Responses

  1. codgedodger says:

    Question – I have three drives (more on the way) and I’m trying out the snapRAID with MergerFS. I have disk1 and disk2 my data drive and disk3 parity. When I see how much space /storage (where it is merging it all) it shows the total some of ALL disks which is 18TB. It should only be 10TB with the parity factored in. Is this expected?

    • Zack says:

      Hello, thanks for the comment. Can you provide a copy of your /erc/fstab? Your parity drive should not be included in the Mergerfs pool and it sounds like it is being included as result of your mount string.

  2. codgedodger says:

    This is my code in /etc/fstab I was curious about the snapRAID tutorial on the parity mounting disk. I can just remount it to /media/parity1 or something since I’ll eventually have two parity drives.

    # SnapRAID Disks
    /dev/disk/by-id/ata-ST5000DM000-1FK178_W4J1A61H-part1  /media/disk1 ext4 defaults 0 2
    /dev/disk/by-id/ata-ST5000DM000-1FK178_W4J1BXGN-part1  /media/disk2 ext4 defaults 0 2
    
    # Parity Disks
    /dev/disk/by-id/ata-WDC_WD80EZZX-11CSGA0_VKKRZ30Y-part1 /media/disk3 ext4 defaults 0 2
    
    # Mergerfs pool to /storage
    /media/disk* /storage fuse.mergerfs category.create=eplfs,nonempty,defaults,allow_other,minfreespace=20G,fsname=mergerfsPool 0 00
    
    • Zack says:

      I would suggest you create separate mountpoints for your parity and data disks.

      mkdir /mnt/data
      mkdir /mnt/parity
      

      and umount and remount your disks there.

      umount /storage
      umount /media/disk1
      umount /media/disk2
      umount /media/disk3
      chmod -R 777 /mnt/data /mnt/parity
      

      Update your /etc/fstab

      # SnapRAID Disks
      /dev/disk/by-id/ata-ST5000DM000-1FK178_W4J1A61H-part1  /mnt/data/disk1 ext4 defaults 0 2
      /dev/disk/by-id/ata-ST5000DM000-1FK178_W4J1BXGN-part1  /mnt/data/disk2 ext4 defaults 0 2
       
      # Parity Disks
      /dev/disk/by-id/ata-WDC_WD80EZZX-11CSGA0_VKKRZ30Y-part1 /mnt/parity/disk1 ext4 defaults 0 2
       
      # Mergerfs pool to /storage
      /mnt/data/* /storage fuse.mergerfs category.create=eplfs,nonempty,defaults,allow_other,minfreespace=20G,fsname=mergerfsPool 0 00
      

      Mount everything back.

      mount -a
      

      Remember… If you are using SnapRAID, you will need to update your /etc/snapraid.conf to point to these new locations.

  3. codgedodger says:

    Amazing! Thank you! Works great now!

  4. oxzhor says:

    Hi,

    How is it possible to setup an ftp account? i try to create an account on /mnt/storage but this not work.

    mergerfsPool                5857668592   66004 5857602588   1% /mnt/storage
    /dev/sdc1                   2928834296   33008 2928801288   1% /mnt/data/disk2
    /dev/sdd1                   2928834296   32992 2928801304   1% /mnt/parity/parity1
    /dev/sdb1                   2928834296   32996 2928801300   1% /mnt/data/disk1
    /dev/sde1                   2928834296   32992 2928801304   1% /mnt/parity/parity2
    

    Thanks for your feedback.

    • Zack says:

      I would suggest using SFTP or SSH instead of FTP. Both are FAR more secure than FTP. That being said, I don’t use FTP on my mergerFS pool, but SFTP should work fine (I use SSH all the time without issue).

      • oxzhor says:

        I totally agree with you that it is less secure but the problem is, i have some devices that not support sftp / ssh.
        So that is why i needed some ftp connections.

        • oxzhor says:

          I created an ftp account with vsftpd and set the path to /mnt/storage but i cannot ftp files or created any folder.

          • Zack says:

            Do you have a copy of the directions you followed? Also, what errors do you see in the logs? This is likely either a permissions issue or a misconfiguration. Have you tried setting up an FTP path not on the mergerFS pool to see if that works?

  5. shag00 says:

    Had some issues with the mergerfs options as some of them are not listed in the github write-up until I realised some of the options are in fact fuse options. Once I understood that, everything worked perfectly. I was not able to detect any noticeable improvement over mhddfs but there were certainly no drawbacks and being currently maintained is always a big advantage.

    • Zack says:

      Hello, thanks for the comment!

      What options did you have issues with? I can’t see any options in my tutorial that are not explained in the Github Readme page.

      Other things that are nice over mhddfs: the lack of an readonly volume occasionally (without patched mhddfs. Requiring the pool to be unmounted and re-mounted to remedy), many write policies vs. one with mhddfs, and faster read/write speed on decent hardware.

  6. bugs181 says:

    I know this post is kind of old but I’d really love to get this to work on OpenMediaVault 5. After doing an apt install for python-xattr, I try running the xattr command it says command not found. How do I use it now?

Leave a Reply

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