Once you have finished installing ZFS on Ubuntu 20.04, the next step is to do some configuration with your hard disks. There are a lot of possibilities with ZFS, and what you decide to do will depend on how many drives you have available and what your storage goals are. For example, would you rather your storage array focus on speed or redundancy? Do you have 3 disks or 20? What about encryption?
Whichever type of configuration you're going for, we'll show you how to get started in this guide. Read on as we cover basic usage commands in ZFS and setting up zpools, RAID-Z, encryption, and more.In this tutorial you will learn:
- How to install ZFS on Ubuntu 20.04
- How to create and destroy zpools
- Configure different levels of RAID and RAID-Z
- How to use encryption with ZFS
|Category||Requirements, Conventions or Software Version Used|
|System||Installed or upgraded Ubuntu 20.04 Focal Fossa|
|Other||Privileged access to your Linux system as root or via the |
|Conventions|| # - requires given linux commands to be executed with root privileges either directly as a root user or by use of |
The only thing you need to get started with ZFS and follow along with our guide is Ubuntu 20.04 Focal Fossa, some hard drives you'd like to use in your storage array(s), and the ZFS utilities installed on your system. If you don't already have ZFS installed, you can open a terminal and install the
zfsutils-linux package with these two commands:
$ sudo apt update $ sudo apt install zfsutils-linux
You can verify ZFS is installed with the following command in terminal:
$ zfs --version
ZFS Basic Usage and Commands
We have a few hard drives in our test system that we plan to use with ZFS. We'll show you various things you can do with them in this section.
When you plug new hard disks into your system, ZFS addresses them by their device name - normally something along the lines of
/dev/sda or similar. You can use the
fdisk command to see what hard drives you have available.
$ sudo fdisk -l
Create and destroy ZFS storage pools
ZFS works by "pooling" disks together. These pools (commonly called "zpools") can be configured for various RAID levels.
The first zpool we'll look at is a RAID 0. This works by striping your data across multiple disks. When a file is read from or written to the storage pool, all the disks will work together to present a portion of the data. This offers you a speed boost for your read and write speeds, but it doesn't do anything for redundancy. As a matter of fact, any disk failure in the pool will result in a complete loss of data.
$ sudo zpool create mypool /dev/sdb /dev/sdc
This command has created a ZFS storage pool named "mypool" with two hard drives,
/dev/sdc. You can see details about your storage pools any time by running this command:
$ zpool status
And you can see a more concise report of your ZFS storage pools by executing:
$ zpool list
Your newly created pool will be mounted automatically for you, and you can begin to use it right away. A nice feature of ZFS is that you don't need to go through a lengthy partitioning (when using whole disks) or formatting process. The storage is just accessible right away.
$ df -hT | grep zfs
If you want to add another hard disk to the pool, take a look at this command where we add hard disk
/dev/sdd to our previously created
mypool storage pool:
$ sudo zpool add mypool /dev/sdd
You can see that the drive has been added to the zpool with the
zpool status command.
We can destroy our zpool at any time with the following command:
$ sudo zpool destroy mypool
In the case of RAID 0 zpools, you can't remove any disk from the pool without destroying the pool entirely and losing all data. ZFS has many different options, some of which allow for the removal or failure of disks while still maintaining the integrity of the pool.
Other types of ZFS storage pools are created in the same manner as we've shown you above, but you need to supply an extra argument in the
zpool command when creating the pool. Let's look at some examples.
A mirrored storage pool is ZFS' equivalent to RAID 1. This gives you redundancy because all your data is mirrored from one hard disk to one or more others. To make a mirrored storage pool, use the following command syntax:
$ sudo zpool create mypool mirror /dev/sdb /dev/sdc
Of course, more disks can be added to the pool to create additional redundancy.
Now, let's take a look at RAID-Z pools. RAID-Z is very similar to RAID 5, but improves upon it with better speed and avoiding some of the common errors associated with RAID 5.
RAID-Z will give you speed plus redundancy by using block level striping and distributed parity. There are three types of RAID-Z available, depending on how much parity you want.
- raidz1 (or just raidz) - single parity
- raidz2 - double parity
- raidz3 - triple parity
Here's how you can create a RAID-Z pool. Use
raidz3 in place of of
raidz in this command if you want more parity (keep in mind you'll also need additional disks in that case):
$ sudo zpool create mypool raidz /dev/sdb /dev/sdc /dev/sdd
Encryption on ZFS
After creating your ZFS storage pool, you can configure encryption on it with the following commands. For this example, we are still using our three disk RAID-Z pool named mypool.
$ sudo zfs create -o encryption=on -o keylocation=prompt -o keyformat=passphrase mypool/encrypted
You'll be asked to enter a passphrase twice for the encryption.
A new directory is created under
/mypool/encrypted, and anything in that directory is encrypted. Whenever you reboot, you'll need to manually mount the encrypted dataset. Be sure to use the
-l flag when mounting encrypted datasets. You'll be prompted to enter the passphrase you chose earlier.
$ sudo zfs mount -l mypool/encrypted
ZFS is a file system focused on high availability and data integrity. It's perfect for storage/NAS servers and any environment where read and write speeds are crucial along with hard drive redundancy.
In this guide, we learned about some basic usage commands for ZFS in Ubuntu 20.04 Focal Fossa. We have shown you how to get started with configuring ZFS on your own system with zpools, but the configuration for ZFS can become far more extensive.