Talk Tech to Me: Configuring ZFS on Linux

If you aren't familiar with zpool and zvol, don't fret. Our Linux guru, Jason Eckert, is back to “Talk Tech to Me” with a crash course on configuring ZFS.

Talk Tech to Me, brought to you by CompTIAOur Linux guru, Jason Eckert, is back to “Talk Tech to Me” with a few crash courses on some of the hottest Linux topics. Here’s his second in the three-part series of articles full of commands and step-by-step instructions to help you master Linux.

Read more from Jason in All About Linux and Linux+3 Ways CompTIA Linux+ Helps New Grads Land Jobs and Talk Tech to Me: Using Linux BASH on Windows 10 .

What is ZFS?

Zettabyte File System (ZFS) is a 128-bit filesystem (capacity = 256 quadrillion Zettabytes) initially created by Sun Microsystems in 2001 and is available on nearly every Linux or UNIX operating system. Since ZFS does not currently have a GPL-compatible license, it cannot be bundled within a Linux distribution, but can be easily added afterward. ZFS On Linux maintains ZFS support.

Why is ZFS Important?

When it comes to fault tolerance of data, we’ve traditionally relied on storage technologies such as Redundant Array of Independent Disks (RAID). However, RAID is a very old technology that doesn’t protect against the different types of file corruption that can occur from writing to the filesystem on the storage devices themselves, including:

  • Accidental driver overwrites.
  • Bit rot.
  • Disk firmware bugs.
  • Driver and kernel buffer errors.
  • Misdirected writes.
  • Phantom writes.
  • Silent data corruption.

Using the ZFS filesystem on these storage devices protects against these problems. ZFS detects and repairs data errors in real time and can work with thousands of different storage devices of nearly any type (local hard disks and solid-state drives (SSDs), storage area networks (SANs), remote shares, etc.).

In addition to incredible performance due to caching, ZFS also supports huge numbers of files, online resizing/modification and bleeding-edge storage technologies such as peripheral component interconnect express (PCIe) SSDs and battery-backed RAM disk devices with ultra-low latency. Consequently, ZFS is often used by the largest Linux and UNIX systems in the world!

Installing ZFS on Linux

How you’ll install ZFS will differ based on your Linux distribution.

For example, to install ZFS on Ubuntu 14.04 LTS, you could run the following commands as the root user:

apt-get -y install build-essential gawk zlib1g-dev uuid-dev vim-nox python-software-properties

add-apt-repository ppa:zfs-native/stable

apt-get update

apt-get install ubuntu-zfs

 

Next, you’ll need to edit the /etc/modules file and add the following entries to ensure that the correct modules are loaded at boot time:

spl

zavl

znvpair

zunicode

zcommon

zfs

 

Finally, you’ll need to run the update-initramfs –u command to update the disk and module support for the boot image.

Configuring ZFS Volumes

Although ZFS configuration can be quite complex when it comes to very large systems that host thousands of different storage devices (e.g., cloud servers and large data centers), it’s not difficult to configure ZFS for use in a typical production environment.

ZFS pools are groups of storage devices that ZFS can manage (local disks, SANs, shared devices, large raw files, etc.), and ZFS filesystems are simply ZFS-managed filesystems that are created from ZFS pools.

Although ZFS normally works with device files for storage devices (e.g., /dev/sdb1, /dev/sdc1, /dev/sdd1), ZFS can even use empty files on an existing filesystem, which is a simple way to explore ZFS configuration if you don’t have a plethora of additional disks available.

The following commands create four empty 128MB files (/disk1, /disk2, /disk3 and /disk4) that we’ll treat as four separate disks:

dd if=/dev/zero of=/disk1 bs=1024k count=128

dd if=/dev/zero of=/disk2 bs=1024k count=128

dd if=/dev/zero of=/disk3 bs=1024k count=128

dd if=/dev/zero of=/disk4 bs=1024k count=128

 

Next, you can use the following commands to create a simple ZFS volume called zvol1 from the space on /disk1, work with the new volume and remove it afterward. Once a new ZFS volume is created using the zpool command, it is automatically mounted to a directory of the same name under the / directory:

zpool create zvol1 /disk1

zpool list

cp /etc/hosts /zvol1

ls -l /zvol1

zpool destroy zvol1

 

You can also create mirrored ZFS volumes, which are the equivalent of RAID 1 but resizable under ZFS. To create and work with a mirrored ZFS volume called zvol2 from the space on /disk1 and /disk2, you can use the following commands:

zpool create zvol2 mirror /disk1 /disk2

zpool list

cp /etc/hosts /zvol2

zpool status zvol2

 

Next, you can overwrite a portion of /disk1 (simulating disk corruption), update the status of ZFS (called scrubbing), detach the bad disk (/disk1), and mirror the data on /disk2 to another disk (/disk3) using the following commands. The final command will remove the mirror.

dd if=/dev/random of=/disk1 bs=512 count=1

zpool scrub zvol2

zpool status zvol2

zpool detach zvol2 /disk1

zpool status zvol2

zpool attach zvol2 /disk2 /disk3

zpool list

zpool status zvol2

zpool iostat -v zvol2

zpool destroy zvol2

 

In addition to simple volumes and mirrored volumes, you can create a RAID-Z volume (the equivalent of a RAID-5 volume with a variable-sized stripe for faster performance). The following commands will create a RAID-Z volume called zvol3 using /disk2, /disk3 and /disk4 and view the results:

zpool create zvol3 raidz /disk2 /disk3 /disk4

zpool status zvol3

zpool iostat -v zvol3

 

A RAID-Z needs at least three disks to protect against single-disk failure, and at least seven disks to protect against multi-disk failure. You can also use raidz2 (double parity like RAID-6) and raidz3 (triple parity) in place of RAID-Z in the zpool command shown earlier. You need at least four devices for raidz2 and at least five for raidz3.

Filesystems and subfilesystems are managed with the zfs command, which allows you to set a wide variety of ZFS-specific functionality including directory size quotas, file- and directory-specific features, and performance options. The following commands will create three subdirectories under /zvol3 that are labelled as ZFS subfilesystems using the zfs command. The final two commands shown below examine those properties and set a storage limit of 10GB for the larry subfilesystem.

mkdir /zvol3/larry

mkdir /zvol3/curly

mkdir /zvol3/moe

zfs list

zfs create zvol3/larry

zfs create zvol3/curly

zfs create zvol3/moe

zfs list

ls /zvol3

zfs get all zvol3/larry

zfs set quota=10G zvol3/larry


Are you ready to take your Linux knowledge to the next level? Check out CompTIA Linux+ to prove your skills to employers.

Email us at blogeditor@comptia.org for inquiries related to contributed articles, link building and other web content needs.

Read More from the CompTIA Blog

Leave a Comment