Setting up SnapRAID on Ubuntu to Create a Flexible Home Media Fileserver7 min read

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 that 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.

Zack

Zack

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

You may also like...

47 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;

    this
    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!

  11. Hildebrau says:

    Can this be setup with a bunch of USB drives of various sizes? I see you are copying the partition table from one drive to all the others. I assume that means your drives are all identical sizes.

    I have a Hodgepodge of USB drives. I want to use mergerfs as you documented, but the snapraid underlying sounds like a great idea, too. As it stands today, I lose files when a disk dies. 🙁

    Thank you!

    • Zack Zack says:

      Hello! Yes, this can certainly be setup with a bunch of USB drives in varying sizes. Also, you would just want to manually cemented the partitions like I did on the first disk rather than copying the partition table. This is still vary straightforward.

      SnapRAID will also pair well with this setup and is a good way to prevent data loss. Good luck on your adventure 🙂

  12. Dulanic says:

    OK if I reinstall the OS and need to reinstall Snapraid, yet keep the same config as before, is there a good way to do that? It looks like it goes crazy /w the make check? I kept all of the conf files etc… and have the exact same fstab, but not sure how to reinstall and “restore” the previous snapraid?

    • Zack Zack says:

      You would want to move over your /etc/snapraid.conf, have the exact mountpoints in /etc/fstab, and install snapraid. Once everything is mounted in the same locations with the same snapraid.conf, it should work just fine. I’d just do a snapraid diff to make sure everything looks good after the move.

  13. Savage702 says:

    Question for you again.

    I think I have a Sata controller going bad. It’s a 2 port card, so I moved those drives over to an old RocketRaid card that has extra ports on, and removed the 2 port card.

    The drives showed up, then kinda dropped during sync, and an error mentioned something about one of the disks being “sane”.
    I tried a few things, but no luck, so put the failing card back in, moved all back, and running a sync now, and all seems to be back to normal.

    What am I missing. I have a feeling getting an 8 port card is in my future, and removing the 2 cards I have in there now… but would like to avoid difficulty. In snapraid, you should just be able to move the drives onto another controller and all be good, right?

    • Zack Zack says:

      Great question. And, to answer it, yes, you can put a different SAS/SATA Controller in there and be fine. I would really suggest the Dell H310 used off eBay. I just bought another one used yesterday for $35 with free shipping. I’ll flash it to IT mode like my other ones using these directions.

      https://techmattr.wordpress.com/2016/04/11/updated-sas-hba-crossflashing-or-flashing-to-it-mode-dell-perc-h200-and-h310/

      • Savage702 says:

        Ok, so really, I should not be having any issues moving everything over, and my array being just fine. So something is def. up.
        The H310 card is half of what I was looking at for a standard 8 port sata card…. I just picked this one up on ebay, looks like it’s already in IT mode, so I don’t have to hassle with that.

        http://www.ebay.com/itm/122574859783

        and one of these cables
        https://www.amazon.com/gp/product/B012BPLYJC

        Fingers crossed that this is the cause of my server crashes and freezes.

        FYI – Miss reading your updates on the site here. Hope all is going well.

        • Zack Zack says:

          It should work great. You will need some 8087 -> forward breakout cables or 8087 -> 8087 to hook up to backplanes. The H310s don’t have standard SATA plugs on them.

          • Savage702 says:

            Right, pretty sure I purchased the right cable in the amazon link above? One of the people in the comments on Amazon said they also had an H310 card. Cable arrived already, just tapping my fingers on the card. Oddly enough, I think I may have fixed the issue with replacing the sata cords and reseating the cards. Everything seems to be playing nice right now (touch wood). I’ve done a few scrubs and fixes and stuff to clear out some of the errors, and SMART seems to be reassuring me the drives are ok. All turning out to be a bit of a mystery.

          • Zack Zack says:

            I’m glad you got it working. In regards to updates on the site let me know what you would like to see. I frequently updates old posts with new info, but I typically only write a new article when I’m trying something new at home. I haven’t set up anything new lately. My real job and family tend to keep me very busy:)

          • Savage702 says:

            Nothing I particularly want to see, i think I found this site when you were pushing out a lot of new info. Maybe it was a time of discovery… not sure. You’re always finding/doing something cool to read about though.

            But yeah, Family and “real” job do keep one busy. That’s why I like my stuff to just… work. LOL

      • Savage702 says:

        Wow, I’m a walking disaster with this stuff. Got the card & cable, but had a lot of issues.
        Something happened in the process, and either I didn’t get the tape on right, or the slot didn’t like the card, and during all that, one of the drives took a slight dirtnap…. which required me having to fsck the drive. Ultimately though, seems the PCIe x16 slot was preferred, and it finally worked. Not after losing the tape in one of the other slots, and possibly it shifting position in the other slots, I honestly have no idea. The picture from your link, not sure how he has that tape on there, but it doesn’t look like it’s going anywhere.

        Oh well… It’s working for now. Had a slight issue with my first sync, the sync went through but status showing a sync at 99%. My nightly scripted sync though ran successfully, and status no longer shows a sync stuck at 99%.

        I do think one of my drives is not playing nice in the array causing my issues, but SMART isn’t complaining like it has before on a flaky drive.

        Ok, I’m off to hit up our Docker section. I have questions there. I want to start getting containerized.

        • Zack Zack says:

          I’ve never had to use the tape method on any of my motherboards before. We you having issues without the tape before you applied it? Ultimately, I’m glad you got it all working. Docker is great, although it can be confusing when you first start out. I’d just start with a couple of simple containers to better understand how the ports and volumes (storage you pass to the container) work. Good luck!

          • Savage702 says:

            Yes, system would not POST, just a bunch of beep codes that changed each time I shut down and started back up again. Display would not come up on screen.

            I’ve read of issues where using onboard video and these cards might cause issues. That is my case. My mobo is getting pretty aged, but probably not as old as the H310 card? could be wrong. Biostar TZ77B.

            Also, whenever I try to work with SMART to get the overall health of the drives that are attached to that controller, I get an error. I don’t for my other drives running on the Mobo’s controller. I get the following if it’s attached to the H310.

            smartctl -d ata -H /dev/sdi

            smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.10.0-26-generic] (local build)
            Copyright (C) 2002-16, Bruce Allen, Christian Franke, http://www.smartmontools.org

            Read Device Identity failed: Invalid argument

            A mandatory SMART command failed: exiting. To continue, add one or more ‘-T permissive’ options.

          • Zack Zack says:

            That is weird. I have run these in a few different systems (some with onboard video and some without), but haven’t hit that before. I’m glad the tape solved it. In regards to SMART, have you tried a more simplified command like this?

Leave a Reply