Skip to main content

ZFS on Linux with Ubuntu 18.04 LTS

Hands-On Lab

 

Photo of Kenny Armstrong

Kenny Armstrong

Linux Training Architect II in Content

Length

01:30:00

Difficulty

Intermediate

ZFS is an extremely powerful file system and volume manager for storage. Depending on how ZFS pools configured, they can self-heal files that have suffered bitrot, provide snapshots of data on volumes for quick backups, and have methods to completely duplicate pools to new disks, essentially keeping the same file systems going for years at a time. This lab introduces the ZFS on Linux kernel module and toolset that are are available in Ubuntu 18.04. We will use two spare disks to create a mirrored ZFS pool that provides compression and will store two copies of a file as a safety precaution. We will look at how we can view the status of this pool, and how to unmount a ZFS dataset and pool from the system.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

ZFS on Linux with Ubuntu 18.04 LTS

Introduction

ZFS is an extremely powerful file system and volume manager for storage. Depending on how ZFS pools configured, they can self-heal files that have suffered bitrot, provide snapshots of data on volumes for quick backups, and have methods to completely duplicate pools to new disks, essentially keeping the same file systems going for years at a time.

This lab introduces the ZFS on Linux kernel module and toolset that are are available in Ubuntu 18.04. We will use two spare disks to create a mirrored ZFS pool that provides compression and will store two copies of a file as a safety precaution. We will look at how we can view the status of this pool, and how to unmount a ZFS dataset and pool from the system.

Solution

Create Disk Labels

Using the gdisk command, create labels on /dev/xvdg and /dev/xvdh. Use the following:

DiskLabel
/dev/xvdgzfs1
/dev/xvdhzfs2

The first command will be:

sudo gdisk /dev/xvdg

and the second will be:

sudo gdisk /dev/xvdh

Each time, type c at the first prompt, enter the appropriate name when prompted (according to the table a little ways back), then make sure to type w at the last prompt, to write changes out to disk.

Install the ZFS Utilities and Kernel Module

Run the following command to install the needed software (Note: This step will take some time as the kernel modules will have to be compiled):

sudo apt -y install zfs-dkms zfsutils-linux

Once it installs, we can check to see if it's loaded with:

lsmod | grep zfs

Create the ZFS Pool

Create the ZFS pool named PoolA, adding the disk with the label zfs1 to it:

sudo zpool create -f PoolA zfs1

Then, verify the pool with:

zpool status PoolA

Next, create the backup dataset in this pool:

sudo zfs create PoolA/backup

Modify the ZFS File System Settings

Modify the ZFS file system settings on PoolA/backup by performing the following commands:

sudo zfs set compression=lz4 PoolA/backup
sudo zfs set copies=2 PoolA/backup

We can review all of the file system's settings with:

sudo zfs get all

Or, we can check on individual aspects, with these:

sudo zfs get compression PoolA/backup
sudo zfs get copies PoolA/backup

Attach Second Disk to Pool

Attach the disk labeled zfs2 to the existing pool:

sudo zpool attach PoolA zfs1 zfs2

All settings and configurations will automatically get mirrored to the second disk. We can verify the status of our pools with:

zpool status

Copy the /etc/services file over to the ZFS pool:

sudo cp /etc/services /PoolA/backup/

If all went well, then a quick ls /PoolA/backup ought to show us that a services file is sitting there, the one we just copied.

Unmount the ZFS Pool

Unmount the ZFS pool using:

sudo zfs unmount PoolA/backup

Verify that the /PoolA directory is no longer available (Note: on cloud servers, it can sometimes take a minute or two for the file systems to unmount):

ls /PoolA

This should show us nothing. And if we try to run the zfs unmout command again, we should get an error about it not being mounted now in the first place.

Conclusion

Well, that's all there is to it. We installed the kernel modules that make it possible to use ZFS in Ubuntu, then we created some shares that would could mount, write to, and then unmount. Congratulations!