How to install ZFS on Qubes OS

published Feb 28, 2023, last modified Feb 08, 2024

A guide for advanced Qubes OS users and developers who want to use OpenZFS on their systems.

How to install ZFS on Qubes OS

Qubes OS is one of the most secure desktop operating systems out there.  ZFS is one of the safest file systems out there.

This guide will help you marry the both.

Why?

So why would you want to use ZFS with Qubes OS?  Here are a few reasons:

  1. Qubes OS has native support for storing the data of your qubes on ZFS volumes.
  2. ZFS checksums all your data, so undetectable corruption is impossible.
    1. If you use mirroring to store your data, data corruption is automatically healed too.
  3. ZFS also compresses your data, so your disks go a much longer way — and compression makes disk accesses faster too.
    1. You can choose between light compression all the way to the heaviest gzip compression.
  4. You can use tools like zfs snapshot and zfs send / recv to safeguard your qubes and experiment with them safely. 
    1. Do you want to keep extra snapshots of a qube?  No problem!
    2. Do you want automatic snapshots?  zfs-auto-snapshot to the rescue!
    3. Do you want to release snapshot space for a specific qube?  You can do that as well.
  5. It is the most tested file system of them all, so your data is extremely safe with it.
  6. Managing a ZFS pool — adding storage, checking consistency, snapshotting and reverting — is much, much easier than managing LVM volumes.
    1. Do you want to pivot to a larger hard disk or SSD while the system runs?  That's easy with ZFS' zpool attach and zpool detach.
  7. Disk space management in ZFS is superb.
    1. In Qubes OS, all qubes backed by ZFS support TRIM, which means qubes automatically release all freed data back to the operating system.
    2. ZFS itself supports TRIM, automatic (with autotrim pool property) or manual (through zpool trim), to keep your SSDs running at their top speed.

How?

The following instructions will only work on Qubes OS 4.2 and later.

Clone this repository to a trustworthy AppVM of your choice, then transfer the contents of the repository to a folder in your Qubes OS dom0.  Here is a summary of instructions:

In your disposable qube

cd ; git clone https://github.com/Rudd-O/zfs-fedora-installer

In dom0, after cloning

cd ; qvm-run -p <name of dispvm> tar c zfs-fedora-installer | tar xv

Be aware that you will be executing code made by me on your dom0.

Change into the folder containing the transferred repository (zfs-fedora-installer), and run sudo ./deploy-zfs.

The script will obtain the necessary source code and install the necessary dependencies on your Qubes OS system.  After a few minutes, you'll have a from-source deployment of ZFS and ZFS-DKMS on your system, such that every kernel upgrade automatically builds and installs its corresponding ZFS module.  The sources can be found in /usr/src.

Now systemctl restart systemd-udevd to pick up the new udev rules (the script will not do that for you).

Try ZFS by running sudo zfs.

That is all.  You are ready to migrate your qubes to your ZFS pool.  Enjoy!