How to Setup ZFS Filesystem on Linux with zpool Command Examples

Messing around with FreeBSD 10 lately I loved ZFS, its simplicity and expand-ability. So I thought, what about a Linux with ZFS ? I’ll write about How to Setup ZFS Filesystem on Linux with zpool Command Examples in here.


ZFS has combined volume manager and filesystem with several advanced features.

This is the first part in a series of articles on ZFS.

In the article, we’ll provide an high level introduction to ZFS, explain how to install ZFS on linux, create a ZFS pool, and several ZFS zpool commands.

1. Introduction to ZFS

The following are some of the features of ZFS filesystem:

  • Protection against data corruption
  • Support for high storage capacities
  • Efficient data compression
  • Take Snapshots of filesystem
  • Copy-on-write clones
  • RAID Z Support
  • Integrity checking
  • Automatic repair and support for native NFSV4 ACL

This was developed originally by Sun Microsystems for the Solaris platform. In 2010, Oracle acquired Sun microsystems and has made lot of improvements on ZFS filesystem.

ZFS is recently becoming popular on Linux as it has become more stable.

The ZFS on Linux port is produced by the Lawrence Livermore National Laboratory (LLNL).


ZFS on Linux is a kernel module that you can download, compile and install. You do not have to patch or recompile your kernel.

You can download the source packages for your respective OS distribution from here.

2. Install ZFS on Linux

In this article, we’ll be installing ZFS on CentOS server. But, the zfs commands mentioned below are same for almost all the distributions on Linux distros except the installation part.

Execute the following yum commands to install ZFS on Redhat / CentOS.

Please ensure all the dependencies are met. One of the dependencies where the installation normally fails, would be a requirement to install GCC compiler. In this case, please install the GCC compiler before installing ZFS.


If you are not sure which packages you need you may also install the whole group “Development Tools” using yum groupinstall “Development Tools”


Ensure that the ZFS modules are loaded us lsmod command as shown below:

We have added few disks on this server (/dev/sdb through /dev/sdf) to test the ZFS functionality.

3. Create a zpool

Zpool command used to configure the storage pools in ZFS. Storage pool is a collection of devices that provides physical storage and data replication for zfs datasets.

The following creates a zpool.

In the above example:

  • create stands for creating a new pool.
  • The -f option is to ignore disk partition labels since these are new disks
  • raidz is raid level. RAIDZ is nothing but the variation of RAID-5 that allows for better distribute on of parity and eliminates the “RAID-5” write hole (data and parity inconsistency after a power loss).
  • A raidz group can have single, double or tribe parity meaning it can sustain one, two, or three failures respectively without losing any data. Data and parity is striped across all disks within a raidz group.

Next, verify the status of the zpool that we just created.

Once the pool is created, if you do df –h, you will see the newly created pool is mounted automatically on the mountpount.

4. Create a Mirrored Pool

To create a mirrored pool, uze the zpool create command with the following options.

If any of the disk in the particular mirror group is failed, then the other disk still holds the data. As soon as the failed disk is replaced the contents are mirrored back(also known as resilvering) to the newly replaced disk.

Next, verify the status of the mirrored zpool that we just created:

5. Zpool Import and Export

There are some cases when you may need to migrate a zfs pools between systems.

ZFS makes this possible by exporting a pool from one system and importing it to another system.

To export any pool, use the zpool export command and zpool import command is used to import the pool as shown in the following example:

6. View I/O stats of the ZFS Pool

To view the zpool I/O statistics, use the zpool iostat command as shown below:

7. Delete a ZFS pool

To destroy a pool, use the zpool destroy command as shown below:

8. Replace Corrupted disk in ZFS pool

To replace a disk, after a failure or corruption, use the following command:

9. Expand ZFS Pool with new Disk

To expand the zpool by adding a new disk use the zpool command as given below:

10. Add a Spare Disk to ZFS Pool

You can also add a spare disk to the zfs pool using the below command, by adding a spare device to a zfs pool.

The failed disks is automatically replaced by the spare device and administrator can replace the failed disks at later time.

Please note that you can also share the spare device among multiple ZFS pools.


11. Check your pool for errors

Checking ZFS File System Integrity

No fsck utility equivalent exists for ZFS. This utility has traditionally served two purposes, those of file system repair and file system validation.

File System Repair

With traditional file systems, the way in which data is written is inherently vulnerable to unexpected failure causing file system inconsistencies. Because a traditional file system is not transactional, unreferenced blocks, bad link counts, or other inconsistent file system structures are possible. The addition of journaling does solve some of these problems, but can introduce additional problems when the log cannot be rolled back. The only way for inconsistent data to exist on disk in a ZFS configuration is through hardware failure (in which case the pool should have been redundant) or when a bug exists in the ZFS software.

File System Validation

In addition to performing file system repair, the fsck utility validates that the data on disk has no problems. Traditionally, this task requires unmounting the file system and running the fsck utility, possibly taking the system to single-user mode in the process. This scenario results in downtime that is proportional to the size of the file system being checked. Instead of requiring an explicit utility to perform the necessary checking, ZFS provides a mechanism to perform routine checking of all inconsistencies. This feature, known as scrubbing, is commonly used in memory and other systems as a method of detecting and preventing errors before they result in a hardware or software failure.

Controlling ZFS Data Scrubbing

Whenever ZFS encounters an error, either through scrubbing or when accessing a file on demand, the error is logged internally so that you can obtain quick overview of all known errors within the pool.

Explicit ZFS Data Scrubbing

The simplest way to check data integrity is to initiate an explicit scrubbing of all data within the pool. This operation traverses all the data in the pool once and verifies that all blocks can be read. Scrubbing proceeds as fast as the devices allow, though the priority of any I/O remains below that of normal operations. This operation might negatively impact performance, though the pool’s data should remain usable and nearly as responsive while the scrubbing occurs. To initiate an explicit scrub, use the zpool scrub command.

The status of the current scrubbing operation can be displayed by using the zpool status command. For example:

Only one active scrubbing operation per pool can occur at one time.

You can stop a scrubbing operation that is in progress by using the -s option. For example:

In most cases, a scrubing operation to ensure data integrity should continue to completion. Stop a scrubbing operation at your own discretion if system performance is impacted by the operation.

Performing routine scrubbing guarantees continuous I/O to all disks on the system. Routine scrubbing has the side effect of preventing power management from placing idle disks in low-power mode. If the system is generally performing I/O all the time, or if power consumption is not a concern, then this issue can safely be ignored.