Skip to main content

Command Palette

Search for a command to run...

(MergerFS + SnapRAID) is the new RAID 5

Home Server Storage Setup with Slack Notifications

Updated
13 min read
(MergerFS + SnapRAID) is the new RAID 5

Feeling more like watching youtube? Check out my tutorial in video on my youtube channel.

I am travelling a lot, and as you must know, travelling with external hard drives, is heavy, and mostly unsafe. If anything happens to your hard drive, you will lose all your precious travel memories. Google One and its Google Photo app are very good, but you cannot store your videos in full definition, and you have to pay a monthly fee. Not ideal when you want to store a massive quantity of 4K videos.

Because of this, a few years ago I decided to set up my own Home Server, aka NAS. I used old components from my previous PC, and others were found second-hand. I prefer to save my money to travel. 🤑

I use it mainly for storing my photos and video and my files. In this NAS I have one M2 SSD drive for the system and temporary files, and 4 disks of 2TB, in RAID5, which means that I had a failure tolerance of one drive and could use 6TB of storage. This was enough size for my usage, and it was accessible from everywhere, 24/7. The dream.

My previous RAID5 configuration

Until that one day when I could not access it. 🤯

I tried to recover the best I could, but between the fact that 2 drives were down, and LVM on top of it, because of a bad choice made a long time ago. That was impossible.

What probably happened is that one day, a disk silently crashed. I was sure I set up email notifications, but I never received anything about it. The system continued working on 3 disks. Until a few days ago when a second disk crashed, and I lost it all.

Changing the drives

Anyway, it was time for me to grieve my lost data, and be grateful for the few was hanging on another computer or with still copy of it on an SD card.

Then I put everything out and remove the 2 faulty drives. I had 2 x 12TB external hard drive laying around from when mining CHIA was a thing. I decided to use them so this repair will not cost me any additional money.

As you realised by now, I have a heterogenous drive configuration :

  • 2x2TB

  • 2x12TB

We could use it in RAID in a 2xRAID1 configuration, but we will lose half of the drives in capacity.

My thoughs about Raid solutions

On Paper, Raid is a great system for a NAS. We are losing one or 2 drives' capacity, depending if we choose RAID5 or RAID6 in exchange for 1 or 2 drive failure tolerance.

Every time you write a file in a RAID5 Array, every block of it is written in a different drive, with its parity information stored in the parity drive.

Now if like me you are losing 2 drives, well you lose everything.

Well, I assure you that when it is happening to you would love to be able to get back some data from the 2 last disks! Well with RAID you can't. 😑

Then RAID has some annoying limitations when you are on a budget :

  • Replacing disks is not trivial, you need to put your array in degraded state and rebuild it.

  • All disks must be the same size or you will just lose space, so an upgrade can be pretty salty. 💸

The solution I choose

And If I was telling you that with two different software, you could have the same level of safety, with more advantages? MergerFS and SnapRAID are not related to each other but are very complementary.

MergerFS

  • MergerFS is a simple tool that allows you to group your disks and make them appear as one. When you write a file to this group, by default the file is written on the disk with more available space, on all the branches where the relative path exists. I invite you to have a look at the extensive list of policies to find the one that matches the best.

  • Unlike RAID, the split is not made on the block level, but on the file level. That means that if you lose one disk because it is just temporarily offline, or dead, you still have access to the files that are on the others. When your lost disk is back online, the missing files will magically appear.

  • There are ways with a bit of scripting, to have an SSD cache of the recently used files (I won't cover this for now).

  • Downside: that also can bring slower read/write times, because the load is not spread across all the drives.

SnapRAID

  • SnapRAID allows you to store parity data from other drives, on 1 or 2 drives to have the same disk failure tolerance as RAID 5 or RAID 6

  • It is stored in files, so if you change of hard drive, you just have to copy these parity files to the new one.

  • You can exclude some folders if you don't want to generate parity for them.

  • Downside: The parity is not generated in real-time, you have to run a command to analyse the drives and create the parity data for the files you just added or modified.

By combining these 2, we will have a storage solution, similar to RAID, but that will allow you to recover some data even with more than 2 drives failure. Yes, the parity is not in real-time, so there is a risk that you can lose the files between the moment you add them, and the moment you launch a sync. But my home server is mainly to store non-critical files, not every second, so it will be enough for my usage.

Setting it up on my machine

I have 4 drives, 2 x 2TB and 2 x 12 TB. It is recommended to use one of your biggest hard drives for SnapRAID parity data, so I will use one 12TB drive. So I will have :

  • /mnt/data1

  • /mnt/data2

  • /mnt/data3

  • /mnt/parity1

Formating the drives and mounting them

First, on all the storage drives, we will create a new empty partition with fdisk, and format them in XFS.

# For my first drive
sudo fdisk /dev/sda
# Then use : 
# g : Create a new partition table
# n : Create a new partition on your drive
# w : Write the new table on the drive

Start over with all the other drives

Then we format them all

sudo mkfs.xfs /dev/sd{a,b,c,d}1

Then we will format them all :

Then we will print the ids of the different drives with the blkid command. We use these IDs to complete our /etc/fstab file. The goal of it is to mount automatically the drives on startup.

In the end, my /etc/fstab looks like this :

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/nvme0n1p2 during curtin installation
/dev/disk/by-uuid/b9da617f-0084-47ff-93ac-f53f91e8a838 / ext4 defaults 0 1
# /boot/efi was on /dev/nvme0n1p1 during curtin installation
/dev/disk/by-uuid/BFA1-BF33 /boot/efi vfat defaults 0 1
/swap.img    none    swap    sw    0    0

# Data drives
UUID="a7005af1-e11f-4a49-8c32-47a19711d39f"    /mnt/data1    xfs    defaults    0    2
UUID="99322a38-d6e1-45ab-96eb-21c10bbb621d"    /mnt/data2    xfs    defaults    0    2
UUID="eedaa80f-e3a9-4b89-8412-c1eeba7a9077"    /mnt/data3    xfs    defaults    0    2

# Parity drive
UUID="77bbec02-1662-4953-83c3-8f5f7367b1f0"    /mnt/parity1    xfs    defaults    0    2

I save the file and create these folders and mount all the drives at once :

sudo mkdir -p /mnt/data{1,2,3}
sudo mkdir -p /mnt/parity1
sudo mount -a

Ok, we have our drives formatted and mounted!

MergerFS

We install MergerFS with a simple command :

sudo apt install fuse mergerfs # MergerFS rely on fuse

Warning : on my Ubuntu 22.04 LTS, the package version is giving me the resonably outdated version 2.33.3-1 ( Actual version from the Github repo at the moment of writing this post : 2.34.1). If you want the latest bugfixes, install your package from GitHub releases

We go back to our /etc/fstab file and we are creating a new mount.

Here I decided to group all the drives mounted in /mnt/data* and the grouped drive should be accessible under /mnt/pool. As I want the data that I create to be spread across the drives according to their percentage of free space, I choose the pfrd policy. Feel free to choose another (see Policies). For me the line I add looks like this :

#MergerFS
/mnt/data*    /mnt/pool    fuse.mergerfs    allow_other,use_ino,cache.files=partial,dropcacheonclose=true,category.create=pfrd    0    0

We create the directory /mnt/pool and we mount everything again :

sudo mkdir -p /mnt/pool
sudo mount -a
sudo df -h

We check and you will see a new drive appeared, having the cumulated capacity of all the drives in the array! If you create one file in the pool mount, you will see it appear on one of your drives.

Cool no? 😎

SnapRAID

OK. We have one big drive, but not of the data in it is safe from one drive failing.

First, we install SnapRAID easily with :

sudo apt install snapraid

Then we will edit /etc/snapraid.conf If this file does not exist, don't worry, what has to be inside is pretty simple and we can write it ourselves.

  1. We want to specify where to store the parity data.

  2. We want to specify which data disk to use.

  3. We want to give to SnapRAID some content files. The content files are like an index of your data. It does not take that much space, so more won't hurt. You can even add one content file on the boot drive.

  4. You can add exclusions for the folders or files you don't want to have the parity generated, to save resources and space, and sync faster.

  5. Last but not least, a little option I like to add, autosave 100 specify that during a synchronisation, every 100Gb, the state should be saved. In case of a crash, or whatever happens, this will be safe.

My /etc/snapraid.conf look like this at the end:

parity /mnt/parity1/snapraid.parity
data d1 /mnt/data1/
data d2 /mnt/data2/
data d3 /mnt/data3/
content /home/thenomadcode/snapraid.content
content /mnt/data1/.snapraid.content
content /mnt/data2/.snapraid.content
content /mnt/data3/.snapraid.content
exclude /Backup/
exclude /tmp/
exclude *.bak
autosave 100

You can launch your first sync with snapraid sync it is quite fast but it also can take a while depending on how much data you have. When this command completes, your data is now safe 🎉.

Auto sync

Wait a minute, my data is safe now, but if I add or modify my files?

Indeed with snapRAID, nothing is running in the background. You have to launch the process manually. To sync it on regular basis, I used a script inspired by Zack Reed. This script was supposed to send an email when finished with a report.

From experience, email is nice, but it needs a configuration. You need to use a mail provider like Mailchimp or Sendgrid to send your email reliably, or you can also use your own Gmail account with a bit of configuration. Personally, I prefer to have my mailbox as clean as possible, so would prefer another solution: Sending a notification to a Slack channel.

Slack notifications

To receive slack notifications, nothing more simple. Go to https://api.slack.com. From there click on "Create a new App". Then choose from scratch, enter a name for it, and a workspace, and click create.

Then to be able to send notifications, go to Incoming Webhook. Active the feature, and click on the "Add a new webhook to your workspace" button. Then grant access for your app to one channel.

Once this is done, you will be given an example of a webhook that you can call using curl.

If you just copy-paste this into your terminal, you will receive it on slack directly! Perfect! 🔔

Slack is always open because it is the way my main customer decided to work. So I find it handy to be able to receive this notification here. But feel free to use the app you want, Discord or Microsoft Teams (if you are into that) also have a webhooks feature.

Automated parity script

Now that this works, let's copy the script of Zack Reed that you can find here, and adapt it to send slack messages instead. You can find my slack version on my gist right here.

This script has several variables that you can modify to suit your needs better.

  • The DEL_THRESHOLD and UP_THRESHOLD will allow you to track the number of deleted or updated files. If the number of those files is exceeding the threshold numbers, the script will stop and trigger an alert (with slack in my case). This is preventing the script to modify the existing parity in case of accidental deletions of files and can prevent encryption malware that would encrypt all your files. This way you should be able to recover your deleted or modified files to their original state. Set it as you want according to what you consider to be an unusual number.

  • The SYNC_WARN_THRESHOLD variable is here to force a synchronisation after a certain amount of warning generated by the Updated/deleted files thresholds. Imagine you are changing a lot of files on purpose and the SYNC_WARN_THRESHOLD=1, you will receive an alert. As you know that you are the one responsible for all these changes, you can just ignore them. The next time the script run, it will sync everything because one warning was already emitted.

  • You can also set up some settings for the scrubbing, so you don't verify all your data each time you run the script, but a percentage of it, thanks to :

SCRUB_PERCENT=20
SCRUB_AGE=10
  • Don't forget to set the SLACK_WEBHOOK_URL to your webhook endpoint :
# Slack
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/XXXXXXXX/XXXXXXX/XXXXXXXXXXXXXXXXXXXXXXX"

Everything set? Good, save the script, and make it executable. Launch it, just to see that everything works fine and that you receive the notification. 🔔

Then you have one last decision to make: when to call this script. Indeed, if you add a new file to your pool, it will be unprotected and you can lose it in case of a failure until the parity synchronisation is done. For my usage, I choose to call it once a night. I set up a cron task for that, and if I add a lot of pictures at once, I call it manually to feel safer.

# m h  dom mon dow   command
0 3 * * * /home/thenomadcode/scripts/snapsync.sh

But you can call it several times a day if you don't have that much data or if you consider that your data is more precious than mine. Your Server, Your Rules. 😎

Conclusion

We have now a real alternative to RAID systems. MergerFS to see all your disks as one, and SnapRAID to handle parity are working seamlessly together. The parity is handled at the file level and not at the block one, and it brings more simplicity.

If tomorrow's drive sizes increase and I want to replace my drives with bigger ones, I will just have to copy content over the new drive and make it mount at the same mount point as the old one. This is a game changer compared to having to put your RAID array in a degraded state, and rebuild it, soliciting heavily CPU and all drives, with the possibility it can create a failure while doing it.

If like me you just use your home server to store files from time to time, movies that you want to watch or content that you can re-download, this is more than enough! If you want to use this in a more intensive context, with a lot of critical files changing all the time that you can't afford to lose, then RAID is still the way to go.

PS: If you want to receive more stories like this, don't hesitate to subscribe to my newsletter or to follow me on twitter

L

Thanks for sharing, I'm also interested in creating a personal file server, for which I have a few questions

  1. Since I currently have unraid installed, the reason I chose unraid was to be able to quickly add and remove hard disks and to be able to pull the hard disks out of the host machine and swap them out to another machine to read the data on them. I'd like to ask if the two software programs in your article can be used in conjunction with each other, and if multiple hard disks are used to form a pool, is it possible to pull out a single hard disk and still read and write the data on the remaining hard disks?
  2. What is the hardware configuration of your host machine? And what system are you using to install these two software and data sharing? The hardware configuration of my current unraid host is 4 core Celeron + 4gb of RAM, is this enough to configure mergerfs and snapraid as a file server? Do these two programs have high hardware requirements?
  3. In terms of your current usage, is the data security and capacity utilization of this solution high? I have 7 hard disks of different capacities, how should I configure them? (2 x 18t, 1 x 16t, 2 x 8t, 2 x 6t). These drives are mounted on many machines, 4 on unraid and windows and macOS configured for the remaining ones. If I were to set up a file server like yours, how could my existing data be transferred? What file system do you use in your OS and in these two programs?

All in all, thank you for discussing with me, I have tens of tons of data that are very scattered and need to be managed, and I just came across your blog on the internet, and the content in it has been very beneficial and inspiring, and I was wondering if you have just recently started blogging and then where do you live and work? I am very happy to see the birth of your new baby and hope you and your family are well, I have subscribed to your blog. I am a high school student and would like to pursue your profession, best wishes and thank you!

3
C

Hi Leo ! Thanks for your comment ! Let me try to answer your questions :

  1. Disclamer here : I generaly don't recommand swapping drives out of a NAS to access the content. The role of a NAS, is to have your content accessible throught the network, or a VPN if you are not at home. From experience, removing disks and moving them on regular basis, make them fail at a point of time. This been said, MergerFS is working very well when you disconnect a disk. Even if you disconnect all but one ! The only problem is that, in my tutorial, I prefer the files to be spread on the disks depending of their capacity. But you can choose other policies, for example, if you want all the subfolders of a root folder to be in the same disk. I invite you to check the policies here : https://github.com/trapexit/mergerfs?tab=readme-ov-file#policy-descriptions SnapRAID on the other hand, is used only to generate parity data. If you remove one disk and you run snapraid sync or my script while disconnected, it will consider the files on the disconnected disk like deleted. This is why it is important to set a good DEL_THRESHOLD in my script so you don't sync in the case of a missing disk. So technicaly, the answer of your question is YES. Even if I don't really recommand this kind of usage.

  2. My machine is made of spare parts, with a cheap Ryzen 3 1200 (4 Cores), 8G of ram. It should be enough, but it depends of how much you store. MergerFS has some function to regulate memory usage and caching. SnapRAID has also some information about memory on their doc here https://www.snapraid.it/faq#mem But anyway, with my 8G of ram, everything works perfectly fine with 10T of data, and a lots of heavy docker container running.

  3. Security VS Capacity is most important quesiton of any RAID (or unraid) system. You usualy sacrifice disks for parity. The more you sacrifice, the more tolerant to failure you will be. You can in your configuration, put the parity data on one of your 18Tb disk, The rest will be available for storing your files (62TB for your files then). This makes your system tolerant to 1 disk failure. You can also choose to dedicate your 2x18Tb for parity ( 44Tb left for your files), in this case you will be able to recover your data, even with 2 disk failure at the same time. Maybe I don't understand correctly but you tell me that your drives are mounted on many machines. That implies different files systems no ? How are you currently working ? My server is with Ubuntu 22.04 LTS. All my drives are in ext4 filesystem. To transfer files from the NAS to my other computers, I use Samba.. It works quite well even if the transfer rates are not the craziest ! I also have "Resilio Sync" installed on it. It allows me to synchronise quickly files between my different computers, with offline access when I am not at home. And it is really fast. But their must be other solutions probably !

I hope I could answer some of your questions. It was a pleasure ! For your last questions. Let't say that blogging and making youtube videos, is something I would like to be able to do more, but it is hard for me to find the time to do all this. I am a French, living in Barcelona. I am a freelance tech lead, with a classical 9-5 job for a customer. But on the side of all this I try to create my own apps. My current project is Flowmodoro : https://flowmodoro.thenomadcode.tech/ The dream would be to have my own business to be able to travel the world all year long and work from anywhere. I work in development since more than 15 years, I have been CTO, created my own companies, all sorts of things.

Don't hesitate to follow me on twitter https://twitter.com/the_nomad_code and youtube (even if it is quite empty for now !) https://www.youtube.com/@thenomadcode

Wish you the best for your studies !

2
L

Thank you for your patience, I have to attend class in the morning and I can only wait until school is over now to reply to you!

  1. Your suggestion is really worth thinking about. You mentioned that as a rule of thumb, dismantling and moving disks periodically can cause them to fail. This is indeed something I have not considered, and on reflection I have realized that this is detrimental to the security of my current data storage. I am going to do as you say and keep the nas disk as a separate carrier on one machine and not remove it again. In fact, after reviewing my usage requirements again, I realized that what I actually need is a disk array with a little bit of nas functionality attached to it. My goal is to be able to access files in the same place on 2 computers and an ipad at home, I don't actually have a scenario where I need to use it away from home yet, and the network environment where I'm currently located doesn't allow me to expose the nas port (no public ip). I have one more question after reading your answer: after using snapraid and mergerfs to build several hard disks into a large pool, what should I do if I need to add hard disks to this pool or if one of the hard disks in the pool goes bad?

  2. my machine is a separate finished nas. i've looked at other people's experiences with it, and i think i still need to add another strip of ram to 8gb. i was actually considering freenas/truenas at first, but the zfs file system seems to be exceptionally demanding on ram? My data is basically long term storage oriented, with a relatively low amount of changes/writes, and only reads from time to time, which is just close enough to the snapraid usage profile. I just came across this article which describes the working conditions which are very suitable for my actual needs.

  3. Because my data are basically cold data, I think it is acceptable to take a 18t hard disk for disaster recovery. Regarding your question "Maybe I misunderstood, but you told me that your hard disk is installed on multiple machines. That means different file systems, doesn't it? How do you currently work?" This is probably a mistake in my description, because English is not my native language, and my writing "Chinese" is quite different from English, there are some situations that I can't express very well. To summarize, a. In unraid, there are 3 hard disks with xfs filesystem, which are placed in nas for a long time and not removed. 1 hard disk has ntfs filesystem, which can be removed via UD plugin github.com/dlandon/unassigned.devices/raw/master/ unassigned.devices.plg to be accessed as a removable drive. b. In Windows, I placed 2 hard drives that use the ntfs format. c. In mac I placed 1 hard drive that uses the apfs format to be used as a Time Machine disk. Usually my needs are to read and write to other ntfs disks by installing ntfs read/write software in the mac. Because of my very messy file system and disk management model, I'm thinking of reorganizing my data to make sure my data is secure and easy to manage.

I wonder if this is a site you have built yourself? The design is very modern and minimalist and the browsing performance is good. But from what I can see it seems like it automatically logs out every other day it's not online? I need to re-click to log in, so I'm not sure if that's just me or if it's a common occurrence. If this doesn't happen to others, maybe I'm using a proxy node (VPN) to access?

Lastly, thank you for taking time out of your busy schedule to share and discuss with me! Your answers have been very helpful and I've benefited greatly from them. You mentioned that you are French and I am currently living in mainland China. However, due to government policies and the strict blocking of the internet, it is very difficult for me to access knowledge effectively, and I can't do what I want to do due to the high-pressure in-scroll environment and the 6:30-22:00 study schedule six days a week. Therefore, I plan to go to university in Germany next year to get out of this high-pressure environment! See your current project is a tomato clock software? Seriously the moment I saw the description I fell in love with it because of its ui design. It's like it's called neomorphic design style and I really like it! Looking forward to your finished product.

You mentioned that you want to travel the world all year round and have your own business, and I have the same dream as you! I envision and admire the things you have done and served as CTO! I also have an outside-the-box interest in traveling, having visited very many cities in China on my own when I was 16, and traveled to Singapore and Japan just this past winter break and Lunar New Year. France is a place I've longed to visit, and the first country I visited in my life was France, which left a deep impression on me. I wish you the best of luck in your health and career and success in achieving your goals. You are also welcome to come to China to have some fun. Putting aside the political factors, there are special green mountains and natural scenic spots, as well as many humanistic buildings or museums. Especially the many low-priced and delicious cuisines over here. And you should have heard of Huaqiangbei「华强北」Electronic World in Shenzhen. It's only 100km from where I live, and I got to experience VisionPro there! I've followed you!

1
T
trapexit3y ago

Few comments:

1) The default policy for create functions is epmfs not mfs. So you might not get the behavior you expect.

2) defaults,allow_other,use_ino,hard_remove... defaults and hard_remove are both unnecessary (though harmless). You can see the official docs for a suggested default. In a future release use_ino will also be unnecessary.

3) Using the package from your distro is going to give you a reasonably outdated version. You can find packages I built of the latest releases on the github releases page.

2
C

Hi trapexit,

This is an honour to have MergerFS' author writing the first comment ever on my blog. 🙏 Thank you for your work on MergerFS, it is really useful to a lot of people.

I updated my article according to your useful commentaries and changed my create policy to pfrd because I want data to be spread across the drives.

Regardless the distro package used, my Ubuntu 22.04LTS gives me the version 2.33.3-1 which is indeed outdated(1 year old). The problem here is practicality (and laziness). Indeed by installing the Github version, I will have an up-to-date version but I will have to pay attention to all future updates and do it manually. Did you consider having your own PPA to distribute the package, so people can enjoy automatic updates with up to date code, at least for ?

1
T
trapexit3y ago

Yes, I've considered a PPA but auto updating software like mergerfs that can break a system if I screw up and introduce a bug is not something I really want to take responsibility for. I could keep it a bit out of date I guess to help lessen the likelihood.

2