Thursday, December 6, 2012

Switching from FreeNAS to ZFS Mirror on NAS4Free

My FreeNAS server has been running without problems for almost 3 years now. Although I put in another CPU and PSU, overall the machine is still the same. The server consists now of the following components:

CPU: AMD Sempron(tm) Processor LE-1200
Motherboard: ASUS M3N78-EMH HDMI AM2+/AM2 NVIDIA GeForce 8200 Micro ATX
Memory: 1GB Kingston (kit of 2x512MB) KHX6400D2LLK2_1G & 1GB Geil module
Harddisk: 1TB Samsung HD103UJ
PSU: Silentmaxx MX460

It is still scheduled to start at 10:30 and stop at 23:30 to save costs of electricity.

NAS4Free:
But I realised that with one harddisk, all my data would be gone if it fails. So I started reading about different possibilities for a redundant setup. The first thing that I needed to do, was to update the software. Currently running FreeNAS 0.7 to be updated to either FreeNAS 8 of NAS4Free. So I started up VirtualBox and installed FreeNAS 8. I really tried, but I didn't like the user interface and chose NAS4Free.

Redundant harddisks setup:
I decided to use ZFS, but before setting up the new system with NAS4Free, I tested it with VirtualBox running 64 bits NAS4Free. The setups for ZFS RAID Z1 (similar to Raid-5) and ZFS Mirror (similar to Raid-1) are similar. Below I show the setup for ZFS RAID Z1.

Setup in VirtualBox:
To be able to run NAS4Free in VirtualBox, I created a small virtual harddisk of 512 MB (NAS4Free.vdi)) that holds the embedded OS and functions as USB stick (of CF Card) and 3 virtual harddisks with a size of 2 GB (NAS4Free.Disk1 etc). This is the configuration for the disks:


For Network I used the Host-only adapter, but you need to  make sure you configure your network settings for Adapter and DHCP server correctly in File/Preferences, Network. Both need to be in the same subnet.



And for DHCP server:



The rest of the settings should be self-explanatory. This is the screen after starting the Virtual Machine with NAS4Free:




Setting up ZFS RAID-Z:
Prerequisites: three harddisks of same size.
Three disks were created and named Disk1, Disk2 and Disk3. All disks were formatted as a ZFS Storage pool device. If you get error messages like "error code 1", you can try to select NTFS instead of unformatted when adding the disks in Disks | Management and then try again to format the disk with ZFS. It worked for me.


To create a ZFS Pool, select Disks/ZFS and then Pools/Virtual Devices and add new device and select all disks and name the device ZFS2. Automatically a mount point is established with the same name as your virtual device. So you don't have to create a seperate mount point.



Next select Disk/ZFS, Pools/Management and add new device and select ZFS2 from the previous step and apply the new setup:


At this moment I can start using the ZFS RAID Z. It is possible to use FTP or Shares to read and write files. Three disks with 2GB result in 4GB of free space. If one disk fails the data is still intact. To test this, I put some files on NAS4Free. Then NAS4Free was shutdown and I removed one random disk (Disk3) from the storage settings in VirtualBox. After starting the NAS4Free again, the result is a running configuration with Health status DEGRADED:


After shutdown, add a new disk in Storage in VirtualBox (Disk4):


Start NAS4Free and choose Disks | ZFS | Pools | Tools and replace ada3 with the new disk on the same port. Don't touch the disks in de Disks Management.


The status changes now from DEGRADED to ONLINE after the array is resilvered (all disks are up to date). The disk is replaced. Now you can Clear config and Import disks in Disks | Management.

Expanding RAID:
It isn't possible to dynamically add new disks to an existing pool to get more space. But it is possible to replace existing disks with bigger ones. For instance if you have a ZFS Mirror with 2 x 1TB disks, you can expand your disk space by replacing both with 2TB disks. As an example I updated ZFS2 with 4GB disk space and 3 2GB disks to 6GB disk space and 3 4GB disks, by replacing one disks at the time. After the final disk is replaced and the array is resilvered, then Clear config and Import disks in Disks | Management and reboot NAS4Free and the size is updated:


For me it's clear. Although my budget will allow only for 2 disks of 1TB at the moment, I will be able to expand it's size in the future. With 2 disks I choose a ZFS Mirror configuration which is running happily at the moment.