How to manage ZFS on your Ubuntu or Debian Linux.

This tutorial was tested on Debian 10, Ubuntu 18 and 20 both, Server and Desktop editions. I’m not going into details about what is ZFS. I’m assuming you already know this.

Getting ready

Install support for ZFS on Ubuntu with this command:

$sudo apt install zfsutils-linux

ZFS on Debian will require little bit more work. First you need to add contrib section to your apt sources configuration. See more details here. After adding contrib, run these commands to install:

$sudo apt update
$sudo apt install dkms spl-dkms
$sudo apt install zfs-dkms zfsutils-linux

Creating a pool

Now you should be able to create a simple ZFS pool. Command to create a stripe configuration ZFS pool with two hard drives with a name zpool1:

$sudo zpool create zpool1 /dev/sdi /dev/sdh

In this case, sdi and sdh are the hard drives that were chosen to be part of this pool. This pool is auto-mounted upon creation in /zpool1 directory. Check the the status of the pool with:

$sudo zpool status
pool: zpool1
state: ONLINE
scan: none requested
config:

NAME STATE READ WRITE CKSUM
zpool1 ONLINE 0 0 0
sdi ONLINE 0 0 0
sdh ONLINE 0 0 0

errors: No known data errors

The best practice is to create a pool with device IDs instead of drive letters, like /dev/sda. Look up device ID with the following command:

$ls -l /dev/disk/by-id/

In another example, let’s create a ZFS pool with some redundancy. Mirror configuration is a very popular choice:

$sudo zpool create tank mirror /dev/sdb /dev/sdc /dev/sdd

Here we have a three way mirror ZFS pool called tank. There are other pool configurations that could be used. They are:

  • raidz1 – single drive parity, three drives minimum in the pool. Similar to RAID5.
  • raidz2 – double drive parity, requires four drives. Similar to RAID6.
  • raidz3 – triple drive parity,  requires five drives.

There is more to it

More drives can be added to the pool later, if needed. There are no equivalent of RAID10 or RAID50 configurations, but it can be accomplished by creating a pool and adding another configuration to that pool. Like so:

$sudo zpool add tank mirror /dev/sde /dev/sdf /dev/sdg

This adds another three way mirror configuration to already existing mirror of the previously created tank pool. It would be best to create configurations like RAID10 or RAID50 before you start using your pool. Converting mirror to RAID10 equivalent configuration later on might not get you the results you are expecting. ZFS will not evenly redistribute data across newly added configuration, like a typical RAID10 would. Here is the status of my 8 drive pool in a RAID50 configuration. These drives connected via USB ports.

pool: zpool
state: ONLINE
scan: resilvered 4.50K in 0 days 00:00:00 with 0 errors on Sun Oct 11 17:18:25 2020
config:

NAME STATE READ WRITE CKSUM
zpool ONLINE 0 0 0
raidz1-0 ONLINE 0 0 0
sdh ONLINE 0 0 0
sdi ONLINE 0 0 0
sdg ONLINE 0 0 0
sdj ONLINE 0 0 0
raidz1-1 ONLINE 0 0 0
usb-DISK00_DB98765432146-0:0 ONLINE 0 0 0
usb-DISK02_DB98765432146-0:2 ONLINE 0 0 0
usb-DISK01_DB98765432146-0:1 ONLINE 0 0 0
usb-DISK03_DB98765432146-0:3 ONLINE 0 0 0

errors: No known data errors

If you are using portable USB hard drives to create your pool, it is possible to connect the pool to a different computer running Ubuntu or Debian. With a simple commands you can export it from one device and import it on another one.

$sudo zpool export tank
$sudo zpool import tank

When you are done with the pool destroy command will delete the pool and all the data on it:

$sudo zpool destroy tank

There is a whole lot more to ZFS. Enjoy!