Notes on ZFS on Linux

Russell Bateman
September 2018
last update:

ZFS is a combination filesystem and logical volume manager invented at Sun Microsystems. It's scalable and desinged to prevent data corruption. I make use of the feature of copy-on-write cloning in a very simple way: I always buy two identical disks (in size, but I also insist on buying the same model from the same manufacturer) and mirror them.

Generically, ZFS for Linux comes from a GitHub project of the specific version you want. The latest one as of this writing is v0.7.11. Start here: ZFS on Linux.

However, since I'm running on Ubuntu Server and since Canonical supports ZFS more or less directly, I'm getting it from Ubuntu. Here are the directions I'm following:

# apt-add-repository main*
# apt-add-repository universe*
# apt-add-repository restricted
'restricted' distribution component enabled for all sources.
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://archive.ubuntu.com/ubuntu bionic-security InRelease [83.2 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [9,184 B]
Get:5 http://archive.ubuntu.com/ubuntu bionic/restricted Translation-en [3,584 B]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [388 kB]
Get:7 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [538 kB]
Fetched 1,110 kB in 2s (468 kB/s)
Reading package lists... Done
# apt-add-repository multiverse
'multiverse' distribution component enabled for all sources.
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic-security InRelease
Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Get:4 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [151 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic/multiverse Translation-en [108 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [1,444 B]
Get:7 http://archive.ubuntu.com/ubuntu bionic-security/multiverse Translation-en [996 B]
Get:8 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [4,180 B]
Get:9 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse Translation-en [2,740 B]
Fetched 268 kB in 2s (125 kB/s)
Reading package lists... Done
# cat sources.list
deb http://archive.ubuntu.com/ubuntu bionic main universe restricted multiverse
deb http://archive.ubuntu.com/ubuntu bionic-security main universe restricted multiverse
deb http://archive.ubuntu.com/ubuntu bionic-updates main universe restricted multiverse

* I already had these defined.

Next, update the available versions of packages in the various respositories, then proceed to installation of the ZFS filesystem:

# apt-get update
# apt-get install zfsutils-linux
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-zed
Suggested packages:
  nfs-kernel-server samba-common-bin zfs-initramfs | zfs-dracut
The following NEW packages will be installed:
  libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-zed zfsutils-linux
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,167 kB of archives.
After this operation, 4,259 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libnvpair1linux amd64 0.7.5-1ubuntu16.3 [45.3 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libuutil1linux amd64 0.7.5-1ubuntu16.3 [48.0 kB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libzpool2linux amd64 0.7.5-1ubuntu16.3 [547 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libzfs2linux amd64 0.7.5-1ubuntu16.3 [128 kB]
Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 zfsutils-linux amd64 0.7.5-1ubuntu16.3 [341 kB]
Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 zfs-zed amd64 0.7.5-1ubuntu16.3 [57.7 kB]
Fetched 1,167 kB in 2s (488 kB/s)
Selecting previously unselected package libnvpair1linux.
(Reading database ... 106086 files and directories currently installed.)
Preparing to unpack .../0-libnvpair1linux_0.7.5-1ubuntu16.3_amd64.deb ...
Unpacking libnvpair1linux (0.7.5-1ubuntu16.3) ...
Selecting previously unselected package libuutil1linux.
Preparing to unpack .../1-libuutil1linux_0.7.5-1ubuntu16.3_amd64.deb ...
Unpacking libuutil1linux (0.7.5-1ubuntu16.3) ...
Selecting previously unselected package libzpool2linux.
Preparing to unpack .../2-libzpool2linux_0.7.5-1ubuntu16.3_amd64.deb ...
Unpacking libzpool2linux (0.7.5-1ubuntu16.3) ...
Selecting previously unselected package libzfs2linux.
Preparing to unpack .../3-libzfs2linux_0.7.5-1ubuntu16.3_amd64.deb ...
Unpacking libzfs2linux (0.7.5-1ubuntu16.3) ...
Selecting previously unselected package zfsutils-linux.
Preparing to unpack .../4-zfsutils-linux_0.7.5-1ubuntu16.3_amd64.deb ...
Unpacking zfsutils-linux (0.7.5-1ubuntu16.3) ...
Selecting previously unselected package zfs-zed.
Preparing to unpack .../5-zfs-zed_0.7.5-1ubuntu16.3_amd64.deb ...
Unpacking zfs-zed (0.7.5-1ubuntu16.3) ...
Setting up libuutil1linux (0.7.5-1ubuntu16.3) ...
Setting up libnvpair1linux (0.7.5-1ubuntu16.3) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up libzpool2linux (0.7.5-1ubuntu16.3) ...
Setting up libzfs2linux (0.7.5-1ubuntu16.3) ...
Setting up zfsutils-linux (0.7.5-1ubuntu16.3) ...
Created symlink /etc/systemd/system/zfs-import.target.wants/zfs-import-cache.service → /lib/systemd/system/zfs-import-cache.service.
Created symlink /etc/systemd/system/zfs-mount.service.wants/zfs-import.target → /lib/systemd/system/zfs-import.target.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-import.target → /lib/systemd/system/zfs-import.target.
Created symlink /etc/systemd/system/zfs-mount.service.wants/zfs-load-module.service → /lib/systemd/system/zfs-load-module.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-load-module.service → /lib/systemd/system/zfs-load-module.service.
Created symlink /etc/systemd/system/zfs-share.service.wants/zfs-mount.service → /lib/systemd/system/zfs-mount.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-mount.service → /lib/systemd/system/zfs-mount.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-share.service → /lib/systemd/system/zfs-share.service.
Created symlink /etc/systemd/system/multi-user.target.wants/zfs.target → /lib/systemd/system/zfs.target.
zfs-import-scan.service is a disabled or a static unit, not starting it.
Setting up zfs-zed (0.7.5-1ubuntu16.3) ...
Created symlink /etc/systemd/system/zed.service → /lib/systemd/system/zfs-zed.service.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-zed.service → /lib/systemd/system/zfs-zed.service.
Processing triggers for libc-bin (2.27-3ubuntu1) ...

Next, let's see if there are any pools (there shouldn't be):

# zpool status
no pools available


Original layout of server tol-eressea

I'm making two pools, the larger for television episodes and the smaller for movies.

I choose the bigger volume for television series because they seem to take up more space quicker. So, still in brown for the smaller disk and, therefore, movies while in green for television shows.

[email protected]:/# zpool status
no pools available
[email protected]:/# zpool create movies mirror /dev/sda /dev/sdb
[email protected]:/# zpool create television mirror /dev/sdd /dev/sde
[email protected]:/# zpool status
  pool: movies
 state: ONLINE
  scan: none requested
config:

	NAME        STATE     READ WRITE CKSUM
	movies      ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    sda     ONLINE       0     0     0
	    sdb     ONLINE       0     0     0

errors: No known data errors

  pool: television
 state: ONLINE
  scan: none requested
config:

	NAME        STATE     READ WRITE CKSUM
	television  ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    sdd     ONLINE       0     0     0
	    sde     ONLINE       0     0     0

errors: No known data errors
[email protected]:/# zpool export movies
[email protected]:/# zpool import -d /dev/disk/by-id movies
[email protected]:/# zpool export television
[email protected]:/# zpool import -d /dev/disk/by-id television
[email protected]:/# zpool status
  pool: movies
 state: ONLINE
  scan: none requested
config:

	NAME                                          STATE     READ WRITE CKSUM
	movies                                        ONLINE       0     0     0
	  mirror-0                                    ONLINE       0     0     0
	    ata-WDC_WD20EARX-00PASB0_WD-WCAZAJ004702  ONLINE       0     0     0
	    ata-WDC_WD20EARX-00PASB0_WD-WCAZAJ069805  ONLINE       0     0     0

errors: No known data errors

  pool: television
 state: ONLINE
  scan: none requested
config:

	NAME                                 STATE     READ WRITE CKSUM
	television                           ONLINE       0     0     0
	  mirror-0                           ONLINE       0     0     0
	    ata-ST4000DM000-1F2168_S300MZ7G  ONLINE       0     0     0
	    ata-ST4000DM000-1F2168_S300ELBZ  ONLINE       0     0     0

errors: No known data errors
[email protected]:/# zfs set mountpoint=/plex-movies movies
[email protected]:/# zfs set mountpoint=/plex-television television
[email protected]:/# ll /plex-movies
total 13
drwxr-xr-x  2 root root    2 Jul 30 20:55 ./
drwxr-xr-x 25 root root 4096 Jul 30 20:57 ../
[email protected]:/# ll /plex-television
total 13
drwxr-xr-x  2 root root    2 Jul 30 20:55 ./
drwxr-xr-x 25 root root 4096 Jul 30 20:57 ../
[email protected]:/plex-movies# /home/russ/diskspace.sh
.
.
.
Filesystem on disk: /plex-movies (device: movies)
   Total disk size: 1.8Tb
        Used space: 256Kb (1%)
        Free space: 1.8Tb
Filesystem on disk: /plex-television (device: television)
   Total disk size: 3.6Tb
        Used space: 256Kb (1%)
        Free space: 3.6Tb