ZFS module included in the snap?


I was wondering how is LXD able to use a ZFS storage pool even when ZFS is installed on the host?

After creating and using the pool, I can install ZFS on the host and indeed see that a zpool with multiple datasets are in use. How is LXD able to use ZFS since it requires a kernel module? Does it come with the snap? Is ZFS inside the snap the same version as available from the 18.04 repository?

Snaps have their own filesystem and indeed, we do ship our own version of ZFS in there.
We include the latest versions of ZFS 0.6, 0.7 and 0.8, then select the right version based on the version of the kernel module.

The tools we ship are usually slightly newer than what’s in Ubuntu but those are just bugfix releases and as you noticed, you can totally use the distro’s version to interact with ZFS.

1 Like

Ok, so snaps can add and load kernel modules?

Most snaps can’t, the LXD snap can load kernel modules indeed though we do not ship any in the snap.
What we ship in the snap is the ZFS tools, the kernel module we ask the system to load normally.

I’m starting to understand more but… Does it mean that Ubuntu comes with a disabled ZFS module? This should be impossible because of ZFS licensing so I’m a bit lost :thinking:

Canonical performed a license review of ZFS in 2016 and concluded that it’s OK to have ZFS precompiled in the stock Ubuntu Linux kernel. Other distributions use the DKMS version of ZFS, which means that ZFS is loaded separately. All that is for the kernel modules of ZFS.

For LXD to use ZFS, first the kernel modules must be loaded by the operating system. Then, LXD should have access to the ZFS client software (ZFS tools). As @stgraber mentioned, there are several versions packaged in the snap so the user that has the LXD snap does not have to worry about the client software.

However, if you are using the DEB package of LXD, then you need to take care and install zfsutils-linux before running sudo lxd init. Current versions of LXD will only show ZFS as an option for a storage driver if you have zfsutils-linux installed.

1 Like

You also can skip installing zfs tools on the host if you add the library path of zfs and call the zfs binary inside the snap:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/snap/lxd/current/zfs-0.8/lib /snap/lxd/current/zfs-0.8/bin/zfs

Thank you very much! I didn’t know of canonical point of view, that’s interesting.

Unrelated: Does it mean that theoretically, Ubuntu could offer ZFS on / during the installation process?

ZFS is not offered yet as an installation option and I believe it is because it’s complicated to setup and use for most users. There are some nice tutorials though, like Ubuntu 18.04 Root on ZFS.

We don’t offer ZFS for root devices out of the box, though it’s possible to do it manually with quite a lot of care, that’s what I have on my laptop.

MAAS allows for Ubuntu installations with a ZFS root filesystem too, but that’s limited to servers deployed with it.

1 Like

Great stuff from Canonical :slight_smile: