Linux / Storage

How to Create and Destroy ZFS Snapshots on Ubuntu 19.10

22 Oct 2019 9:49am, by

As we noted last week, Ubuntu 19.10 has officially arrived and it brings along with it a number of really exciting features. Although the majority of those new options target desktop users, there is one particularly exciting feature that will benefit both desktop and server users. That feature is ZFS support.

First developed by Sun Microsystems for its Solaris Unix distro, ZFS is a combination 128-bit file system and logical volume manager that offers the following features:

  • Is scalable.
  • Offers support for high storage capacity and more efficient data compression.
  • Includes snapshots and rollbacks.
  • Supports copy-on-write clones.
  • Does continuous integrity checking and automatic repair.
  • 128-bit addressing
  • And much more.

Ask any admin and they’ll agree that the addition of ZFS is a big deal for Ubuntu. Why? The snapshots and rollback features alone are worth the price of entry (which, by the way, is free). With this feature, admins can roll back their systems to a working state (or a state that included accidentally deleted data). That’s quite a big deal.

Of course snapshots and rollbacks aren’t a new thing. In fact, many platforms have included this tool for years. So maybe Ubuntu is a bit behind the curve on this. But for anyone who uses Ubuntu this is a case of “better late than never.”

But how does ZFS work on Ubuntu? I’m glad you asked. Let me show you.

A Caveat

Before you dive into this, know that ZFS support in Ubuntu 19.10 is experimental. Although I’ve found it to be incredibly stable, you might think twice about using it in a production environment (until it is no longer listed as “experimental”).

Also, note that ZFS support is currently only offered during the desktop version installation. That doesn’t mean you cannot add support for the filesystem on the server version, but it’s not quite as simple. Because of this, I’ll be demonstrating on the desktop version of Ubuntu 19.10.


The first step is to enable ZFS at the install time of Ubuntu 19.10. During the installation, you will find a new option in the Installation type phase (Figure 1).

Figure 1: Selecting the ZFS option during installation.

Once the installation completes, reboot and log in.

If you’re using the server version of Ubuntu 19.10, you can always install ZFS support with the command:

Of course, should you go that route, you’ll have to take a few extra steps (such as creating datasets). With the desktop installation, you’ll find your entire directory hierarchy is made up of ZFS datasets, so there’s much less work to do.

First Steps with ZFS

Once you’ve logged into the desktop, you’ll want to open a terminal window and get a listing of your datasets. With Ubuntu installations that don’t use ZFS, you’d typically work with directory paths like /home/jack or /usr/local/. That’s not the case with ZFS-enabled systems. Instead, they work with datasets. A dataset is a type of filesystem that shares a storage pool (the most basic building block of ZFS).

To find your datasets, issue the command:

As you can see (in Figure 2), every directory is either found in the bpool (boot) or rpool (root) pool. 

Figure 2: Our dataset listing.

Let’s work with a user’s home directory. In this case, the dataset rpool/USERDATA/jack_bwcn4u.

Creating a Snapshot

The first thing we’re going to do is create a new snapshot of the /home/jack directory (which, remember, is the rpool/USERDATA/jack_bwcn4u dataset). Let’s say we want to create a snapshot tagged with today’s date. The command for this would be:

Of you could include the date command like so:

To verify that your snapshot was taken, issue the command:

You should see all current snapshots listed (Figure 3).

Figure 3: Our new snapshot has been created.

Rolling Back a Snapshot

Let’s say, for whatever reason, a directory was accidentally deleted out of that home directory. What do you do? Fortunately, you’ve taken a snapshot and can roll that snapshot back, such that the deleted directory returns.

First, let’s delete the ~/Documents directory with the command:

Issue the ls command and you can see the Documents directory is gone (Figure 4).

Our Documents directory has been deleted.

Now we’ll roll back the Friday snapshot to recover that directory. To do this, issue the command:

After the command completes, issue ls again to see that Documents has returned (Figure 5).

Figure 5: Documents is back.

Destroying Snapshots

Let’s say you’ve created a number of snapshots, or a particular snapshot has either corrupt or missing data. You might want to delete that snapshot. Let’s say we want to delete the rpool/USERDATA/jack_bwcn4u@FRIDAY10-18-19 snapshot. To do that, the command would be:

Once you’ve destroyed a snapshot it cannot be retrieved, so use that command with care. If you happen to have a particularly important snapshot that you don’t want destroyed, you can place a hold on it. To place a hold on our rpool/USERDATA/jack_bwcn4u@FRIDAY10-18-19 snapshot,  you would issue the command:

Now if you try to destroy that snapshot, you’ll see an error (Figure 6).

Figure 6: Cannot destroy this snapshot.

To destroy a held snapshot, you have to add the -d option like so:

That’s it, the held snapshot is gone.

And that’s the basics of creating and destroying snapshots with the newly added ZFS feature in Ubuntu 19.10. Give this a try on a testing environment and see how well it works. So far I’ve only discovered one issue that, when trying to roll back a snapshot, I had to reboot the machine before the rollback command would successfully run. Outside of that one issue, it’s been smooth sailing with ZFS and Ubuntu 19.10.

A newsletter digest of the week’s most important stories & analyses.