All posts tagged ZFS

I had previous experience with awesome ZFS at my current company where I implemented two backup storage servers for our corporate services.

For home use I wanted to create a NAS with several network shares and with some data redundancy. I chose FreeNAS, it had everything I needed already implemented with a nice and sleek Web UI. Or at least that’s what I thought.

I wanted to create a RAID-Z pool with some percentage of my three hard drives for somewhat important data and use the rest as separate non-redundant (or even striped) zpool – like one would do on Windows Server with dynamic disks.  But, FreeNAS does not support creating zpools with different size of disks/partitions through its web interface. It always goes for the whole drive. Although, this is not that surprising – official ZFS documentation states that “The recommended mode of operation is to use an entire disk“. Maybe its not recommended, but it doesn’t mean it won’t work, and dare I say – smoothly.

So, we’ll have to get our hands dirty and do it manually.

First, we want to list all the hard drives on our system. We could do this by doing ls on /dev/ directory.

ls /dev/ada?

You could check if the drive is already partitioned with (where X is the number of the drive you want to check out):

gpart list adaX

Output will be something like “gpart: No such geom: adaX”, if the drive is new. And this means there is no partition table on the drive. In case that the drive is already partitioned, you would most likely want to delete its partitioning info by doing:

gpart destroy adaX

You can do -F to force most of the commands.

Now, we want to create new partition table for the drive with:

gpart create -s gpt adaX

Then, we want to add partitions with desired size and file system:

gpart add -s 500g -t freebsd-zfs adaX

Where “-s 500g” is for size of 500 gigabytes, and “-t freebsd-zfs” is for ZFS type of file system.

This will generate the first partition, usually named adaXp1. In my scenario, I added another partition with the remaining size of the drive. Repeat this for all the drives you want in your zpool.

Now, its time to create zpool, a pretty straightforward procedure.

zpool create poolname raidz ada1p1 ada2p1 ada3p1

zpool create secondpoolname ada1p2 ada2p2 ada3p2

Zpool will try to mount it under /mnt/poolname and that will fail if there is no directory with the poolname. Fine with me, because I want to continue using FreeNAS through its WebUI so I wouldn’t have to meddle with manual CIFS/NFS  configuration.

When you go to FreeNAS volume manager in WebUI there will be no zpools you just created. No worry though. Easiest way to get them mounted and imported in web interface is to go back to cli, export the pools with:

zpool export poolname

And use the Auto Import Volume feature in Storage tab in FreeNAS.

Extra – In case you need to do some maintenance of your ZFS pools you should do it only through cli, as web interface might give unpredictable or undesired results.

To replace a failed hard drive, recreate the partitioning scheme on the new drive and do:

zpool replace poolname adaXpX

Which will resilver/rebuild the ZFS pool.

Note that this is not a recommended way to utilize ZFS and may require additional manual steps in creating and mounting a swap partition(s) that is/are usually handled by FreeNAS. ZFS can be very memory intensive depending on the size and configuration, so take caution and use this configuration on your own risk.