How To Use The ZFS File System On Linux
The ZFS file system is incredibly popular. As a result, many in the enterprise swear by it and use it to house trillions of bytes of data. Despite its popularity, Linux users will not be able to enjoy it out of the box. Instead, those looking to check it out and use it as their primary storage file system will need to install it.
Installing ZFS is a little different than other file systems and, depending on what you use, may require a little know-how. If you’re new to this file system, it’s best to go the Ubuntu route. As of Ubuntu 16.04, Canonical makes it very easy to get going with ZFS. Better yet, Ubuntu is by far the safest implementation of ZFS on Linux, with its simple setup, and build process that has been known to be very reliable (while other Linux distributions have a high risk of breaking ZFS).
To install the ZFS file system, head over to our in-depth guide. Follow the instructions and learn how to get it working before continuing on with this tutorial.
Note: Though it is possible to use ZFS for a single hard drive, it’s not a good idea, and you’ll likely miss out on all of the features that make this file system great. The point of the file system is to create redundancies, by stretching data across multiple hard drives. Before continuing, ensure you have more than 1 hard drive for ZFS.
Set Up ZFS
The ZFS file system works by pooling many different hard drives together to create one large storage center. This sounds overly complex, and it is. However, the result is superior storage with way more space.
Creating a new ZFS file system is a little more complex than just opening the Gparted partition editor. Instead, you’ll need to interact with it at a command line level. In a terminal window, run the lsblk command. Running the “list block” command will print out all of the storage drives on your Linux PC.
Go through and decide which hard drives to use for your Z-pool, and remember the names. In this tutorial, our three drives in the ZFS pool are /dev/sdb, /dev/sdc, and /dev/sdd.
Next, you’ll need to completely zero out the hard drives selected for the Z-pool, so that they no longer have any data on it. Using the dd command, overwrite each of the drives. This will take a while.
Note: change /dev/sdX with the drive id found with the lsblk command (sdb, etc.)
sudo dd if=/dev/zero of=/dev/sdX bs=8M
When dd finishes up, run the fdisk command. Running fdisk will show a lot of information about hard drives, including the file system information for each. Look through the readout and make sure none of the drives you’ve erased have a file system. This step is critical, as ZFS doesn’t use the traditional partitioning layout.
sudo fdisk -l
If the fdisk readout looks good, it’s safe to create a new ZFS Z-pool. For a basic Z-pool setup, do the following:
sudo zpool create -f newzpool /dev/sdb dev/sdc /dev/sdd
A basic setup will get most users through their storage needs. However, those that value their data and need to protect it shouldn’t go with such a basic setup. Instead, consider creating a ZFS pool with RaidZ.
Using RaidZ in combination with your ZFS pool will ensure your data is redundant, with many backups. To create a ZFS pool with RaidZ, run:
sudo zpool create -f newzpool raidz /dev/sdb dev/sdc /dev/sdd
To add files to your new ZFS storage pool, open up the file manager and go to the root of the file system. Place files inside of the folder you named your ZFS Zpool.
Add Disks To ZFS Zpool
ZFS is meant to hold a lot of data, but that doesn’t mean your original drives won’t fill up. There will come a time when more storage space is needed. Luckily, since ZFS doesn’t use partitions, adding more storage to a system is simple.
In this example, we’ll add two more drives to the Zpool (/dev/sde and /dev/sdf).
Note: if your ZFS setup doesn’t use RaidZ, remove it from the command.
sudo zpool add -f newzpool raidz /dev/sde /dev/sdf
Delete A ZFS Pool
Often times, ZFS volumes become broken and unusable. When this happens, you may need to delete the storage pool. To delete a storage pool, open up a terminal and use the zfs destroy command.
sudo zpool destroy newzpool
Running zpool destroy takes quite a long time, depending on how much data is on your storage pool. You’ll know the Zpool is completely destroyed when the terminal is usable again.
Check ZFS Status
A quick way to check the status of your Zpool is with the zpool status command. With it, users can see a basic readout of the ZFS volume, how it’s doing and if there are any errors. To check status, run the following command:
zpool status