Dustin Kirkland
on 16 February 2016
ZFS is *the* FS for Containers in Ubuntu 16.04!
Ubuntu 16.04 LTS (Xenial) is only a few short weeks away, and with it comes one of the most exciting new features Linux has seen in a very long time…
ZFS — baked directly into Ubuntu — supported by Canonical.
What is ZFS?
ZFS is a combination of a volume manager (like LVM) and a filesystem (like ext4, xfs, or btrfs).
ZFS one of the most beloved features of Solaris, universally coveted by every Linux sysadmin with a Solaris background. To our delight, we’re happy to make to OpenZFS available on every Ubuntu system. Ubuntu’s reference guide for ZFS can be found here, and these are a few of the killer features:
- snapshots
- copy-on-write cloning
- continuous integrity checking against data corruption
- automatic repair
- efficient data compression
These features truly make ZFS the perfect filesystem for containers.
What does “support” mean?
You’ll find zfs.ko automatically built and installed on your Ubuntu systems. No more DKMS-built modules!
$ locate zfs.ko
/lib/modules/4.4.0-4-generic/kernel/zfs/zfs/zfs.ko
You’ll see the module loaded automatically if you use it.
$ lsmod | grep zfs
zfs 2801664 11
zunicode 331776 1 zfs
zcommon 57344 1 zfs
znvpair 90112 2 zfs,zcommon
spl 102400 3 zfs,zcommon,znvpair
zavl 16384 1 zfs
- The user space zfsutils-linux package will be included in Ubuntu Main, with security updates provided by Canonical (as soon as this MIR is completed).
- As always, industry leading, enterprise class technical support is available from Canonical with Ubuntu Advantage services.
How do I get started?
It’s really quite simple! Here’s a few commands to get you up and running with ZFS and LXD in 60 seconds or less.
First, make sure you’re running Ubuntu 16.04 (Xenial).
$ head -n1 /etc/issue
Ubuntu Xenial Xerus (development branch) \n \l
Now, let’s install lxd and zfsutils-linux, if you haven’t already:
$ sudo apt install lxd zfsutils-linux
Next, let’s use the interactive lxd init command to setup LXD and ZFS. In the example below, I’m simply using a sparse, loopback file for the ZFS pool. For best results (and what I use on my laptop and production servers), it’s best to use a raw SSD partition or device.
$ sudo lxd init
Name of the storage backend to use (dir or zfs): zfs
Create a new ZFS pool (yes/no)? yes
Name of the new ZFS pool: lxd
Would you like to use an existing block device (yes/no)? no
Size in GB of the new loop device (1GB minimum): 2
Would you like LXD to be available over the network (yes/no)? no
LXD has been successfully configured.
We can check our ZFS pool now:
$ sudo zpool list
NAME SIZE ALLOC FREE EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT
lxd 1.98G 450K 1.98G - 0% 0% 1.00x ONLINE -
$ sudo zpool status
pool: lxd
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
lxd ONLINE 0 0 0
/var/lib/lxd/zfs.img ONLINE 0 0 0
errors: No known data errors
$ lxc config get storage.zfs_pool_name
storage.zfs_pool_name: lxd
Finally, let’s import the Ubuntu LXD image, and launch a few containers. Note how fast containers launch, which is enabled by the ZFS cloning and copy-on-write features:
$ newgrp lxd
$ lxd-images import ubuntu --alias ubuntu
Downloading the GPG key for http://cloud-images.ubuntu.com
Progress: 48 %
Validating the GPG signature of /tmp/tmpa71cw5wl/download.json.asc
Downloading the image.
Image manifest: http://cloud-images.ubuntu.com/server/releases/trusty/release-20160201/ubuntu-14.04-server-cloudimg-amd64.manifest
Image imported as: 54c8caac1f61901ed86c68f24af5f5d3672bdc62c71d04f06df3a59e95684473
Setup alias: ubuntu
$ for i in $(seq 1 5); do lxc launch ubuntu; done
...
$ lxc list
+-------------------------+---------+-------------------+------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | EPHEMERAL | SNAPSHOTS |
+-------------------------+---------+-------------------+------+-----------+-----------+
| discordant-loria | RUNNING | 10.0.3.130 (eth0) | | NO | 0 |
+-------------------------+---------+-------------------+------+-----------+-----------+
| fictive-noble | RUNNING | 10.0.3.91 (eth0) | | NO | 0 |
+-------------------------+---------+-------------------+------+-----------+-----------+
| interprotoplasmic-essie | RUNNING | 10.0.3.242 (eth0) | | NO | 0 |
+-------------------------+---------+-------------------+------+-----------+-----------+
| nondamaging-cain | RUNNING | 10.0.3.9 (eth0) | | NO | 0 |
+-------------------------+---------+-------------------+------+-----------+-----------+
| untreasurable-efrain | RUNNING | 10.0.3.89 (eth0) | | NO | 0 |
+-------------------------+---------+-------------------+------+-----------+-----------+
We’ve written a short reference guide to help with getting started, and understanding the ZFS terminology. This touches the basics on setting up ZFS pools as well as creating and using ZFS file systems.
If you are new to ZFS, I recommend having a look at the reference guide to get you started.