Debian

Install and Setup ZFS on Debian 10

Install and Setup ZFS on Debian 10
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.

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.

The limits of the ZFS filesystem are:

  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.

This article will show you how to install and set up the ZFS filesystem on Debian 10. So, let's get started.

Enabling Debian contrib Package Repository:

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

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.

Now, update the APT package repository cache with the following command:

$ sudo apt update

The APT package repository cache should be updated.

Installing ZFS Dependencies:

The ZFS filesystem kernel module depends on many other libraries you need to install before installing ZFS on your Debian 10 machine.

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>.

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

Once all the packages are downloaded, the APT package manager will install them one by one. It may take a while to complete.

All the required packages should be installed at this point.

Installing ZFS on Debian 10:

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

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

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

To accept the ZFS license, select <OK> and press <Enter>.

The APT package manager should download and install all the required packages. It may take a while to complete.

At this point, the ZFS filesystem should be installed. But, some services are not configured correctly, as you can see in the screenshot below.

To configure the ZFS services correctly, you need to enable the zfs kernel module with the following command:

$ sudo modprobe zfs

Now, configure the ZFS services that were not configured correctly before, run the following command:

$ sudo apt -f install

As you can see, the ZFS services are being configured. It may take a few seconds to complete.

The ZFS services should be configured at this point.

The zfs kernel module won't automatically load when your computer starts. So, you have to configure Debian 10 to load the zfs kernel module automatically at boot time.

To load the zfs kernel module at boot time, create a new file /etc/modules-load.d/zfs.conf with the following command:

$ sudo nano /etc/modules-load.d/zfs.conf

Type in zfs in the /etc/modules-load.d/zfs.conf file as marked in the screenshot below.

Once you're done, press <Ctrl> + X followed by Y and <Enter> to save the /etc/modules-load.d/zfs.conf file.

For the changes to take effect, reboot your computer with the following command:

$ sudo reboot

Once your computer boots, the zfs kernel module should load automatically, as you can see in the screenshot below.

$ sudo lsmod | grep zfs

Creating ZFS Pools:

Once you've installed the ZFS filesystem on your computer, you need to create a ZFS pool using one or more hard 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 displayed.

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

To create a new ZFS pool pool1 using the hard 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 is created.

$ sudo zpool list

As you can see, the ZFS pool pool1 is ONLINE, and it uses the hard 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 you can see 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 you can see in the screenshot 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.

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.

Removing ZFS Datasets:

If you don't need a ZFS dataset, you can remove it if you want.

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 shown 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 being 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 ZFS on Debian 10. I have shown you how to load the ZFS kernel module at boot time automatically. I have shown you how to create and remove a ZFS pool 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 10.

References:

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

Як використовувати Xdotool для стимулювання клацань миші та натискань клавіш у Linux
Xdotool - це безкоштовний інструмент командного рядка з відкритим кодом для імітації клацань миші та натискань клавіш. У цій статті буде розглянуто ко...
Топ 5 ергономічних продуктів для комп'ютерної миші для Linux
Чи викликає тривале використання комп’ютера біль у зап’ясті або пальцях? Ви страждаєте від ригідності суглобів і вам постійно доводиться трясти руки? ...
How to Change Mouse and Touchpad Settings Using Xinput in Linux
Most Linux distributions ship with “libinput” library by default to handle input events on a system. It can process input events on both Wayland and X...