How to Enable ZFS Compression on Linux

Wondering how to enable ZFS compression on Linux?

File systems are methods responsible for managing data in permanent storage e.g. hard disks and solid-state drives(SSD). File Systems are the decision-makers for deciding where the data will be stored and how it’s going to be managed and accessed.

One of the most renowned file systems is the Zettabyte file system (ZFS), now known as OpenZFS after being acquired by Oracle Corp. ZFS is on its way to becoming the goto filesystem for many Linux users. With its plethora of features, it’s a strong competitor against other filesystems for managing your data.

A feature that makes ZFS extremely valuable is its ability to compress the data. This allows for efficient data storage i.e. you can store larger chunks of data in your available storage. Thus, learning how to enable ZFS compression on Linux will prove to be a valuable feature, which is why you’re here. 

As long as you follow the steps in this guide, enabling ZFS compression on Linux will be a walk in the park.

So with all set and ready, let’s begin!

Significance of ZFS compression.

Before we learn how to enable ZFS compression on Linux, it is advised that you learn what makes ZFS compression a valuable feature. This will allow you to make a better decision of whether enabling ZFS compression on your Linux system will be worth the effort.

Without a doubt, the most significant advantage of using ZFS compression is that it would allow you to save space on your system. By compressing most files and applications that are installed on your Linux distribution, you’d be preserving space that would otherwise have been used by the aforementioned applications. This will allow you to install more apps.

ZFS compression also provides a boost in performance. This is because the execution cycles by the processor for compression/decompression of data are significantly faster when compared to the execution cycles for the reading/writing of the uncompressed data.

ZFS compression is a helpful feature if you’re working on a virtual machine(VM). This is because you have a limited amount of permanent storage to work it. ZFS compression makes sure that each bit of that space is utilized to its maximum potential.

The only potential disadvantage of ZFS compression is that although it’s faster, the processor will require more execution cycles for compression/decompression. This change is hardly noticeable if you’re working on systems with powerful processors. However, in the case of less powerful systems like the Raspberry Pi, those extra cycles are a red flag.

With all the advantages and disadvantages discussed, we can move on to the prerequisites for ZFS compression.

Prerequisites for Enabling ZFS Compression.

The installation method of the ZFS module is more or less similar for all Linux distributions. For this guide, we’ll be using Ubuntu 20.04 LTS, which offers support for ZFS by default.

If you’re using a previous version of Ubuntu, you can check how to set up ZFS for the previous versions on the official ZFS GitHub by clicking here.

The official manual for the implementation of ZFS is available on the Oracle website. You can consult the manual by clicking here.

Now that we’ve discussed the pre-requisites, we can proceed to the steps for enabling ZFS Compression.

Step 1: Configuring ZFS.

In this step, we’re going to make sure that our ZFS is configured properly. 

In case you’ve already set up ZFS on your system along with the memory pools, you can skip this step. Otherwise, follow the instructions to ensure that ZFS is configured correctly.

  1. Open the terminal by pressing Ctrl + Alt +T.
  2. Type in the following command.
$ sudo lsmod | grep zfs

If nothing loads up, then type the following command first.

$ sudo modprobe zfs

Running the $ lsmod command again should display modules, as shown in the image below.

grep
  1. Furthermore, you need to ensure that you have all the necessary utilities and tools for using ZFS. For this purpose, type the following command in the terminal.
$ sudo apt-get install zfsutils
enable ZFS Compression on Linux

The next step is to select a memory pool or if none exist, then create one first. These are chunks of memory space that have been allocated beforehand.  This step should cover the utmost basics of creating one.

First and foremost, make sure that you’re working as a superuser. You can do that by typing the following command in the terminal.

$ sudo -i

After typing in your password, you should be a root user.

sudo

Next, ensure that you have free disks available. You can check for all disks by typing the following command.

$ ls -l /dev/sd*

Then create the pool by typing the following command.

$ zpool create -f <pool name> raidz <disk 1> <disk 2> <disk n>
enable ZFS Compression on Linux

Since we don’t have additional drives available at the moment, we’re using the system drives to explain the syntax for creating the pool. The method is no different for additional drives. Once you create the pool, you can move onto the next step.

Step 2: Enabling ZFS Compression.

With ZFS configured properly, it’s time that we move to the main event i.e. enabling ZFS compression. We’re going to perform ZFS compression on our newly created pool.

With the help of these steps, you’ll be able to enable ZFS compression on your Linux distribution. We will also provide additional commands that will help you master ZFS.

It should be noted that ZFS compression does not tweak or compress the data already present in your filesystem. Instead, the compression will only work for the data that will come after the setting has been enabled. 

To enable ZFS compression on your Linux distribution, we continue from where we left in the previous step. After successfully creating the pool using the zpool command, type the command under the following syntax.

$ zfs set compression=<compression type> <pool name>

An example of this code is given below.

$ zfs set compression=lz4 mypool
enable ZFS Compression on Linux

Here, lz4 is one of the many algorithms that are made for the compression of data in filesystems. A list of these algorithms with their basic descriptions can be accessed by clicking here.

To disable the ZFS compression, type the following command.

$ zfs set compression=off mypool
enable ZFS Compression on Linux

 You can check for the status of the ZFS compression by typing the following command.

$ zfs get all <pool name> | grep compress

This command will display the details of ZFS compression, i.e., whether it is disabled or running with a specific algorithm.

We hope this guide helped you learn how to enable ZFS compression on Linux, along with some general details about configuring ZFS on your system. We also hope that the commands you learned in this article further help you in your journey to master Linux.

Furthermore, if you’d like to learn how to fix the “No bootable medium found” in Virtualbox, click here.

If this guide helped you out, please share it.  🙂

Author

Leave a Reply

Your email address will not be published. Required fields are marked *