1. ZFS Overview
To work with ZFS, its important to understand the basics of the technical side and implementation. I have seen lots of failures that have stemmed from the fact that people were trying to administer or even troubleshoot ZFS file systems without really understanding what they were doing and why. ZFS goes to great lengths to protect your data, but nothing in the world is user proof. If you try really hard, you will break it. Thats why its a good idea to get started with the basics.
Note
On most Linux distributions, ZFS is not available by default. For up-to-date information about the implementation of ZFS on Linux, including the current state and roadmap, visit the projects home page: http://zfsonlinux.org/ . Since Ubuntu Xenial Xerus, the 16.04 LTS Ubuntu release, Canonical has made ZFS a regular, supported file system. While you cant yet use it during the installation phase, at least not easily, it is readily available for use and is a default file system for LXD (a next-generation system container manager).
In this chapter, we look at what ZFS is and cover some of the key terminology.
What Is ZFS?
ZFS is a copy-on-write ( COW ) file system that merges a file system, logical volume manager, and software RAID. Working with a COW file system means that, with each change to the block of data, the data is written to a completely new location on the disk. Either the write occurs entirely, or it is not recorded as done. This helps to keep your file system clean and undamaged in the case of a power failure. Merging the logical volume manager and file system together with software RAID means that you can easily create a storage volume that has your desired settings and contains a ready-to-use file system.
Note
ZFSs great features are no replacement for backups. Snapshots, clones, mirroring, etc., will only protect your data as long as enough of the storage is available. Even having those nifty abilities at your command, you should still do backups and test them regularly.
COW Principles Explained
The Copy On Write (COW) design warrants a quick explanation, as it is a core concept that enables some essential ZFS features. Figure shows a graphical representation of a possible pool; four disks comprise two vdevs (two disks in each vdev). vdev is a virtual device built on top of disks, partitions, files or LUNs. Within the pool, on top of vdevs, is a file system. Data is automatically balanced across all vdevs, across all disks.
Figure 1-1
Graphical representation of a possible pool
Figure presents a single block of freshly written data.
Figure 1-2
Single data block
When the block is later modified, it is not being rewritten. Instead, ZFS writes it anew in a new place on disk, as shown in Figure . The old block is still on the disk, but ready for reuse, if free space is needed.
Figure 1-3
Rewritten data block
Lets assume that before the data has been modified, the system operator creates a snapshot. The DATA 1 SNAP block is being marked as belonging to the file system snapshot. When the data is modified and written in new place, the old block location is recorded in a snapshot vnodes table. Whenever a file system needs to be restored to the snapshot time (when rolling back or mounting a snapshot), the data is reconstructed from vnodes in the current file system, unless the data block is also recorded in the snapshot table ( DATA 1 SNAP ) as shown in Figure .
Figure 1-4
Snapshotted data block
Deduplication is an entirely separate scenario. The blocks of data are being compared to whats already present in the file system and if duplicates are found, only a new entry is added to the deduplication table. The actual data is not written to the pool. See Figure .
Figure 1-5
Deduplicated data block
ZFS Advantages
There are many storage solutions out in the wild for both large enterprises and SoHo environments. It is outside the scope of this guide to cover them in detail, but we can look at the main pros and cons of ZFS.
Simplified Administration
Thanks to merging volume management, RAID, and file system all in one, there are only two commands you need use to create volumes, redundancy levels, file systems, compression, mountpoints, etc. It also simplifies monitoring, since there are two or even three less layers to be looked out for.
Proven Stability
ZFS has been publicly released since 2005 and countless storage solutions have been deployed based on it. Ive seen hundreds of large ZFS storages in big enterprises and Im confident the number is hundreds if not thousands more. Ive also seen small, SoHo ZFS arrays. Both worlds have witnessed great stability and scalability, thanks to ZFS.
Data Integrity
ZFS was designed with data integrity in mind. It comes with data integrity checks, metadata checksumming, data failure detection (and, in the case of redundant setup, possibly fixing it), and automatic replacement of failed devices.
Scalability
ZFS scales well, with the ability to add new devices, control cache, and more.
ZFS Limitations
As with every file system, ZFS also has its share of weaker points that you need to keep in mind to successfully operate the storage.
80% or More Principle
As with most file systems, ZFS suffers terrible performance penalty when filled up to 80% or more of its capacity. It is a common problem with file systems. Remember, when your pool starts filling to 80% of capacity, you need to look at either expanding the pool or migrating to a bigger setup.
You cannot shrink the pool, so you cannot remove drives or vdevs from it once they have been added.
Limited Redundancy Type Changes
Except for turning a single disk pool into a mirrored pool, you cannot change redundancy type. Once you decide on a redundancy type, your only way of changing it is to destroy the pool and create a new one, recovering data from backups or another location.
Key Terminology
Some key terms that youll encounter are listed in the following sections.
Storage Pool
The storage pool is a combined capacity of disk drives. A pool can have one or more file systems. File systems created within the pool see all the pools capacity and can grow up to the available space for the whole pool. Any one file system can take all the available space, making it impossible for other file systems in the same pool to grow and contain new data. One of the ways to deal with this is to use space reservations and quotas.