I’m writing a bit about ZFS these days, and I thought I’d write a bit about why I am using it, why it might or might not be interesting for you, and what you might do about it.
ZFS Features and Background
ZFS is not just a filesystem in the traditional sense, though you can use it that way. It is an integrated storage stack, which can completely replace the need for LVM, md-raid, and even hardware RAID controllers. This permits quite a bit of flexibility and optimization not present when building a stack involving those components. For instance, if a drive in a RAID fails, it needs only rebuild the parts that have actual data stored on them.
Let’s look at some of the features of ZFS:
- Full checksumming of all data and metadata, providing protection against silent data corruption. The only other Linux filesystem to offer this is btrfs.
- ZFS is a transactional filesystem that ensures consistent data and metadata.
- ZFS is copy-on-write, with snapshots that are cheap to create and impose virtually undetectable performance hits. Compare to LVM snapshots, which make writes notoriously slow and require an fsck and mount to get to a readable point.
- ZFS supports easy rollback to previous snapshots.
- ZFS send/receive can perform incremental backups much faster than rsync, particularly on systems with many unmodified files. Since it works from snapshots, it guarantees a consistent point-in-time image as well.
- Snapshots can be turned into writeable “clones”, which simply use copy-on-write semantics. It’s like a cp -r that completes almost instantly and takes no space until you change it.
- The datasets (“filesystems” or “logical volumes” in LVM terms) in a zpool (“volume group”, to use LVM terms) can shrink or grow dynamically. They can have individual maximum and minimum sizes set, but unlike LVM, where if, say, /usr gets bigger than you thought, you have to manually allocate more space to it, ZFS datasets can use any space available in the pool.
- ZFS is designed to run well in big iron, and scales to massive amounts of storage. It supports SSDs as L2 cache and ZIL (intent log) devices.
- ZFS has some built-in compression methods that are quite CPU-efficient and can yield not just space but performance benefits in almost all cases involving compressible data.
- ZFS pools can host zvols, a block device under /dev that stores its data in the zpool. zvols support TRIM/DISCARD, so are ideal for storing VM images, as they can instantly release space released by the guest OS. They can also be snapshotted and backed up like the rest of ZFS.
Although it is often considered a server filesystem, ZFS has been used in plenty of other situations for some time now, with ports to FreeBSD, Linux, and MacOS. I find it particularly useful:
- To have faith that my photos, backups, and paperwork archives are intact. zpool scrub at any time will read the entire dataset and verify the integrity of every bit.
- I can create snapshots of my system before running apt-get dist-upgrade, making it easy to track down issues or roll back to a known-good configuration. Ideal for people tracking sid or testing. One can also easily simply boot from a previous snapshot.
- Many scripts exist that make frequent snapshots, and retain the for a period of time as a way of protecting work in progress against an accidental rm. There is no reason not to snapshot /home every 5 minutes, for instance. It’s almost as good as storing / in git.
The added level of security in having cheap snapshots available is almost worth it by itself.
ZFS drawbacks
Compared to other Linux filesystems, there are a few drawbacks of ZFS:
- CDDL will prevent it from ever being part of the Linus kernel tree
- It is more RAM-hungry than most, although with tuning it can even run on the Raspberry Pi.
- A 64-bit kernel is strongly preferred, even in low-memory situations.
- Performance on many small files may be less than ext4
- The ZFS cache does not shrink and expand in response to changing RAM usage conditions on the system as well as the normal Linux cache does.
- Compared to btrfs, ZFS lacks some features of btrfs, such as being able to shrink an existing pool or easily change storage allocation on the fly. On the other hand, the features in ZFS have never caused me a kernel panic, and half the things I liked about btrfs seem to have.
- ZFS is already quite stable on Linux. However, the GRUB, init, and initramfs code supporting booting from a ZFS root and /boot is less stable. If you want to go 100% ZFS, be prepared to tweak your system to get it to boot properly. Once done, however, it is quite stable.
Converting to ZFS
I have written up an extensive HOWTO on converting an existing system to use ZFS. It covers workarounds for all the boot-time bugs I have encountered as well as documenting all steps needed to make it happen. It works quite well.
Additional Hints
If setting up zvols to be used by VirtualBox or some such system, you might be interested in managing zvol ownership and permissions with udev.
Why and how to convert to #ZFS on #Linux: http://t.co/vaxfVwVhMz
Planet Debian: John Goerzen: Why and how to run ZFS on Linux http://t.co/FfQM6t1eqO
John Goerzen: Why and how to run ZFS on Linux http://t.co/4ol65ANfk5 #debian #linux
John Goerzen: Why and how to run ZFS on Linux: I’m writing a bit about ZFS these days, and I thought I’d write… http://t.co/GTqo8XILyv
John Goerzen: Why and how to run ZFS on Linux: I’m writing a bit about ZFS these days, and I thought I’d write… http://t.co/2OxbDcXEIK
RT @planetdebian: John Goerzen: Why and how to run ZFS on Linux: I’m writing a bit about ZFS these days, and I thought I’d write… http://…
RT @jgoerzen: Why and how to convert to #ZFS on #Linux: http://t.co/vaxfVwVhMz
RT @jgoerzen: Why and how to convert to #ZFS on #Linux: http://t.co/vaxfVwVhMz
I am running my data tombs on zfs with my trusty sid system for some years now. I have not set up roots fs on zfs or got dkms to compile new modules on the fly for me but I am very happy anyway. That she’s a memory hog is very true but on low mem systems running other applications memory max settings can be applied.
Anyway: just wanted to say nice to read about zfs on planet debian.
regards,
Martin
John Goerzen: Why and how to run ZFS on Linux http://t.co/g4Ag1DpiA9
RT @planetdebian: John Goerzen: Why and how to run ZFS on Linux: I’m writing a bit about ZFS these days, and I thought I’d write… http://…
Why and how to run #ZFS on #Linux http://t.co/6uNO3aMMdL
RT @planetdebian: John Goerzen: Why and how to run ZFS on Linux: I’m writing a bit about ZFS these days, and I thought I’d write… http://…
Why and how to run #ZFS on #Linux http://t.co/0jtT84Pwa8
Why and how to run ZFS on Linux | The Changelog http://t.co/8hF8rhZNSS