Ubuntu 20.04’s zsys adds ZFS snapshots to package management

Closeup photo of an attentive wildcat.
Enlarge / This is a Fossa. It appears to be focusing. (Cryptoprocta ferox is a small, catlike carnivore native to Madagascar.)

Last October, an experimental ZFS installer showed up in Eoan Ermine, the second interim Ubuntu release of 2019. Next month, Focal Fossa—Ubuntu’s next LTS (Long Term Support) release—is due to drop, and it retains the ZFS installer while adding several new features to Ubuntu’s system management with the fledgling zsys package.

Phoronix reported this weekend that zsys is taking snapshots prior to package-management operations now, so we decided to install the latest Ubuntu 20.04 daily build and see how the new feature works.

Taking Focal Fossa for a quick spin

Focal installs much as any other Ubuntu release has, but it retains 19.10’s ZFS installer—which is still hidden behind “advanced features” and still labeled experimental. After selecting a ZFS install, you give your OK to the resulting partition layout—with one primary partition for UEFI boot and three logical partitions for swap, boot ZFS pool, and root ZFS pool. A few minutes later, you’ve got yourself an Ubuntu installation.

A quick look under the hood

After installing Fossa, the first thing we did was verify the installed version of zsys. The apt management snapshots were added very recently in 0.4.1, and we’ve learned not to take for granted what’s installed on beta or pre-beta daily builds of Linux distributions. Zsys was, in fact, already installed by default and was at version 0.4.1.

There weren’t any snapshots on the freshly-installed system yet, so we did a quick apt install gimp. Afterwards, we saw that zsys had taken a snapshot in every dataset present on rpool. Having a snapshot taken prior to installing new packages means that, if something should go haywire, we can easily revert the system to its state prior to the new package being installed. Carving the system up into so many different datasets means, in turn, that we can roll back only those parts of the system affected by the package manager—for example, we can roll back packages without affecting data in the user’s home directory.

After installing gimp and seeing new snapshots available, we tried installing a second package. One apt install pv later, we again checked for snapshots. Although we still found the snapshots taken prior to installing gimp, there were no new snapshots to roll back our pv installation. After several more experimental installations and removals with no new snapshots, we started grep-ing our way through the /etc directory to find out why.

In apt.conf.d we find a config file named 90_zsys_system_autosnapshot that adds a pre-install hook to dpkg. This pre-install hook calls zsys-system-autosnapshot prior to making any changes to the package system. We weren’t sure why we hadn’t gotten any new snapshots, so we tried running zsys-system-autosnapshot directly—still no new snapshot.

When we then took a look at zsys-system-autosnapshot itself, the reason for no new snapshots being taken was obvious. A minimum interval is built into that script, so that it exits without doing anything if it’s been less than 20 minutes since the last time it took snapshots.

We’re pretty dubious about this minimum-interval feature. On the one hand, once you accumulate a few thousand snapshots, you can begin seeing filesystem performance issues. On the other hand, we foresee a lot of problematic package installations not getting covered with snapshots this way.

Zsys is still early in development

We should note that zsys is nowhere near complete yet. The tool promises all manner of added functionality, and it’s already useful—but it’s still missing so much of the polish that normal users will need to see.

We can see that zsys refers to these automatically generated snapshots as “system state”—and that zsysctl save will take those snapshots, and zsysctl show will give us a high-level overview of what sets of state have been saved. But there’s no corresponding zsysctl load yet, and until there is, trying to use these saves to actually recover from disaster will remain a little more “expert” of an operation that it ought to be.

Ubuntu’s ZFS installer carves up the base system into a bewildering 21 separate datasets, so zsys really needs that high-level rollback assistant. It’s easy enough to roll back any individual dataset using the zfs command itself—e.g., zfs rollback rpool/USERDATA/jim_v1qce1@autosys_pmxbuj—but we don’t anticipate users having a good time navigating such commands.

We fully expect zsysctl to add functionality for easier rollbacks eventually. It’s just not here yet.

View original article here Source