This tutorial will guide you on how to install Z File System (ZFS) on a Linux distribution. We will use Ubuntu Linux distribution since ZFS package in Ubuntu is maintained well to be compatible with it's Linux Kernel
If you are using an Cloud Instance like in Amazon Web Service you can use the default provided Ubuntu Amazon Machine Image (AMI) like Ubuntu 16.04, 18.04, and 20.04 when you are provisioning it
Don't forget to add some RAW disk like 2 or 3 disks, because in this tutorial it'll show you how to manage your disk as RAID using Z Pool on ZFS
Let's get started!
Before we do the installation make sure you can escalate your privileges on the system by typing the following command in your command line
sudo suAfter you gain the root access by escalating your privilege now you can easily run the installation or the configuration later on, but before it we must make sure that our Operating System (OS) in this case our Ubuntu Linux is already using it's latest packages. Type following command to upgrade our OS to the latest version
apt-get update
apt-get -y dist-upgradeWe are using a distribution upgrade here not a standard upgrade command, because we want to make sure that our OS also using it's latest minor build version
After the upgrade is complete don't forget to reboot the OS just to make sure that it's also using the latest Linux Kernel provided by the distribution
rebootAfter the reboot is completed don't forget to re-escalate your privilege, since in this tutorial we will keep to use the root user
Mostly Ubuntu packages name is following the Debian Linux Distribution which for the ZFS on Linux package name is zfsutils-linux that we will install with the following command
apt-get -y install zfsutils-linuxAfter installation is finished without any then we are ready to go, if you have some error please try to reboot your system, if it's still happening then i think you should search your error in the forum 😄
To make sure the ZFS run or works properly you can type following command
zpool list
zfs listIt should return no pool or no dataset since we are not doing anything with it except the installation process
On this step you should already have a working ZFS on top of Ubuntu Linux Distribution, because now we will try to manage our RAW disk to be completely using ZFS management with Z Pool and ZFS command
Don't forget to always make sure that you are using escalated privilege using by checking out your terminal user ID using the following command
id -uThe command should return user ID of 0 which is the root user ID
ZFS has it's own feature that also cover as a Volume Manager like Linux Volume Manager (LVM). In ZFS the volume manager is called Z Pool. Z Pool is act like volume manager or a disk pool, so before we can use our ZFS Dataset we neet to create Z Pool first
Before we create a Z Pool make sure that we already initialize our RAW disk, this step is optional. We can initialize the disk by using the following step
-
Check available disk
lsblk
In this tutorial we will use 3 disk that will showed from above command as /dev/sdb, /dev/sdc, and /dev/sdd block devices
-
Then we need to create a partition as we intialized the disk by using following command
fdisk /dev/sdb > n > p > (Enter) > (Enter) > w
Before we continue let me explain the above fdisk command and what it does. So
fdisk /dev/sdbcommand mean that we want to manipulate or modify the /dev/sdb block device, then we hitnto create a new partition on it and we want it as primary partition so we hitp, next we need to define the first and last sector of our new partition, because we want to use all of the disk so just hit(Enter)on the keyboard, the last one is we need to write our manipulation or modification to the disk by hitting thew. Repeat the above command for /dev/sdc and /dev/sdd block devices -
Recheck available disk
lsblk
Now we see there are new block devices /dev/sdb1, /dev/sdc1, and /dev/sdd1. That's our new partition on the disk and we will use it and give it to the Z Pool so ZFS will manage it later on
After initializing the disk or may be you can use your available empty partition then we can create a Z Pool, in this tutorial we will use RAID0 (Stripe Mode) configuration, you can define what type of RAID with your own. Following command will create a Z Pool with RAID0
zpool create -O compression=lz4 -o ashift=12 data /dev/sdb1 /dev/sdc1Let me explain the above command first. Basically to manipulate Z Pool we can use the zpool command, to create a new Z Pool we can use zpool create command with options -O compression=lz4 this mean we will activate LZ4 algorithm for compression to the pool and -o ashift=12 mean that we will have 2 factor 12 block sector or equal with 4096 block sectors in our ZFS dataset this will optimize our ZFS read and write performance
Section data is our pool or tank name and next is the pool RAID mode, there are some type of RAID mode that we can use like following
mirrorequal to RAID1 (Mirror Mode)raidzequal with RAID5raidz2equal with RAID6raidz3equal with RAID7- leave it blank or empty is equal to RAID0 (Stripe Mode)
The last option is followed by our intialized block devices /dev/sdb1 and /dev/sdc1. Then how if we want to create a RAID10 or mirror-stripe mode?
We can use following command to create it:
zpool create -O compression=lz4 -o ashift=12 data mirror /dev/sdb1 /dev/sdc1 <another_block_devices> mirror /dev/sdd1 /dev/sdf1 <another_block_devices>Now to see created Z Pool we can use the zpool command like following
zpool listTo see our Z Pool disk status in verbose mode we can use
zpool status -vFor more information about Z Pool command including how to destroy or handling an Z Pool errors, you can see the official documentation from Oracle here
As explained in the Introduction to ZFS, ZFS also handle partitioning in the form of what we call as ZFS Dataset. When we craete a Z Pool we got our big Dataset call the tank in this tutorial is will be data you can see the mount point of it by using following command
df -hTo create child dataset of data or like wanted to create another partition below our parent dataset we can use following command
zfs create data/dimasthe command will automaticaly create new dataset and mount it in /data/dimas and it's already usable for us to save our data
Another type of dataset is Z Volume which we can use it as another block devices and it's basically used when we want to make a thin-provision dataset. To create a thin-provision dataset we can use the following command
zfs create -s -V 10G data/kiddoThe above command will create a virtual volume as new block devices which usually can be found in /dev/zvol path. On this tutorial it will be located in /dev/zvol/data/kiddo where it's actually a link to a device block under /dev path (Hint when you use lsblk command you will see a block device with zd prefix and it's the Z Vol block device). The -s options tell the ZFS to create a thin-provision dataset which it'll create a Z Volume, then -V 10G will tell the ZFS to create a Z Vol with size of volume about 10 Gigabytes, and the last parameter is our dataset location and name
After this you can format your Z Vol Dataset using mkfs command and mount it automatically or manually somewhere using the mount command
As we know that a thin-provision disk will used it's virtual capacity as we declared in -V options when creating a ZFS dataset. When we running out-of-space in our Z Vol we can resized the block device by using the following step
-
Make sure your volume already umounted
unmount /data/kiddo
-
First we need to get the capacity of current volume
zfs get volsize data/kiddo
-
After we got the current size the we need to define the new size of the volume
zfs set volsize=20G data/kiddo -
Resize the file system above the volume you can user
resize2fsif you are using Ext file system orxfs_growfsif you are using XFS file system but don't forget to mount it first if you're using XFS -
Re-mount the volume to the location that we want using
mountcommand
Beside run out-of-space in ZFS Dataset / Z Volumes we can also run out-of-space in our Z Pool. Since the Z Pool is more a like a Volume Manager then we can add another RAW disk directly to the pool, but don't forget to initialize the disk first
In this tutorial we wanted to add an addtional disk to our Z Pool which is data. We already spare out the /dev/sdd1 for this, so to add the /dev/sdd1 to the pool you can use the following command
zpool add data /dev/sdd1More about adding the disk to Z Pool you can read the manual directly from Oracle here