Getting Started With ZFS Filesystem on Ubuntu 19.10

One of the main features of Ubuntu 19.10 is support for ZFS. Now you can easily install Ubuntu with on ZFS without any extra effort.

Normally, you install Linux with Ext4 filesystem. But if you do a fresh install of Ubuntu 19.10, you’ll see the option to use ZFS on the root. You must not use it on a dual boot system though because it will erase the entire disk.

ZFS filesystem support in Ubuntu 19.10
You can choose ZFS while installing Ubuntu 19.10

Let’s see why ZFS matters and how to take advantage of it on ZFS install of Ubuntu.

How ZFS is different than other filesystems?

ZFS is designed with two major goals in mind: to handle large amounts of storage and prevent data corruption. ZFS can handle up to 256 quadrillion Zettabytes of storage. (Hence the Z in ZFS.) It can also handle files up to 16 exabytes in size.

If you are limited to a single drive laptop, you can still take advantage of the data protection features in ZFS. The copy-on-write feature ensures that data that is in use is not overwritten. Instead, the new information is written to a new block and the filesystem’s metadata is updated to point to the new block. ZFS can easily create snapshots of the filesystem. These snapshots track changes made to the filesystem and share with the filesystem the data that is the same to save space.

ZFS assigned a checksum to each file on the drive. It is constantly checking the state of the file against that checksum. If it detects that the file has become corrupt, it will attempt to automatically repair that file.

I have written a detailed article about what is ZFS and what its features are. Please read it if you are interested in knowing more on this topic.

Note

Keep in mind that the data protection features of ZFS can lead to a reduction in performance.

Using ZFS on Ubuntu [For intermediate to advanced users]

Using ZFS on Ubuntu

Once you have a clean install of Ubuntu with ZFS on the main disk you can start taking advantage of the features that this filesystem has.

Please note that all setup of ZFS requires the command line. I am not aware of any GUI tools for it.

Creating a ZFS pool

The section only applies if you have a system with more than one drive. If you only have one drive, Ubuntu will automatically create the pool during installation.

Before you create your pool, you need to find out the id of the drives for the pool. You can use the command lsblk to show this information.

To create a basic pool with three drives, use the following command:

 sudo zpool create pool-test /dev/sdb /dev/sdc /dev/sdd. 

Remember to replace pool-test with the pool name of your choice.

This command will set up “a zero redundancy RAID-0 pool”. This means that if one of the drives becomes damaged or corrupt, you will lose data. If you do use this setup, it is recommended that you do regular backups.

You can alos add another disk to the pool by using this command:

sudo zpool add pool-name /dev/sdx

Check the status of your ZFS pool

You can check the status of your new pool using this command:

 sudo zpool status pool-test 
Zpool Status
Zpool Status

Mirror a ZFS pool

To ensure that your data is safe, you can instead set up mirroring. Mirroring means that each drive contains the same data. With mirroring setup, you could lose two out of three drives and still have all of your information.

To create a mirror, you can use something like this:

sudo zpool create pool-test mirror /dev/sdb /dev/sdc /dev/sdd

Create ZFS Snapshots for backup and restore

Snapshots allow you to create a fall-back position in case a file gets deleted or overwritten. For example, let’s create a snapshot, delete some folder in my home directory and restore them.

First, you need to find the dataset you want to snapshot. You can do that with the

 zfs list
Zfs List
Zfs List

You can see that my home folder is located in rpool/USERDATA/johnblood_uwcjk7.

Let’s create a snapshot named 1910 using this command:

sudo zfs snapshot rpool/USERDATA/[email protected]

The snapshot will be created very quickly. Now, I am going to delete the Downloads and Documents directories.

Now to restore the snapshot, all you have to do is run this command:

sudo zfs rollback rpool/USERDATA/[email protected] 

The length of the rollback depends on how much the information changed. Now, you can check the home folder and the deleted folders (and their content) will be returned to their correct place.

To ZFS or not?

This is just a quick glimpse at what you can do with ZFS on Ubuntu. For more information, check out Ubuntu’s wiki page on ZFS. I also recommend reading this excellent article on ArsTechnica.

This is an experimental feature and if you are not aware of ZFS and you want to have a simple stable system, please go with the standard install on Ext4. If you have a spare machine that you want to experiment with, then only try something like this to learn a thing or two about ZFS. If you are an ‘expert’ and you know what you are doing, you are free to experiment ZFS wherever you like.

At this time the implementation of ZFS in Ubuntu 19.10 is experimental because of the way the disk is laid out may change in the Ubuntu 20.04 release. They are not guaranteeing that you will be able to upgrade if you have ZFS installed.

According to the Ubuntu podcast, the Ubuntu desktop team is working on a tool named zsys. It will hook into apt and grub. As you upgrade your system, zsys will take snapshots so you can boot into a previous snapshot if the upgrade fails. It will arrive in the 20.04 release.

Have you ever used ZFS? Please let us know in the comments below. If you found this article interesting, please take a minute to share it on social media, Hacker News or Reddit.

Similar Posts

  • Ubunto “fossa” did a great job of popularizing ZFS as the root drive. It is a bit slow though. Also a lot more people know about those asian cats which keep focussing on stuff for some reason.

    • ZFS is very fast! But mostly not very properly configured. Expensive raid controllers: which have no use and slowdown the system. and lots of SSD which have no use. What ZFS needs is lots of memory. two tiny cache drives. I used to have a a system for 1100 people. 47 drives. two cache drives of 8MB. Forgotten their names ? Intent ? Log? The OS sees the memory only so writes to memory. The fastest device on a system. Further it is simple to maintain: he you have faulty drive i replaced it with a spare. When you have time, only than you replace the drive which is blinking. Test ZFS ? Use a usb hub with 8 sticks : and do all tests: Transfer big files: but is slow? add a drive Life! too small ? same. Labelling ? no: take out all sticks , shuffle them: it rearranges them. Replaced the faulty drive? it will automatically uses and rearrange the spare

  • Interesting! Ran into this while researching raid1. I chose to try the ZFS instead.

    I have two 500GB Seagate drives and wanted to implement raid1. The ZFS installer IS Beta, so it would only install on one of my drives (sda). Afterwards I had to duplicate the sda to my sdb to get the same partition setup (Gparted not yet updated for ZFS).
    After DD completed I could not add sdb5 to my rpool since it thought it was already in a pool. So I had to use GParted to reformat the partition5 to ‘Cleared’. (It also did not like an ‘Ext4’ partition)
    Now I could add the 2nd drive

    All in all, MUCH easier than Raid (mdadm). so summary:
    1) Install as indicated in article
    this creates 5 partitions on the drive
    2) reboot to new install
    3) duplicate to 2nd drive
    # sudo dd bs=1M if=/dev/sda of=/dev/sdb
    4) use Gparted to format sdb4 and sdb5 to ‘Cleared’
    5)Add new disk partitions to the pools
    # sudo zpool attach rpool /dev/sda5 /dev/sdb5
    # sudo bpool attach rpool /dev/sda4 /dev/sdb4
    6) wait for resilver to finish. Mine took about 5min.

    I spent 2 days trying to get mdadm to work. Had ZFS running in a few hours.

  • nice way to learn about ZFS is to exercise on USB sticks. Take a hub with many slots and and many sticks. Make a pool with one stick, measure performance. copy data to a pool, and add a device to the pool while the copy is active: what happens to the speed? Make a mirror with a spare. remove a part of the mirror. See what happens. make a a big array with many sticks. Do not label them. Put them in random order back. Result?

    Do NOT use raid controllers for a zfs system. They create bottlenecks. And unreliabilities.

    There is no need for ssd’s , Not in the raid system, just for the log and the cache. Two drives the rest can be anything.
    What you need enough space for the transfer of data and intend from memory to disk and disks, I think i had 8MB each for a system with 47 1 GB disks.

    ZFS is clever it stores much used data on the fastest drives.

    ZFS is a poor mans dream: like intended: Raid is an array of cheap drives. Drive sales men deny that. Make a pool of two same sized drives in a mirror: too slow? add a mirror. to small ? Idem. Add 1 spare to your mirrors. If a drive fails, automagically the spare is put to work.

    etc etc

    regards

    Frank

  • For the moment, in addition to being experimental, there is no snapshot automation and there is not yet a graphical interface. Better openSUSE, which offers everything enabled by default with Btrfs, a snapper graphic interface and snapshot automation, which allows the user to cancel system changes or updates by returning to the previous snapshot. But maybe here we only talk about Ubuntu …

    • If a filing system can be labelled experimental it should be btrfs. Just recently adopted if one compares to ZFS.

      ZFS is based on original new ideas how blocks of data are managed.

      btrfs is the result of enhancing an existing filing system. This enhancing is not finished yet, many of the original ideas in ZFS are not implemented yet.

      Calling ZFS a filing system is a misnomer. Is it CIFS ehh yes, act as a dump devices? sure, a swapdevices ? yes of course, a raw device? =array of blocks, yeah. ISCSI target? yeah . Snapshot automation ? yep. etc etc.

      The concept of ZFS can be overwelming, and comparing commands does not justify its posibilities.

      Thanks to mishandling, greed of Oracle, like closing an opensource system, ZFS has not become the mainstream system yet.

      And by the way it runs on Suse!!

      Kind regards

      Frank

    • I have seen why you comment about ZFS being experimental. You are right about it: but it is NOT ZFS, rather the installer, to create a root filesystem.
      One uses that once… Apologies …

      Frank