DIY FreeNAS based system

Introduction

This time I won’t be writing about software related stuff but about building a Network-Attached Storage (e.g. NAS) based on FreeNAS.  A family member asked me if I would be able to build a custom NAS system for him.  As some years have already passed by since  my last PC build, I wasn’t up-to-date with the current available hardware and I didn’t have any knowledge of NAS setups what so ever.

The requirement were:

  • the data should be stored redundantly;
  • it should be easily recoverable in case of failure;
  • it should backup data to an external usb drive;
  • the system should be easy to maintain;
  • the system should have a low power consumption;
  • the system should be quiet;
  • there should be a notion of users and permissions with dedicated folder;
  • it should be able to recover unwanted modifications on data;
  • and if possible run a mail server on top of it.

Thanks to the help of some people, and especially CiPHER, at the tweakers.net forum, I was able to determine the setup I was going to assemble.

Components inventory

NAS PC Components

Here is the list of the components shown above:

Assembling the compontents

Here’s how I proceeded for assembling the NAS components:

  1. Open the side panel of the cooler master.
  2. Mount the 4 metal hex nuts, which are supplied with the mini-tower, so that they match the Mini ITX Form Factor on which the motherboard will be mounted.
  3. Put the I/O Panel Shield on the back of the motherboard and fix it on the case.
  4. Now we’ll put the 2 memory modules in the memory slots.
  5. Wire the picoPSU peripheral extension cable to the picoPSU.
  6. Wire the picoPSU on the ATX power connectors (24-pin and 4-pin connector) of the motherboard.
  7. Wire the cables of the case regarding power led, HD led, power switch and reset switch to the motherboard.
  8. Wire the front panel USB cable of the case to the motherboard.
  9. Wire the HD audio interface cable of the case to the motherboard.
  10. Mount the SSD in the floppy drive bay.
  11. Mount the 3 HD’s in the hard drive bays.

The result of it should look like the picture shown below.

Assembled PC Compents

Running rsync via cron job

One requirement was that a backup should be made from the ZFS pool offsite to an external USB drive. To achieve that I wrote a script based on an example that I found on the freenas forum.

  1. From what I understood on a blog about Freenas is that it loads all it’s stuff from the “/conf/base”-directory in a RAM disk and maps it to the standard Unix installation structure. This means that every modification you made will be lost after a reboot or shutdown. To make those modifications permanent, we have to mount the volume so that we can write on it. To do that execute the following in the shell:
    mount -uw /
  2. Now we are going to write a shell script containing the logic for rsync-ing the ZFS pool to an external USB drive:
    nano /conf/base/var/backup.sh
  3. Once in nano, or any other editor you whish to use, enter the following:
    #!/bin/bash
    partition=/dev/$1
    origin=/mnt/$2
    target=/mnt/backup
    
    backup() {
    	if [ -e ${partition} ]; then
    		/bin/mkdir -p ${target}
    		/bin/chmod 777 ${target}
    		/usr/bin/logger "Mounting USB Device named ${partition} to ${target}..."
    		/sbin/mount -t ext2fs ${partition} ${target}
    		/usr/bin/logger "Mounted USB Device named ${partition} to ${target}"
    		/usr/bin/logger "Rsyncing ${origin} to ${target}..."
    		rsync -av --progress ${origin} ${target}
    		/usr/bin/logger "Unmounting USB Device named ${partition} from ${target}..."
    		umount ${target}
    		/usr/bin/logger "Unmounted USB Device named ${partition} from ${target}"
    		/bin/rm -r ${target}
    	else
    		/usr/bin/logger "USB Device named ${device} not present"
    	fi
    }
    
    backup;
    
  4. Make sure the script is executable:
    chmod 777 /conf/base/var/backup.sh
  5. Set the base volume back to read-only:
    mount -ur /
  6. Exit the shell by typing “exit” in the shell and hit the reboot option.

Once the FreeNAS system is rebooted, you should see via the shell that the script is located under /var/backup.sh. Now let’s create a cron job via the web interface of FreeNAS. As you’ll could have noticed when typing the script, there are 2 arguments:

  • the first argument specifies the device name of the usb device (without the prefix /dev)
  • the second argument specifies the name of the ZFS pool (without the prefix /mnt)

Let’s consider as an example that the full path to the device would be “/dev/da1s1” and the full path to the ZFS pool would be “/mnt/dablomatique”, the script have to be executed as follow:

/var/backup.sh da1s1 dablomatique

That’s it for the moment. If there are any suggestions, they are always welcome.

One thought on “DIY FreeNAS based system

  1. Enigma says:

    How fast is this system? And can you run Sickbeard?

Leave a comment

Erik Wramner

Tips and tricks

Java Enterprise Development

Java / Oracle SOA blog

Java Enterprise Development