Search
Close this search box.

Cheat sheet: Install ZFS file system on Ubuntu 14.04

This file system is perfect to be used in a NAS.
You can check Why ZFS over EXT4 or other FS at the bottom of this article.

Install ZFS

Before we can start using ZFS, we need to install it. Simply add the repository to apt-get with the following command:

apt-add-repository --yes ppa:zfs-native/stable
 apt-get update
apt-get install ubuntu-zfs

You should get something like this:

~/root# apt-get install ubuntu-zfs
Reading package lists... Done
Building dependency tree 
Reading state information... Done
The following extra packages will be installed:
build-essential dkms dpkg-dev fakeroot g++ g++-4.8 libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libfakeroot libnvpair1
libstdc++-4.8-dev libuutil1 libzfs2 libzpool2 mountall spl spl-dkms zfs-dkms
zfs-doc zfsutils
Suggested packages:
debhelper debian-keyring g++-multilib g++-4.8-multilib gcc-4.8-doc
libstdc++6-4.8-dbg libstdc++-4.8-doc zfs-auto-snapshot nfs-kernel-server
zfs-initramfs
The following NEW packages will be installed:
build-essential dkms dpkg-dev fakeroot g++ g++-4.8 libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libfakeroot libnvpair1
libstdc++-4.8-dev libuutil1 libzfs2 libzpool2 spl spl-dkms ubuntu-zfs
zfs-dkms zfs-doc zfsutils
The following packages will be upgraded:
mountall
1 upgraded, 21 newly installed, 0 to remove and 0 not upgraded.
Need to get 11.3 MB of archives.
After this operation, 46.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main mountall amd64 2.53-zfs1 [69.9 kB]
Get:2 http://fr.archive.ubuntu.com/ubuntu/ trusty/main libstdc++-4.8-dev amd64 4.8.2-19ubuntu1 [1050 kB]
Get:3 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main dkms all 2.2.0.3-1.1ubuntu5.14.04+zfs9~trusty [72.0 kB]
Get:4 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main spl-dkms all 0.6.3-3~trusty [390 kB]
Get:5 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main zfs-doc amd64 0.6.3-5~trusty [60.2 kB]
Get:6 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main zfs-dkms amd64 0.6.3-5~trusty [988 kB]
Get:7 http://fr.archive.ubuntu.com/ubuntu/ trusty/main g++-4.8 amd64 4.8.2-19ubuntu1 [7038 kB]
Get:8 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main spl amd64 0.6.3-3~trusty [16.3 kB]
Get:9 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main libuutil1 amd64 0.6.3-5~trusty [27.3 kB]
Get:10 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main libnvpair1 amd64 0.6.3-5~trusty [22.9 kB]
Get:11 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main libzpool2 amd64 0.6.3-5~trusty [355 kB]
Get:12 http://fr.archive.ubuntu.com/ubuntu/ trusty/main g++ amd64 4:4.8.2-1ubuntu6 [1490 B]
Get:13 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main libzfs2 amd64 0.6.3-5~trusty [101 kB]
Get:14 http://fr.archive.ubuntu.com/ubuntu/ trusty-updates/main dpkg-dev all 1.17.5ubuntu5.3 [726 kB]
Get:15 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main zfsutils amd64 0.6.3-5~trusty [254 kB]
Get:16 http://ppa.launchpad.net/zfs-native/stable/ubuntu/ trusty/main ubuntu-zfs amd64 8~trusty [1752 B]
Get:17 http://fr.archive.ubuntu.com/ubuntu/ trusty/main build-essential amd64 11.6ubuntu6 [4838 B]
Get:18 http://fr.archive.ubuntu.com/ubuntu/ trusty/main libfakeroot amd64 1.20-3ubuntu2 [25.4 kB]
Get:19 http://fr.archive.ubuntu.com/ubuntu/ trusty/main fakeroot amd64 1.20-3ubuntu2 [55.0 kB]
Get:20 http://fr.archive.ubuntu.com/ubuntu/ trusty/main libalgorithm-diff-perl all 1.19.02-3 [50.0 kB]
Get:21 http://fr.archive.ubuntu.com/ubuntu/ trusty/main libalgorithm-diff-xs-perl amd64 0.04-2build4 [12.6 kB]
Get:22 http://fr.archive.ubuntu.com/ubuntu/ trusty/main libalgorithm-merge-perl all 0.08-2 [12.7 kB]
Fetched 11.3 MB in 4s (2465 kB/s) 
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_TIME = "fr_FR.UTF-8",
LC_MONETARY = "fr_FR.UTF-8",
LC_CTYPE = "UTF-8",
LC_ADDRESS = "fr_FR.UTF-8",
LC_TELEPHONE = "fr_FR.UTF-8",
LC_NAME = "fr_FR.UTF-8",
LC_MEASUREMENT = "fr_FR.UTF-8",
LC_IDENTIFICATION = "fr_FR.UTF-8",
LC_NUMERIC = "fr_FR.UTF-8",
LC_PAPER = "fr_FR.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
(Reading database ... 197538 files and directories currently installed.)
Preparing to unpack .../mountall_2.53-zfs1_amd64.deb ...
Unpacking mountall (2.53-zfs1) over (2.53) ...
Selecting previously unselected package libstdc++-4.8-dev:amd64.
Preparing to unpack .../libstdc++-4.8-dev_4.8.2-19ubuntu1_amd64.deb ...
Unpacking libstdc++-4.8-dev:amd64 (4.8.2-19ubuntu1) ...
Selecting previously unselected package g++-4.8.
Preparing to unpack .../g++-4.8_4.8.2-19ubuntu1_amd64.deb ...
Unpacking g++-4.8 (4.8.2-19ubuntu1) ...
Selecting previously unselected package g++.
Preparing to unpack .../g++_4%3a4.8.2-1ubuntu6_amd64.deb ...
Unpacking g++ (4:4.8.2-1ubuntu6) ...
Selecting previously unselected package dpkg-dev.
Preparing to unpack .../dpkg-dev_1.17.5ubuntu5.3_all.deb ...
Unpacking dpkg-dev (1.17.5ubuntu5.3) ...
Selecting previously unselected package build-essential.
Preparing to unpack .../build-essential_11.6ubuntu6_amd64.deb ...
Unpacking build-essential (11.6ubuntu6) ...
Selecting previously unselected package dkms.
Preparing to unpack .../dkms_2.2.0.3-1.1ubuntu5.14.04+zfs9~trusty_all.deb ...
Unpacking dkms (2.2.0.3-1.1ubuntu5.14.04+zfs9~trusty) ...
Selecting previously unselected package spl-dkms.
Preparing to unpack .../spl-dkms_0.6.3-3~trusty_all.deb ...
Unpacking spl-dkms (0.6.3-3~trusty) ...
Selecting previously unselected package zfs-doc.
Preparing to unpack .../zfs-doc_0.6.3-5~trusty_amd64.deb ...
Unpacking zfs-doc (0.6.3-5~trusty) ...
Processing triggers for ureadahead (0.100.0-16) ...
ureadahead will be reprofiled on next reboot
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up dkms (2.2.0.3-1.1ubuntu5.14.04+zfs9~trusty) ...
Setting up spl-dkms (0.6.3-3~trusty) ...
Loading new spl-0.6.3 DKMS files...
First Installation: checking all kernels...
Building only for 3.13.0-43-generic
Building initial module for 3.13.0-43-generic
Done.

spl:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

splat.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

Running the post_install script:

depmod.......

DKMS: install completed.
Selecting previously unselected package zfs-dkms.
(Reading database ... 198956 files and directories currently installed.)
Preparing to unpack .../zfs-dkms_0.6.3-5~trusty_amd64.deb ...
Unpacking zfs-dkms (0.6.3-5~trusty) ...
Selecting previously unselected package libfakeroot:amd64.
Preparing to unpack .../libfakeroot_1.20-3ubuntu2_amd64.deb ...
Unpacking libfakeroot:amd64 (1.20-3ubuntu2) ...
Selecting previously unselected package fakeroot.
Preparing to unpack .../fakeroot_1.20-3ubuntu2_amd64.deb ...
Unpacking fakeroot (1.20-3ubuntu2) ...
Selecting previously unselected package libalgorithm-diff-perl.
Preparing to unpack .../libalgorithm-diff-perl_1.19.02-3_all.deb ...
Unpacking libalgorithm-diff-perl (1.19.02-3) ...
Selecting previously unselected package libalgorithm-diff-xs-perl.
Preparing to unpack .../libalgorithm-diff-xs-perl_0.04-2build4_amd64.deb ...
Unpacking libalgorithm-diff-xs-perl (0.04-2build4) ...
Selecting previously unselected package libalgorithm-merge-perl.
Preparing to unpack .../libalgorithm-merge-perl_0.08-2_all.deb ...
Unpacking libalgorithm-merge-perl (0.08-2) ...
Selecting previously unselected package spl.
Preparing to unpack .../spl_0.6.3-3~trusty_amd64.deb ...
Unpacking spl (0.6.3-3~trusty) ...
Selecting previously unselected package libuutil1.
Preparing to unpack .../libuutil1_0.6.3-5~trusty_amd64.deb ...
Unpacking libuutil1 (0.6.3-5~trusty) ...
Selecting previously unselected package libnvpair1.
Preparing to unpack .../libnvpair1_0.6.3-5~trusty_amd64.deb ...
Unpacking libnvpair1 (0.6.3-5~trusty) ...
Selecting previously unselected package libzpool2.
Preparing to unpack .../libzpool2_0.6.3-5~trusty_amd64.deb ...
Unpacking libzpool2 (0.6.3-5~trusty) ...
Selecting previously unselected package libzfs2.
Preparing to unpack .../libzfs2_0.6.3-5~trusty_amd64.deb ...
Unpacking libzfs2 (0.6.3-5~trusty) ...
Selecting previously unselected package zfsutils.
Preparing to unpack .../zfsutils_0.6.3-5~trusty_amd64.deb ...
Unpacking zfsutils (0.6.3-5~trusty) ...
Selecting previously unselected package ubuntu-zfs.
Preparing to unpack .../ubuntu-zfs_8~trusty_amd64.deb ...
Unpacking ubuntu-zfs (8~trusty) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for initramfs-tools (0.103ubuntu4.2) ...
update-initramfs: Generating /boot/initrd.img-3.13.0-43-generic
Processing triggers for ureadahead (0.100.0-16) ...
Setting up mountall (2.53-zfs1) ...
Setting up libstdc++-4.8-dev:amd64 (4.8.2-19ubuntu1) ...
Setting up g++-4.8 (4.8.2-19ubuntu1) ...
Setting up g++ (4:4.8.2-1ubuntu6) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up dpkg-dev (1.17.5ubuntu5.3) ...
Setting up build-essential (11.6ubuntu6) ...
Setting up zfs-doc (0.6.3-5~trusty) ...
Setting up zfs-dkms (0.6.3-5~trusty) ...
Loading new zfs-0.6.3 DKMS files...
First Installation: checking all kernels...
Building only for 3.13.0-43-generic
Building initial module for 3.13.0-43-generic
Done.

zavl:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

zcommon.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

znvpair.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

zpios.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

zunicode.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

zfs.ko:
Running module version sanity check.
- Original module
- No original module exists within this kernel
- Installation
- Installing to /lib/modules/3.13.0-43-generic/updates/dkms/

depmod....

DKMS: install completed.
Setting up libfakeroot:amd64 (1.20-3ubuntu2) ...
Setting up fakeroot (1.20-3ubuntu2) ...
update-alternatives: using /usr/bin/fakeroot-sysv to provide /usr/bin/fakeroot (fakeroot) in auto mode
Setting up libalgorithm-diff-perl (1.19.02-3) ...
Setting up libalgorithm-diff-xs-perl (0.04-2build4) ...
Setting up libalgorithm-merge-perl (0.08-2) ...
Setting up spl (0.6.3-3~trusty) ...
Setting up libuutil1 (0.6.3-5~trusty) ...
Setting up libnvpair1 (0.6.3-5~trusty) ...
Setting up libzpool2 (0.6.3-5~trusty) ...
Setting up libzfs2 (0.6.3-5~trusty) ...
Setting up zfsutils (0.6.3-5~trusty) ...
Processing triggers for initramfs-tools (0.103ubuntu4.2) ...
update-initramfs: Generating /boot/initrd.img-3.13.0-43-generic
Processing triggers for ureadahead (0.100.0-16) ...
Setting up ubuntu-zfs (8~trusty) ...
Processing triggers for libc-bin (2.19-0ubuntu6.4) ...

Reboot.

Now, let’s see if it has been correctly compiled and loaded by the kernel

dmesg | grep ZFS

You get an output like this:

# dmesg | grep ZFS
[ 5.979569] ZFS: Loaded module v0.6.3-5~trusty, ZFS pool version 5000, ZFS filesystem version 5

Creation of a RAID-Z2 disk array using 4 disks

We will use the zpool create command passing in the disks to use for the array as arguments. By specifying the argument -f it removes the need to create partitions on the disks prior to creating the array.

zpool create -f datastore1 raidz2  /dev/sdf /dev/sdg /dev/sdh /dev/sdi

We check if the zpool is created and ok with issuing this command:

# zpool status datastore1
pool: datastore1
state: ONLINE
scan: none requested
config:

NAME STATE READ WRITE CKSUM
datastore1 ONLINE 0 0 0
raidz2-0 ONLINE 0 0 0
sdf ONLINE 0 0 0
sdg ONLINE 0 0 0
sdh ONLINE 0 0 0
sdi ONLINE 0 0 0

errors: No known data errors

Create ZFS dataset

Creating a dataset is not mandatory. You may use the pool directly. A dataset is like a folder on the volume, but it acts like a filesystem in that it supports snapshots, quotas, compression, NFS or SMB sharing. It’s great to have different mounting points for different usages.

The command to use to create a dataset is:

zfs create -o mountpoint=<MOUNT POINT> <ZPOOL NAME>/<DATASET NAME>

Here I do:

zfs create -o mountpoint=/mnt/movies datastore1/movies

Let’s see what we have up to now

# zfs list
NAME USED AVAIL REFER MOUNTPOINT
datastore1 214K 1.78T 43.3K /datastore1
datastore1/dataset1 43.3K 1.78T 43.3K /mnt/dataset1
#

Add compression

You can add compression on dataset or an entire pool. Adding it to the pool will make all the datasets of the pool to get compression by default. You can decide to not set compression for a specific dataset of the pool though.
As you can see here, compression of the pool datastore1 is not set:

# zfs get compression datastore1
NAME PROPERTY VALUE SOURCE
datastore1 compression off default
/#

Let’s add it:

zfs set compression=lz4 datastore1

After that we should get:

# zfs get compression datastore1
NAME PROPERTY VALUE SOURCE
datastore1 compression lz4 local
#

If you want to add compression to the dataset movies:

zfs set compression=lz4 datastore1/movies

Delete a dataset

zfs destroy datastore1/dataset1

Delete a pool

zpool destroy datastore1

Why ZFS ?

1. Checksums in Metadata for Data Integrity
This can detect phantom writes, misdirected reads and writes, DMA parity errors, driver bugs and accidental overwrites as well as traditional “bit rot.”

2. Copy on Write
When data is changed it is not overwritten. It is always written to a new block and checksummed before pointers to the data are changed. The old data may be retained, creating snapshots of the file system through time as changes are made.

3. Data Snapshots
ZFS can be configured to take a snapshot of the file system (or a section of it, such as just a user’s home folder) on a regular basis — every 15 minutes, or every hour, and so on. These snapshots are very small and efficient, as only the deltas from the previous snapshot are stored. Snapshots can also be made writable to create clones of existing file systems.

4. Pooled Data Storage
ZFS takes available storage drives and pools them together as a single resource, called a zpool. This can be optimised for capacity, or I/O performance, or redundancy, using striping, mirroring or some form of RAID. If more storage is needed, then more drives can simply be added to the zpool.

5. RAIDZ and RAIDZ2
RAIDZ (equivalent to RAID5) and RAIDZ2 (equivalent to RAID6).
RAID 5 has a well-known flaw called the RAID 5 write hole. This causes a problem when a data block is written to a stripe but a power failure occurs before the corresponding parity block can be written. As a result, the data and parity for the stripe will be inconsistent. If a disk then fails, the RAID reconstruction process will result in incorrect data. The only way out of this is if an entire stripe happens to be overwritten, thus generating a correct parity block.

RAIDZ gets around this problem by using a variable width stripe, so every write is effectively a full stripe write. This, together with ZFS’s copy on write characteristic, eliminates the RAID 5 write hole completely. RAIDZ2 works in a similar way, but can tolerate the loss of two disks in the array using double parity.

6. SSD Hybrid Storage Pools
High performance SSDs can be added to a storage pool to create a hybrid storage pool.

7. Capacity
ZFS is a 128-bit file system, which means that in theory it could store 256 quadrillion ZB (a ZB is a billion TB.)

8. Data Scrubbing
ZFS can be made to scrub all the data in a storage pool, checking each piece of data with its corresponding checksum to verify its integrity, detect any silent data corruption, and to correct any errors in encounters where possible.

9. Simple, Efficient Administration
Using ZFS commands, you can administer a system with short, efficient commands.

Share the Post:

Related Posts