How to Setup OpenZFS on CentOS 7

Updated on November 21, 2023
How to Setup OpenZFS on CentOS 7 header image

OpenZFS is the open source implementation of ZFS which is an advanced and highly scalable storage platform. Although ZFS was originally designed for Sun Solaris, you can use ZFS on most of major Linux distributions with the help of the ZFS on Linux project, a part of the OpenZFS project.

In this article, I will show you how to setup OpenZFS on CentOS 7. Additionally, I will list some basic ZFS-related commands to help you learn about OpenZFS.

Prerequisites

  • A fresh Vultr CentOS 7 server instance with no less than 2GB of memory. 8GB or more of memory will provide the best performance.
  • An instance of block storage in the same region, being attached to the above server instance.
  • A sudo user.

Step 1: Update the system

Log into your Vultr CentOS 7 system as a sudo user, and then update the system to the latest stable status using the following commands:

sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now

After the reboot, use the same sudo user to log in again.

Step 2: Install OpenZFS

In order to install OpenZFS the easy way, you need to install the OpenZFS YUM repo:

sudo yum localinstall --nogpgcheck http://archive.zfsonlinux.org/epel/zfs-release$(rpm -E %dist).noarch.rpm

Use the following command to verify the installation:

gpg --quiet --with-fingerprint /etc/pki/rpm-gpg/RPM-GPG-KEY-zfsonlinux

The fingerprint on the screen should be the exact same as below:

pub  2048R/F14AB620 2013-03-21 ZFS on Linux <zfs@zfsonlinux.org>
      Key fingerprint = C93A FFFD 9F3F 7B03 C310  CEB6 A9D5 A1C0 F14A B620
sub  2048R/99685629 2013-03-21

Since we are using a distribution-provided kernel in this article, you can install the kABI-tracking kmods instead of the default DKMS style packages. This arrangement will prevent ZFS from being rebuilt after any kernel update from now on.

sudo vi /etc/yum.repos.d/zfs.repo

Change the third line:

baseurl=http://archive.zfsonlinux.org/epel/7/$basearch/

to:

baseurl=http://archive.zfsonlinux.org/epel/7/kmod/$basearch/

Save and quit:

:wq!

Install OpenZFS using YUM:

sudo yum install zfs

Reboot the system in order to make the kernel load ZFS-related modules:

sudo shutdown -r now

After the reboot, use the below command to verify the installation:

lsmod | grep zfs

The output should resemble:

zfs                  2794866  3
zunicode              331170  1 zfs
zavl                   15236  1 zfs
zcommon                55411  1 zfs
znvpair                89086  2 zfs,zcommon
spl                    92029  3 zfs,zcommon,znvpair

Step 3: Some basic OpenZFS commands

In order to test the functionality of OpenZFS, first of all, you need to prepare several storage devices which can be hard disks and/or partitions of a hard disk. Here, we will create 6 partitions on the attached block storage /dev/vdb and use them to demonstrate some basic OpenZFS commands.

sudo parted -s /dev/vdb mklabel gpt
sudo parted -s /dev/vdb unit mib mkpart primary 0% 15%
sudo parted -s /dev/vdb unit mib mkpart primary 15% 30%
sudo parted -s /dev/vdb unit mib mkpart primary 30% 45%
sudo parted -s /dev/vdb unit mib mkpart primary 45% 60%
sudo parted -s /dev/vdb unit mib mkpart primary 60% 75%
sudo parted -s /dev/vdb unit mib mkpart primary 75% 90%

You can use the following commands to confirm your operations, and the 6 partitions will be /dev/vdb1, /dev/vdb2, /dev/vdb3, /dev/vdb4, /dev/vdb5, and /dev/vdb6.

sudo parted -l
ls -l /dev/vdb*

OpenZFS has two main utilities: zpool and zfs. the zpool utility is in charge of creating and maintaining ZFS pools using storage devices, and the zfs utility is responsible for creating and maintaining datasets.

Samples of using the zpool utility:

  1. Create a ZFS pool

You can create a ZFS pool "zfspool1" using one or more storage devices:

sudo zpool create zfspool1 vdb1

or

sudo zpool create zfspool2 vdb2 vdb3 vdb5

Check the status of ZFS pools:

sudo zpool status

Before testing other OpenZFS commands, use the following commands to destroy the ZFS pools you setup earlier:

sudo zpool destroy zfspool1
sudo zpool destroy zfspool2
  1. Create a ZFS pool and make two or more storage devices mirrored.

Use /dev/vdb1 and /dev/vdb2 to create a ZFS pool, and both of them are configured as mirrored:

sudo zpool create zfspool3 mirror vdb1 vdb2

If necessary, you can also make those storage devices three-or-more-way-mirrored:

sudo zpool create zfspool4 mirror vdb3 vdb4 vdb5

Again, confirm your setup using the following command:

sudo zpool status

Then destroy the two ZFS pools:

sudo zpool destroy zfspool3
sudo zpool destroy zfspool4
  1. Create a ZFS pool and establish a raidz array using two or more storage devices

    sudo zpool create zfspool5 raidz vdb1 vdb2

Again, confirm your setup and destroy this ZFS pool:

sudo zpool status
sudo zpool destroy zfspool5

Samples of using the zfs utility:

Before using the zfs utility, create a ZFS pool consisting of 3 storage devices:

sudo zpool create zfspool6 vdb1 vdb3 vdb5
  1. Add a storage device for the ZFS pool.

    sudo zpool add zfspool6 vdb6

Note: You cannot remove these storage devices from the pool directly because they are partitions rather than hard disks.

  1. Create a filesystem for each of these storage devices.

    sudo zfs create zfspool6/vdb1 sudo zfs create zfspool6/vdb3 sudo zfs create -o mountpoint=/test zfspool6/vdb5 sudo zfs create -o compression=gzip zfspool6/vdb6

Explanations about the above commands:

  • The first command created a ZFS filesystem "zfspool6/vdb1" which was then mounted to the default location /zfspool6/vdb1.
  • The second command executed in the same fashion: creating a ZFS filesystem "zfspool6/vdb3" and then mounting it to /zfspool6/vdb3.
  • The third command created a ZFS filesystem "zfspool6/vdb5" which was then mounted to a specified location /test.
  • The fourth command created a gzip-compressed ZFS filesystem "zfspool6/vdb6" which was then mounted to the default location /zfspool6/vdb6.

After that, if you want to change the mounting point of a storage device:

sudo zfs set mountpoint=/vdb3 zfspool6/vdb3

If you want to setup or modify the compression method:

sudo zfs set compression=gzip zfspool6/vdb3
sudo zfs set compression=lz4 zfspool6/vdb6

Use the following command to confirm the compression method:

sudo zfs get -r compression zfspool6/vdb3

List all of the ZFS filesystems on your system:

sudo zfs list

If a storage filesystem is no longer necessary, you can destroy it using the following command:

sudo zfs destroy zfspool6/vdb5

That concludes our tutorial. The contents in this article are only introductory, and you can learn more about OpenZFS from its official website. Thank you for reading.