How to set up a ZFS storage pool on Ubuntu

ZFS is a combined file system as well as a logical volume manager that offers raid like functionality with data integrity and simplified storage management. It allows you to store and manage a large amount of data. It was first created at Sun Microsystems and now a part of the OpenZFS project. Now it has been ported to additional OSes including FreeBSD, Linux, and Mac OSX. ZFS storage pool can deal with a large amount of data that offers you to extend your on-site cloud solution.

In this article, we will show you how to install ZFS and how to set up a ZFS storage pool. But before going through the procedure, let’s take a look at its features:

Features of ZFS

Some of the features of ZFS are as below:

  • Pooled storage
  • Open-source
  • Copy-on-write
  • encryption
  • Snapshots
  • Continuous integrity checking
  • Efficient data compression
  • Data integrity verification and automatic repair

We will use Ubuntu 18.04 LTS for describing the procedure mentioned in this article.

Installing ZFS on Ubuntu

To install ZFS on Ubuntu 18.04 LTS, launch the Terminal by pressing Ctrl+Alt+T and then type the following command in it:

$ sudo apt install zfsutils-linux

Install ZFS Utils for Linux

Wait for a while until the installation is completed.

To verify the installation, run the following command in Terminal:

$ whereis zfs

You will see the output similar to below.

Check if ZFS is installed

Creating a ZFS storage pool

After installation, we will create a pool of drives. The first step while creating a ZFS storage pool is to know what type of pool you want to create. Then decide which drives to put in the storage pool.

1. Select ZFS pool type

There are two types of pool you can create:

Striped pool

In a striped pool, copy of data is stored across all drives. You can get combined storage and faster read/write speed. However, If one drive fails, you will lose all your data.

Mirrored pool

In a mirrored pool, a single and complete copy of data is stored on all drive. If one drive fails, you can still access your data.

2. Select drives for pooling

Now we have to identify what drives are available on our system to pool. To find out the drives, run the following command in Terminal:

$ sudo fdisk –l

From the output of fdisk command, note down the names of the drives which should be something like sda, sdb, sdc.

In our scenario, we have two drives available that are sdb and sdc. I will use these two drives to create a storage pool.

Select Drives for ZFS Pool

3. Creating Pool

Once you have decided the pool type and the drives that need to pool, the next step is to create a pool from the above set of drives using zpool command available in Linux that is used to configure storage pools in ZFS.

To create a striped pool, run the following command in Terminal:

$ sudo zpool create <pool_name> <drive1> <drive2>

To create a mirrored pool, run the following command in Terminal:

$ sudo zpool <pool_name> mirror <drive1> <drive2>

You can create any pool depending upon your storage requirements. We will create a mirrored pool using the above command:

Create ZFS Pool

After creating the pool, you can verify the detailed status of the zpool by using the following command:

# zpool status

Check ZFS Pool state

To see pool health status and space usage, use the below command in Terminal. This command also shows the disks that you have selected for your storage pool. You can add more drives later to further increase redundancy.

$ zpool list

List ZFS Pools

Now run df –h, you will note that the newly created pool is automatically mounted at the mount point.

ZFS Pool listed in df command

The pool you have just created has a size of 1.9 G and it is mounted at the default mount point /new-pool. If you want, you can change the mount point using the following syntax:

$ sudo zfs set mountpoint=<path> <pool_name>

For instance, we want to set the /usr/share/pool as the new mount point. we will use the following command for this purpose:

$ sudo zfs set mountpoint=/usr/share/pool new-pool

To verify if the mount point has changed successfully, use df -h command

From the above results, you can see that the mount point has changed successfully to the new mount point /usr/share/pool..

Now the storage pool has created, we will now create datasets and will keep everything inside these datasets. These datasets are like directories and have a mount point.

To create datasets, run the following command in Terminal:

$ sudo zfs create <pool_name>/directory_name

For instance, I want to create dataset named docs under my storage pool. I will use the following command:

$ sudo zfs create new-pool/docs

The datasets that we have just created will get automatically mounted with the name /new-pool/docs at the mount point /usr/share/pool which we can view by using the df -h command.

$ df -h

Result of df -h command

Removing a ZFS pool

If you want to remove the pool, you can use the zpool destroy command as shown below:

# zpool destroy pool_name

That is all we needed in order to set up a ZFS storage pool in Ubuntu 18.04 LTS. Now you can start storing your files in the newly created pool. It is an awesome and powerful file system that you can use when working with loads of storage.