Debian

Install and Setup ZFS on Debian 11

The full form of ZFS is Zettabyte File System. The ZFS filesystem is a 128-bit filesystem. The ZFS supported filesystem size is 3×1024 TB. You may never encounter such a big filesystem in real life. The ZFS filesystem was designed to keep and access an insane amount of data.

In this article, I will show you how to install and set up the ZFS filesystem on Debian 11. So, let’s get started.

Table of Contents:

  1. Features of the ZFS Filesystem
  2. Limits of the ZFS Filesystem
  3. Enabling Debian contrib Package Repository
  4. Installing ZFS Filesystem Dependencies
  5. Installing the ZFS Filesystem
  6. Creating ZFS Pools
  7. Creating ZFS Datasets
  8. Setting ZFS Dataset Quotas
  9. Removing ZFS Datasets
  10. Removing ZFS Pools
  11. Conclusion
  12. References

Features of the ZFS Filesystem:

Other than the huge filesystem size support, ZFS also has some impressive features:

  1. ZFS has a built-in volume manager.
  2. Built-in support for different types of RAIDs.
  3. Built-in encryption support.
  4. Built-in data/metadata checksum support.
  5. Built-in filesystem compression support.
  6. Built-in quota support.
  7. Built-in data deduplication support.
  8. Filesystem snapshot support.

Limits of the ZFS Filesystem:

Despite the amazing features, the ZFS filesystem has some limits:

  1. Maximum size of a single file can be 264 bytes or 16 exbibytes (EB).
  2. In any individual directory, you can create a maximum of 264 files/directories.
  3. Maximum size of any ZFS pool can be 2128 bytes or 256 quadrillion zebibytes.
  4. You can create 264 ZFS pools on your computer.
  5. In any single ZFS pool, you can add a maximum of 264 storage devices (HDDs/SSDs).
  6. You can create 264 filesystems in any single ZFS storage pool.

Enabling Debian contrib Package Repository:

The ZFS filesystem packages are available in the official Debian 11 contrib package repository. The contrib package repository is not enabled on Debian 11 by default. But you can easily enable it from the command-line.

To enable the contrib package repository, open a Terminal and run the following command:

$ sudo apt-add-repository contrib

The official Debian contrib repository should be enabled.

Update the APT package repository cache with the following command:

$ sudo apt update

Installing ZFS Filesystem Dependencies:

You must install the libraries that the ZFS filesystem kernel module depends on before installing the ZFS filesystem on Debian 11.

You can install all the libraries that the ZFS kernel module depends on with the following command:

$ sudo apt install linux-headers-$(uname -r) linux-image-amd64 spl kmod

To confirm the installation, press Y and then press <Enter>.

All the required dependency libraries should be installed.

Installing the ZFS Filesystem:

Now, you can install the ZFS filesystem on Debian 11 with the following command:

$ sudo apt install zfsutils-linux zfs-dkms zfs-zed

To confirm the installation, press Y and then press <Enter>.

The APT package manager will download all the required packages from the internet. It may take a while to complete.

You will be asked to accept the OpenZFS license. To accept the OpenZFS license (used by the ZFS kernel module), select OK and press <Enter>.

All the required packages will be installed one by one. It will take a while to complete.

The ZFS kernel module is being installed and configured. It will take a few seconds to complete.

All the ZFS systemd services are being started. It will take a few seconds to complete.

At this point, the ZFS filesystem should be installed.

Creating ZFS Pools:

Once you’ve installed the ZFS filesystem on your computer, you can create a ZFS pool using one or more drives.

You can list all the storage devices of your computer with the following command:

$ sudo lsblk

As you can see, all the storage devices of my computer are listed.

In this article, I will use the drives sdb and sdc to create a ZFS pool.

To create a new ZFS pool pool1 using the drives sdb and sdc, run the following command:

$ sudo zpool create -f pool1 /dev/sdb /dev/sdc

As you can see, a new ZFS pool pool1 has been created.

$ sudo zpool list

As you can see, the ZFS pool pool1 is ONLINE, and it uses the drives sdb and sdc.

$ sudo zpool status

After pool1 is created, the pool should be mounted in the /pool1/ (same directory name as the pool) directory, as shown in the screenshot below.

$ df -h

As you can see, a directory with the same name as the pool name pool1 is created in the root directory /.

$ ls /

Creating ZFS Datasets:

ZFS datasets are like filesystem partitions. You can create a lot of ZFS datasets in a single ZFS pool.

To create a new ZFS dataset ds1 in the pool pool1, run the following command:

$ sudo zfs create pool1/ds1

To create another ZFS dataset, ds2 in the pool pool1, run the following command:

$ sudo zfs create pool1/ds2

As you can see, 2 ZFS datasets, ds1 and ds2 are created in the pool pool1.

$ sudo zfs list

The ZFS datasets ds1 and ds2 should be mounted in their respective directories in the /pool1/ directory, as shown below.

$ df -h

As you can see, new directories for the datasets ds1 and ds2 are created in the /pool1/ directory.

$ ls -l /pool1

Now, you can change the owner and the group of the pool1/ds1 dataset to your login username and primary group with the following command:

$ sudo chown -Rfv $(whoami):$(whoami) /pool1/ds1

As you can see, I can copy files to the pool1/ds1 dataset.

$ cp -v /etc/hosts /pool1/ds1

I have copied the /etc/hosts file to the pool1/ds1 dataset. As you can see in the screenshot below, the file is in the /pool1/ds1/ directory.

$ tree /pool1

Setting ZFS Dataset Quotas:

You can limit the amount of disk space that a ZFS dataset can use from a ZFS pool using quotas.

For example, to allow the ZFS dataset ds1 to use only 10 GB of storage from the ZFS pool pool1, run the following command:

$ sudo zfs set quota=10G pool1/ds1

As you can see, a quota of 10 GB is set for the pool1/ds1 dataset.

$ sudo zfs get quota pool1/ds1

As you can see, once the 10 GB quota is set, the dataset ds1 can only use 10 GB of disk space out of 38.5 GB from the storage pool pool1.

$ sudo zfs list

Removing ZFS Datasets:

If you don’t need a ZFS dataset, you can remove it.

For example, let’s say you want to remove the dataset ds1 from the pool pool1.

$ sudo zfs list

You can remove the dataset ds1 from the pool pool1 with the following command:

$ sudo zfs destroy pool1/ds1

As you can see, the dataset ds1 is removed from the pool pool1.

$ sudo zfs list

The ds1/ directory and all the files from the ds1/ directory should also be removed from the /pool1/ directory, as you can see in the screenshot below.

Removing ZFS Pools:

You can remove a ZFS pool as well.

To remove the ZFS pool pool1, you can run the following command:

$ sudo zpool destroy pool1

If the pool you want to remove has one or more datasets actively used by some users/programs, you may see an error while removing the pool.

In that case, you will have to remove the pool with the -f option as follows:

$ sudo zpool destroy -f pool1

As you can see, the pool pool1 is removed.

$ sudo zpool list

Conclusion:

In this article, I have shown you how to install the ZFS filesystem on Debian 11. I have shown you how to create and remove ZFS pools as well as ZFS datasets. I have shown you how to set quotas in ZFS datasets as well. This article should help you get started with the ZFS filesystem on Debian 11.

References:

[1] ZFS – Wikipedia – https://en.wikipedia.org/wiki/ZFS

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.