×

ZFS commonly known as Z file system is mainly based on storage and redundancy. The concept of ZFS was developed with file servers in mind where high availability and data integrity are the most crucial factors. 

ZFS uses virtual storage pools commonly known as zpools to deal with the storage and management of large amounts of data.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Software Installation tasks on Ubuntu Linux System.

In this context, we shall look into how to install zfs on Ubuntu and its common uses in the technical environment.


How to install ZFS on Ubuntu ?

To perform this installation procedure, ensure that you are using a Sudo privileged non-root user account.

ZFS installation process is a straightforward one. You can use the command line terminal application to install the ZFS file system. 

Lunch the command line terminal tool and execute the following command:

$ sudo apt update
$ sudo apt install zfsutils-linux

During the installation, you may be prompted for the password, provide sudo password and continue.

Once running the above command, you will be asked for confirmation if you want to continue with installation or not. Press 'y' and enter. Now the software package will be installed on your system.

To verify the installation of ZFS on your system, use the following command.

$ zfs --version


ZFS Basic usage and commands

Once the ZFS is installed, now you can use hard drives with ZFS. When the new hard drives are inserted into your system, ZFS addresses them by their device name. 

For instance something similar as the lines of /dev/sda or similar. 

You can use fdisk command line utility to check available hard drives:

$ sudo fdisk -l


How to create and destroy zpools ?

ZFS works with the concept of pooling disks together. Various Raid levels can be used while creating pools. The first pool we will be creating is RAID 0 . RAID level 0 works by striping your data across a number of disks. 

When a file is written to or read from the storage pool all the disks will come in action to present the portion of data. This level of RAID provides you a speed boost for your read and write operation speed however it lacks data redundancy. 

Any critical issue on the disk or disk malfunction in the pool will cost complete loss of data.

Here, we have used two hard drives /dev/sdb and /dev/sdd for creating the pool named test-pool. 

You can have your own assumption on disk and pool name selection. 

Run the following command to create zpool:

$ sudo zpool create test-pool /dev/sdb /dev/sdd

If any error appears, you can run the command using -f option after the zpool create command which forces the command to be executed:

$ sudo zpool create -f test-pool /dev/sdb /dev/sdd

Once created, you can find out the mount point using the following command:

$ df -h

From the output, we will see that the pool is mounted at /test-pool . 

You can change the mount point for the pool, use the following syntax.

$ sudo zfs set mountpoint =<path> <pool_name>

Here, we used /var/www as the new mount point. 

You can have your own consideration for the mount point:

$ sudo zfs set mountpoint=/var/www test-pool

Verify the new point using the following command.

$ df -h

You can create the directories under the storage pool.

Here, we have created the directory named MySQL under the storage pool test-tool:

$ sudo zfs create test-pool/mysql

Run the following command to view all the ZFS storage pools on the system:

$ zpool list

To find the configuration and status of each device in the ZFS pool, use the following command:

$ zpool status

To troubleshoot ZFS storage pool in case of any issue, execute the following command which shows the zpool events. 

Replace pool_name with your ZFS storage pool:

$ sudo zpool events pool_name -v

If you want to add another hard disk in the ZFS storage pool, you can use the following command. In this example I have used a new hard disk /dev/sdc to add in the previously created ZFS storage pool test-pool. 

You can select your hard disk and zpool name accordingly:

$ sudo zpool add test-pool /dev/sdc

Once the disk is added verify the pool using the command:

$ zpool status

To destroy the ZFS storage pool, run the following command with your valid pool name:

$ sudo zpool destroy pool_name

For example,

$ sudo zpool destroy test-pool


How to use encryption with ZFS ?

After creating a ZFS storage pool, you can enable encryption on it with the following command. 

For this example, I have used a previously created ZFS pool named "test-pool" for encryption. 

You can select your ZFS pool accordingly:

$ sudo zfs create -o encryption=on -o keylocation=prompt -o keyformat=passphrase test-pool/encrypted

You will be asked to enter the passphrase twice. Enter your passphrase and continue.


A new directory will be created under the storage mount point and anything under this directory will be encrypted. 

Whenever the system is a reboot, you may need to manually mount the dataset. 

Remember to use the -l flag when mounting the encrypted dataset. 

You will be prompted for the passphrase, supply the passphrase you have used to encrypt the pool, and continue:

$ sudo zfs mount -l test-pool/encrypted
$ df -hT | grep zfs


How to take, roll back and destroy ZFS snapshots ?

1. Taking the snapshot

Creating the snapshot in ZFS is quite an easy and straightforward process. You can use the zfs snapshot command followed by the name of the snapshot as an argument to create a snapshot. 

In this example, I have used test-pool/mysql to create a snapshot. You can choose your pool name and data set accordingly:

$ sudo zfs snapshot test-pool/mysql@friday

Verify the snapshot taken using the following command:

$ zfs list -t snapshot


2. Renaming the snapshot

You can also rename the snapshot name using zfs rename command followed by snapshot name. In this example, snapshot named "test-tool/mysql@friday" is renamed to "test-pool/mysql@today".


3. Snapshot Rollback

Snapshot can be rolled back using command zfs rollback with snapshot name to revert all the changes made since a specific snapshot. 

In this example, the test-pool/mysql file system is rolled back to the sunday snapshot:

$ sudo zfs rollback test-pool/mysql@sunday

Once the rollback is completed, you can verify the files present in the directory.


[Need urgent assistance in fixing Linux related Software Installations? We can help you. ]


Conclusion

More Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on IbmiMedia.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com