Setting up SnapRAID on Ubuntu to Create a Flexible Home Media Fileserver

Home Media Fileserver

Home Media Fileserver in Norco 4224 Case

I have SnapRAID setup to create a super flexible, reliable bulk media server. I have used SnapRAID for years across numerous versions of Ubuntu and a plethora of hardware. SnapRAID has been so reliable that I have updated hardware four times since I originally set it up, migrated through many versions of SnapRAID, added many data disks, added parity levels, and replaced disks all without issue.  All the while, it’s been super flexible and an awesome way to manage my bulk media.  I currently have a ridiculously over the top server than you can read more about here.  On it I use three parity disks and 21 data disks.

The first thing I do after any new install is update the system, and install my base packages.

After the reboot, let’s keep installing the packages we will need to build SnapRAID.

Finally, let’s install it.

Next, let’s cleanup.

Next, I’m going to partition the disks, so I need to grab a couple packages.

Let’s partition one, and copy the structure to the other disks.

Now, we will make a place to mount the disks. I mount them via /etc/fstab labeled by their device type and serial number as seen beloew. This makes the disk easier to identify in the event of a disk failure.

Setup a filesystem on each data disk (Note, I’m reserving 2% of the disks space so that the parity overhead can fit on the parity disk). You can set the reserved space to 0% if your parity disk(s) are all larger than your data disks (i.e. you have 6TB parity disks and 5TB data disks).

Put a filesystem on the parity disk (here I’m reserving 0%, or letting it use the whole disk for parity).

Get the device type and serial numbers like this, then add them to your /etc/fstab.

It should give you output like this.

You use the above to add them to /etc/fstab

It should look something like this.

As you may be able to see, the above shows the type of connection, in this case SATA, the Manufacturer of the disk, the part number of the disk, the serial number of the disk, and the partition we are using from the disk.  This makes indentying disks in the event of a failure super easy.

Mount the disks after you add them to /etc/fstab

Next, you’ll want to configure SnapRAID.

This is how I configured mine

Next, we need to create the path that we mentioned above for our local content file.

Once that’s complete, you should sync your array.

Since moving to SnapRAID 7.x, the above mentioned script no longer works. I have revised the script to accommodate dual parity, and to integrate the changes in the counters.

Finally, I wanted something to pool these disks together. There are four options here (choose your own adventure). The nice part about any of these is that it’s very easy to change later if you run into something you don’t like.

1. The first option is mhddfs. It is super easy to setup and “just works”, but many people have run into random disconnects while writing to the pool (large rsync jobs where causing this for me). I have since updated my mhddfs tutorial with some new FUSE options that seems to remedy the disconnect issue. mhddfs runs via FUSE vs. a kernel driver for AUFS, so it’s not as fast as AUFS and it does have more system overhead.

2. The second option is to use AUFS instead. The version bundled with Ubuntu has some weirdness with deletion and file moves with both it’s opaque and whiteout files. It also does not support exporting via NFS.

3. The third option is to use AUFS, but to compile your own versions to support the hnotify option and allow for export via NFS. This is where I landed for a few years after trying both of the above for many months/years.

4. This is what I use Finally, a solution that performs well and is easy to use. MergerFS (the solution I’m currently using). This is a FUSE based solution, but it’s fast and has create modes like AUFS. It’s also easy to install and requires no compiling unlike AUFS to get it working. This is what I use now, and it’s great and actively developed.

After choosing one of the options above, you should now have a mount point at /storage that is pooling all of your disks into one large volume. You’ll still want to setup a UPS and SMART monitoring for your disks. Another thing I did was write up a simple BASH script to watch my disk usage, and email me if a disk gets over 90% used, so I can add another disk to the array.

Next, I would strongly suggest you read my other articles to setup email for monitoring, SMART information monitoring , spinning down disks, setting up a UPS battery backup, and other raid array actions. Being able to cope with drives failing useful, but it’s nice to know that one has failed and be able to replace it too.

Updating in the future
You may wonder…”Hmm, I installed this fancy SnapRAID a while back, but the shiny new version of SnapRAID just came out, so how do I update?” The nice thing about SnapRAID is that it’s a standalone binary with no dependencies, so you can upgrade it in place. Just grab the latest version, untar, and install.

You can check your version like this.

Other Items:
If you would like to have encrypted SnapRAID disks, the following will go through that.



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

You may also like...

32 Responses

  1. Dave Dave says:

    Awesome been looking for someone todo a more current SNAPRAID follow up. Thanks!!!

    • Zack Zack says:

      I’m glad you found this helpful Dave. I just migrated this content from my old site, though, so this has been an article I have updated for a couple of years now. Please let me know if you have any questions.

  2. Joe says:

    your first set of commands didn’t migrate over well;

    apt-get update && apt-get dist-upgrade -y && reboot

    should be
    apt-get update && apt-get dist-upgrade -y && reboot

  3. Joe says:

    ack it looks like my amp; amp; didn’t get written correctly in my post.

  4. oxzhor says:

    Hi Zack,

    Great post! normally i work with CentOS but you done nice work on Ubuntu 16.x.
    I buy a old Dell R510 and put a perc H310 into it and will follow your post to setup a backupserver.
    I keep you updated over how the project will go :).

    Keep the good work up!

  5. Savage702 says:

    Ok, got my first failing drive, next steps?

    The following warning/error was logged by the smartd daemon:

    Device: /dev/sdf [SAT], 2 Offline uncorrectable sectors

    Device info:
    WDC WD30EFRX-68EUZN0, S/N:WD-WMC4N0455643, WWN:5-0014ee-0ae519cc4, FW:80.00A80, 3.00 TB

    For details see host’s SYSLOG.

    I guess turning off Plex sync/updating and stopping new downloads, etc. Then just as simple as replacing drive, setting new drive up, updating config and running a sync?

    • Zack Zack says:

      Hello. Sorry to hear you have lost a disk. Your first steps are correct, I’d stop plex from updating and stop downloading. I would format the new disk and temporarily mount it somewhere for the time being.

      Since the old disk is still available, I would use rsync in a tmux session to transfer the data to the new disk from the old disk. Here is an example. Note the trailing slash. This copies the whole disk to the other one.

      Once this is finished, I would mount the old disk and mount your new disk in its same location. Next, you will want to get the replacement disk setup /etc/fstab so it mounts after a reboot. So, change the device name to match the new name.

      Finally, run a snapraid diff. At this point is should mention that theven UUID for the real ed disk has changed and moves won’t be optimal. As long as the number of deleted and updated files looks good, run a sync.

      Once that’s done, you can remove the failed disk and startup your shutdown services.

      For bonus points, check and see if your failed disk is under warranty. If, so submit and RMA and save the new disk that they send you as a backup disk.

      Let me know if this makes sense.

      • Savage702 says:

        Ok, makes sense, and thanks for that. I’m sure doing the rsync is better/easier/faster than letting it recover from parity. I ran a few status checks and tried a fix, 2 blocks with IO errors. I like these steps though, all the media will remain available for the kids today while this is doing it’s thing.

        I’m going through my stack of drives and making an inventory of which one is where in the stack, something I should have labeled 3 years ago when setting up. Better late than never. In doing this, I saw that I’m about 3 months out of warranty on my 3TB Red Drives… a little longer for 3 of them that I originally started with! (BOOO!!!)

        For 3 years, I’ve had a 3TB Red on standby, so broke that out of the static bag to realize it’s a re certified drive. 😐 Not thrilled about that, but will have a spare on hand by next week. I’ll make sure this time to get the drive all formatted and ready so it will be a much more plug and play scenario.

        • Zack Zack says:

          Sounds like a good idea. One other thing I always like to do with new drives (especially re-certified) before putting them into service is stress test them. I use something like this (this will destroy all data on the disk, so make sure it’s the right one).

          In your case where you have a missing disk, I’d just throw in the re-certified disk and get everything working. I’d stress test and format your new replacement disk when you get it prior to putting it into service.

      • Savage702 says:

        This can be safely ignored and just move along, correct?

      • Savage702 says:

        Thank you! I think I’m there, although it took all day to rsync the drive.

        WARNING! UUID is changed for disks: 'd4'. Move operations won't be optimal.

        134391 equal
        2 added
        0 removed
        187 updated
        0 moved
        0 copied
        0 restored
        There are differences!

  6. phuriousgeorge says:

    Found a little boo-boo in the instructions that made me have to double-back a little:

    cp ~/snapraid-10.0/snapraid.conf.example /etc/snapraid.conf

    Thanks for all your useful information you blog about, it’s really easy to follow and has done wonders to help me!

  7. oxzhor says:

    If you want to use two parity disk you can add it like:

    # Parity Disks
    /dev/disk/by-id/ata-hdd1-name-part1 /mnt/parity/1-parity xfs defaults 0 2
    /dev/disk/by-id/ata-hdd2-name-part1 /mnt/parity/2-parity xfs defaults 0 2

    thx for your feedback.

  8. twhitmer34 says:

    HI — First thank you so much for you blog, it helped me setup Snapraid for my media server

    I just got my first drive (soon to be) failure (SMART reporting bad sectors), it was my parity disk, I have requested an RMA and will be getting my new replacement drive soon. I was wondering if you could help me with my specific drive replacement

    my /etc/fstab looks like the following:

    and my snapraid conf is the following:

    my issue is that i dont have any more sata connectors to add the new drive without removing a drive. so i was thinking that i would
    1. comment out the parity disk is /etc/fstab with a “#”
    2. shutdown pc
    3. remove old drive parity drive
    4. add new replacement parity drive
    5. startup computer
    6. (the current parity drive is /dev/sda1)

    7. mkdir /media/disk1/ (so i dont have to update my snapraid.conf)
    8. mkfs.ext4 -m 0 -T largefile4 /dev/sda1 (again assuming that the new drive is also going to sda1 like the old drive was — not sure this is true?)
    9.blkid /dev/sda1 (to get new disk UUID)
    10. update /etc/fstab parity line with new uuid and un-comment it out.
    11. restart
    12. run “snapraid -F snyc” (to force the making of a new parity file)
    13. all done and should be all good again.

    • Zack Zack says:

      Hello, thanks for the question. Here is what I would do, if the old parity disk is still working…
      1. Shutdown the server
      2. Temporarily remove one of your data disks and add your replacement disk in it’s spot
      3. Boot from a live linux CD run it in try Ubuntu mode.
      4. Clone the old disk to the new disk (MAKE SURE YOU ARE USING THE CORRECT DISKS HERE!)

      This will bring over the partition table and as much of the parity file as is recoverable. It will also clone the UUID so, it should just work in place of the old disk.
      5. Once complete, I would shutdown the server again, and remove the old parity disk
      6. Replace the data disk that you removed early, and boot into the OS.
      7. Run the fix option to check the parity.

      8. Once complete, you should be good to go.

      This way you keep your old disk as a backup the entire time and don’t have to go through creating partitions, changing /etc/fstab, etc.

      • twhitmer34 says:

        Thanks — completed the ddrescue command and it seemed to work fine (3TB in 15hrs and no errors). I ctrl-c out of the snapraid fix -d parity (looked like it was going to take like 6 hrs)? I am not sure what it was “fixing” since i ran a snapraid snyc command before i did the ddrescue command.

        Can i just run a snapraid sync again? what does the fix – d parity actually do? thanks again

        • Zack Zack says:

          The fix will just make sure that your parity file is actually complete and properly checksums. I would suggest running it as an insurance policy. The parity is what is protecting your data, so it is important that it’s valid 🙂

  9. Savage702 says:

    Good Morning Zack,

    Question for you, as always. 🙂
    In one of the older versions of this guide (which I used and continue to configure my setup on), in Snapraid.conf, you only listed 2 content disks out of the 4, like so:

    I noticed last night looking over this again as I was adding a new drive to my array, that you list all disks.
    Is this something I should modify/update on my config?

    Also, older instructions again, when you setup the filesystem, you didn’t reserve the 2% space or do the largefile4, instead it was simply:

    I’d imagine I’d want all my drives to follow the same format vs changing things up, correct? I seem to recall the disk space reservation was handled elsewhere back then, but maybe not. ?

    • twhitmer34 says:

      i have a similar question — (currently “comment is awaiting moderation”). i am about to lose my parity drive — wondering the steps to to take, and like you used a previous version of this tutorial. My issue is that I have no more sata connectors to use (must take out a drive to add one). since my issue is sorta specific i tired the contact tab on the website but it “failed to send”. Any help is much appreciated

    • Zack Zack says:

      Hello 🙂 Yes, I have added content files on all of my data disks at this point. They are not that big and it provides more content files to checksum to make sure everything is okay. To add them to more disks, just add more content lines for each disk. As long as you have the space, it’s worth it.

      In regards to partitioning, if you already have data on the disks, I wouldn’t worry about it too much. Meaning that I wouldn’t format them and start over. The largefile option is totally worth it. It limits the number of files you can create on the disk in exchange for fewer inodes. I also like saving a little space with the reserved space option, but it won’t be honored if the root user is the one that’s writing the files. If you are using mergerfs with the minfreespace option, that should prevent overfilling anyways.

  10. Dulanic says:

    Love this guide, thank you for posting this for v11. I keep running into a compile error… any ideas as to how I may correct this?

    checking for gcc… gcc
    checking whether the C compiler works… no
    configure: error: in `/root/snapraid-11.0′:
    configure: error: C compiler cannot create executables

    • Dulanic says:

      Update: Found this was the issue. May want to add in case others see this problem. FYI, I am running Linux Mint 18.1 which is based on Ubuntu 16.04.

      Had to run apt-get install gcc-multilib

      • Zack Zack says:

        I’m glad you got it figured out. I’ve never had an issue with compiling this with just gcc on 16.04 (this is what I currently run). I would suggest for most users to just install the build-essential package, as that will give you all of the compilers that are typically needed. Thanks for the post!

Leave a Reply