ZFS is an advanced file system with many terrific features that are not available in many of the traditional file systems such as ext4. Some of the key features found in ZFS are:
- Pool drive storage, multiple disks can ‘merged’ into a single file-system.
- RAID-Z, performs software raid functionality with a variety of options even with as few as two disks.
- Copy-on-write, this ensures that data on a drive is not removed until it’s copy has been fully written. This prevents data loss in the event that the system crashes before the write has completed as the original data is still present on the disk.
- Snapshots, a snapshot contains the original version of the file system, and the live file system contains any changes made since the snapshot was taken.
- Data Checksums, data written to ZFS has checksum data associated with it to allow for verification and data restoration in the event of bit-rot or other potential corruption problems.
ZFS was created and open-sourced originally by Sun Microsystems back in 2001. However after Oracle purchased Sun Microsystems, everything was moved to being closed source. The OpenZFS project is a result of this, it’s the continued open-source work from the original Sun code by many of the original engineers. Because of this, there has been a lot of discussion regarding the open-source license that ZFS uses and if it’s compatible for inclusion into the mainline Linux kernel. Many Linux distributions have chosen to include ZFS, for this guide we'll be using Ubuntu as it’s readily available on all ODROIDs.
Several years ago, I looked into running ZFS on my ODROID-XU4 Cloudshell 2, when I asked on the forums I was let down to know the ODROID-XU4 just wouldn’t cut it. However, now we have the ODROID-H2, which is more than capable of the task at hand. ZFS is fairly heavy in its memory use. The bulk of this memory is used for cache, or the Advanced Replacement Cache, ARC, to be specific. While some online will say you need one GB of memory per TB of capacity in the ZFS pool, others, including myself, have found that to be a bit over the top. However, for a setup like a NAS the more RAM you can allocate for ZFS the better. Luckily, since the ODROID-H2 is expandable to 32GB of RAM that gives a good amount of flexibility.
Installation and setup
As mentioned earlier in this guide, we will be using Ubuntu as our distro, more specifically Ubuntu Server 18.04 LTS. Once everything is installed and the desired drives are attached we can pick up with the steps listed below.
The first thing that needs to be done is to install ZFS utilis via apt-get:
$ sudo apt install zfsutils-linuxNext, we can create the ZFS pool, or zpool, from the attached drives. A ZFS pool is a configuration of drives.
ZFS supports many other configurations, I’ll outline a few for a more thorough listing to find a more particular configuration please see one of the links at the end of this guide. For instance the command below with just the zpool create command with a list of drives yields a RAID-0 configuration in a pool named ‘mypool’. Here the pool has only two drives ‘sdb’ and ‘sdc’, but more drives, if available, could be added to the list:
$ sudo zpool create mypool /dev/sdb /dev/sdcThe following command will take two drives ‘sdb’ and ‘sdc’ and mirror them together in a pool named ‘mypool’:
$ sudo zpool create mypool mirror /dev/sdb /dev/sdcTo help protect against data loss in the event of drive failure in a system with more than multiple disks we can take advantage of the ZFS RAIDZ types. RAIDZ, this is similar to RAID-5 where one disk worth of capacity is lost in the total pool size and only provides protection for a single disk failure. RAIDZ2, this is similar to RAID-6, with double parity and has the advantage of protecting against two disk failures. RAIDZ3, tripe the parity to provide protection against three disk failures:
$ sudo zpool create mypool raidz /dev/sdb / dev/sdc /dev/sdd /dev/sde /dev/sdfAlthough the H2 has only two SATA points new revisions, an expansion for additional SATA ports is possible via NVMe adapters.
Setting up a ZFS pool is fairly simple as we saw, luckily most other commands are just as straight forward. The following command is one of the most useful to remember as it returns the status and the health of your pool:
$ sudo zpool statusThe output for this command should look as follows:
odroid@copenhagen:~$ sudo zpool status [sudo] password for odroid: pool: poolc state: ONLINE scan: scrub repaired 0B in 1h0m with 0 errors on Sun Feb 9 01:24:36 2020 config: NAME STATE READ WRITE CKSUM poolc ONLINE 0 0 0 mirror-0 ONLINE 0 0 0 sda ONLINE 0 0 0 sdb ONLINE 0 0 0 errors: No known data errorsIf everything is healthy, you should see ‘0’s, anything else should be an indication that action is needed. One of the potential commands to run would be a scrub, which performs a data integrity check. A ‘-v’ argument can be passed as well for more verbose output:
$ sudo zpool scrub mypoolSnapshots are a very helpful tool to create reference points that you can later revert back to in the event of a problem. The command below creates a snapshot named ‘somelabel’ of the ‘/home/odroid’ directory in the ZFS pool named ‘mypool’:
$ zfs snapshot mypool/home/odroid@somelabelTo view a list of all the snapshots available:
$ sudo zfs list -t snapshotTo reset your file system, or in this case ‘/home/odroid’, to the state it was in when the ‘somelabel’ snapshot was taken, the following command can be used:
$ sudo zfs rollback mypool/home/odroid@somelabel
This guide was intended to be a starting point to get you familiar with ZFS and highlight some of the features that set it apart. I would highly recommend everyone interested to take a look at the Ubuntu ZFS reference guide for further information as well as the Ars Technica article (albeit a bit dated, the information and writeup are terrific).