Debian: How to install, configure and manage ZFS

root's picture

Before starting, I have to mention this tutorial is not about ZFS Fuse which comes by default with Debian. This is the real deal, the native ZFS for Linux, without fuse support. In theory should be faster and more reliable and according to my tests so far, it is amazing!

First of all, install ZFS:

wget http://archive.zfsonlinux.org/debian/pool/main/z/zfsonlinux/zfsonlinux_6_all.deb
dpkg -i zfsonlinux_6_all.deb
aptitude update
aptitude install debian-zfs

Example (the example below is from previously wheezy installation but the main package has been replaced to zfsonlinux_6_all.deb above):
root@eave:~# wget http://archive.zfsonlinux.org/debian/pool/main/z/zfsonlinux/zfsonlinux_3~wheezy_all.deb
--2014-12-01 22:35:38--  http://archive.zfsonlinux.org/debian/pool/main/z/zfsonlinux/zfsonlinux_3~wheezy_all.deb
Resolving archive.zfsonlinux.org (archive.zfsonlinux.org)... 54.231.33.81
Connecting to archive.zfsonlinux.org (archive.zfsonlinux.org)|54.231.33.81|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2038712 (1.9M) [application/x-debian-package]
Saving to: `zfsonlinux_3~wheezy_all.deb'

100%[=========================================================>] 2,038,712   1012K/s   in 2.0s    

2014-12-01 22:35:41 (1012 KB/s) - `zfsonlinux_3~wheezy_all.deb' saved [2038712/2038712]

root@eave:~# dpkg -i zfsonlinux_3~wheezy_all.deb 
Selecting previously unselected package zfsonlinux.
(Reading database ... 41395 files and directories currently installed.)
Unpacking zfsonlinux (from zfsonlinux_3~wheezy_all.deb) ...
Setting up zfsonlinux (3~wheezy) ...

root@eave:~# aptitude update
Get: 1 http://security.debian.org wheezy/updates Release.gpg [836 B]
Get: 2 http://security.debian.org wheezy/updates Release [102 kB]                
Get: 3 http://archive.zfsonlinux.org wheezy Release.gpg [836 B]               
Hit http://ftp.us.debian.org wheezy Release.gpg                                          
Get: 4 http://security.debian.org wheezy/updates/main Sources [141 kB]
Get: 5 http://archive.zfsonlinux.org wheezy Release [3,598 B]                
Get: 6 http://ftp.us.debian.org wheezy-updates Release.gpg [836 B]                       
Get: 7 http://security.debian.org wheezy/updates/contrib Sources [14 B]
Get: 8 http://security.debian.org wheezy/updates/non-free Sources [14 B]                   
Get: 9 http://security.debian.org wheezy/updates/main amd64 Packages [224 kB]              
Get: 10 http://security.debian.org wheezy/updates/contrib amd64 Packages [14 B]             
Hit http://ftp.us.debian.org wheezy Release                                                     
Get: 11 http://security.debian.org wheezy/updates/non-free amd64 Packages [14 B]
Get: 12 http://security.debian.org wheezy/updates/contrib Translation-en [14 B]
Get: 13 http://security.debian.org wheezy/updates/main Translation-en [127 kB]                                              
Get: 14 http://archive.zfsonlinux.org wheezy/main amd64 Packages [10.5 kB]                                                     
Get: 15 http://security.debian.org wheezy/updates/non-free Translation-en [14 B]                                          
Get: 16 http://ftp.us.debian.org wheezy-updates Release [124 kB]                              
Hit http://ftp.us.debian.org wheezy/main Sources                           
Hit http://ftp.us.debian.org wheezy/non-free Sources
Hit http://ftp.us.debian.org wheezy/contrib Sources               
Hit http://ftp.us.debian.org wheezy/main amd64 Packages           
Hit http://ftp.us.debian.org wheezy/non-free amd64 Packages
Ign http://archive.zfsonlinux.org wheezy/main Translation-en_US
Hit http://ftp.us.debian.org wheezy/contrib amd64 Packages
Ign http://archive.zfsonlinux.org wheezy/main Translation-en      
Hit http://ftp.us.debian.org wheezy/contrib Translation-en
Hit http://ftp.us.debian.org wheezy/main Translation-en
Hit http://ftp.us.debian.org wheezy/non-free Translation-en
Get: 17 http://ftp.us.debian.org wheezy-updates/main Sources [1,215 B]
Get: 18 http://ftp.us.debian.org wheezy-updates/contrib Sources [14 B]
Get: 19 http://ftp.us.debian.org wheezy-updates/non-free Sources [14 B]
Get: 20 http://ftp.us.debian.org wheezy-updates/main amd64 Packages/DiffIndex [1,747 B]
Get: 21 http://ftp.us.debian.org wheezy-updates/contrib amd64 Packages [14 B]
Get: 22 http://ftp.us.debian.org wheezy-updates/non-free amd64 Packages [14 B]
Get: 23 http://ftp.us.debian.org wheezy-updates/contrib Translation-en [14 B]
Get: 24 http://ftp.us.debian.org wheezy-updates/main Translation-en/DiffIndex [1,195 B]
Get: 25 http://ftp.us.debian.org wheezy-updates/non-free Translation-en [14 B]
Get: 26 http://ftp.us.debian.org wheezy-updates/main amd64 Packages [2,738 B]
Get: 27 http://ftp.us.debian.org wheezy-updates/main Translation-en [1,940 B]
Fetched 743 kB in 6s (122 kB/s)                                                                                                              
                            
Current status: 6 updates [+6], 32 new [+26].


root@eave:~# aptitude install debian-zfs
The following NEW packages will be installed:
  build-essential debian-zfs dpkg-dev{a} g++{a} g++-4.7{a} libalgorithm-diff-perl{a} libalgorithm-diff-xs-perl{a} 
  libalgorithm-merge-perl{a} libdpkg-perl{a} libfile-fcntllock-perl{a} libnvpair1{a} libstdc++6-4.7-dev{a} libuutil1{a} libzfs2{a} 
  libzpool2{a} spl spl-dkms{a} zfs-dkms zfsutils{a} 
0 packages upgraded, 19 newly installed, 0 to remove and 6 not upgraded.
Need to get 15.3 MB of archives. After unpacking 44.9 MB will be used.
Do you want to continue? [Y/n/?] 
Get: 1 http://ftp.us.debian.org/debian/ wheezy/main libstdc++6-4.7-dev amd64 4.7.2-5 [1,726 kB]
Get: 2 http://archive.zfsonlinux.org/debian/ wheezy/main spl-dkms all 0.6.3-7~wheezy [554 kB]
Get: 3 http://archive.zfsonlinux.org/debian/ wheezy/main zfs-dkms all 0.6.3-1~wheezy [1,475 kB]
Get: 4 http://ftp.us.debian.org/debian/ wheezy/main g++-4.7 amd64 4.7.2-5 [8,011 kB]
Get: 5 http://archive.zfsonlinux.org/debian/ wheezy/main spl amd64 0.6.3-7~wheezy [15.8 kB]
Get: 6 http://archive.zfsonlinux.org/debian/ wheezy/main libuutil1 amd64 0.6.3-1~wheezy [53.4 kB]
Get: 7 http://archive.zfsonlinux.org/debian/ wheezy/main libnvpair1 amd64 0.6.3-1~wheezy [50.8 kB]
Get: 8 http://archive.zfsonlinux.org/debian/ wheezy/main libzpool2 amd64 0.6.3-1~wheezy [465 kB]
Get: 9 http://archive.zfsonlinux.org/debian/ wheezy/main libzfs2 amd64 0.6.3-1~wheezy [144 kB]
Get: 10 http://ftp.us.debian.org/debian/ wheezy/main g++ amd64 4:4.7.2-1 [1,374 B]
Get: 11 http://archive.zfsonlinux.org/debian/ wheezy/main zfsutils amd64 0.6.3-1~wheezy [401 kB]
Get: 12 http://ftp.us.debian.org/debian/ wheezy/main libdpkg-perl all 1.16.15 [958 kB]
Get: 13 http://archive.zfsonlinux.org/debian/ wheezy/main debian-zfs amd64 7~wheezy [7,052 B]
Get: 14 http://ftp.us.debian.org/debian/ wheezy/main dpkg-dev all 1.16.15 [1,356 kB]
Get: 15 http://ftp.us.debian.org/debian/ wheezy/main build-essential amd64 11.5 [7,178 B]
Get: 16 http://ftp.us.debian.org/debian/ wheezy/main libalgorithm-diff-perl all 1.19.02-2 [51.5 kB]
Get: 17 http://ftp.us.debian.org/debian/ wheezy/main libalgorithm-diff-xs-perl amd64 0.04-2+b1 [12.9 kB]
Get: 18 http://ftp.us.debian.org/debian/ wheezy/main libalgorithm-merge-perl all 0.08-2 [13.5 kB]
Get: 19 http://ftp.us.debian.org/debian/ wheezy/main libfile-fcntllock-perl amd64 0.14-2 [17.2 kB]
Fetched 15.3 MB in 5s (2,603 kB/s)                   
Preconfiguring packages ...
Selecting previously unselected package spl-dkms.
(Reading database ... 41401 files and directories currently installed.)
Unpacking spl-dkms (from .../spl-dkms_0.6.3-7~wheezy_all.deb) ...
Setting up spl-dkms (0.6.3-7~wheezy) ...
Loading new spl-0.6.3 DKMS files...
First Installation: checking all kernels...
Building only for 3.2.0-4-amd64
Building initial module for 3.2.0-4-amd64
Done.

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

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

Running the post_install script:

depmod..............

DKMS: install completed.
Selecting previously unselected package zfs-dkms.
(Reading database ... 41649 files and directories currently installed.)
Unpacking zfs-dkms (from .../zfs-dkms_0.6.3-1~wheezy_all.deb) ...
Selecting previously unselected package libstdc++6-4.7-dev.
Unpacking libstdc++6-4.7-dev (from .../libstdc++6-4.7-dev_4.7.2-5_amd64.deb) ...
Selecting previously unselected package g++-4.7.
Unpacking g++-4.7 (from .../g++-4.7_4.7.2-5_amd64.deb) ...
Selecting previously unselected package g++.
Unpacking g++ (from .../g++_4%3a4.7.2-1_amd64.deb) ...
Selecting previously unselected package libdpkg-perl.
Unpacking libdpkg-perl (from .../libdpkg-perl_1.16.15_all.deb) ...
Selecting previously unselected package dpkg-dev.
Unpacking dpkg-dev (from .../dpkg-dev_1.16.15_all.deb) ...
Selecting previously unselected package build-essential.
Unpacking build-essential (from .../build-essential_11.5_amd64.deb) ...
Selecting previously unselected package spl.
Unpacking spl (from .../spl_0.6.3-7~wheezy_amd64.deb) ...
Selecting previously unselected package libuutil1.
Unpacking libuutil1 (from .../libuutil1_0.6.3-1~wheezy_amd64.deb) ...
Selecting previously unselected package libnvpair1.
Unpacking libnvpair1 (from .../libnvpair1_0.6.3-1~wheezy_amd64.deb) ...
Selecting previously unselected package libzpool2.
Unpacking libzpool2 (from .../libzpool2_0.6.3-1~wheezy_amd64.deb) ...
Selecting previously unselected package libzfs2.
Unpacking libzfs2 (from .../libzfs2_0.6.3-1~wheezy_amd64.deb) ...
Selecting previously unselected package zfsutils.
Unpacking zfsutils (from .../zfsutils_0.6.3-1~wheezy_amd64.deb) ...
Selecting previously unselected package debian-zfs.
Unpacking debian-zfs (from .../debian-zfs_7~wheezy_amd64.deb) ...
Selecting previously unselected package libalgorithm-diff-perl.
Unpacking libalgorithm-diff-perl (from .../libalgorithm-diff-perl_1.19.02-2_all.deb) ...
Selecting previously unselected package libalgorithm-diff-xs-perl.
Unpacking libalgorithm-diff-xs-perl (from .../libalgorithm-diff-xs-perl_0.04-2+b1_amd64.deb) ...
Selecting previously unselected package libalgorithm-merge-perl.
Unpacking libalgorithm-merge-perl (from .../libalgorithm-merge-perl_0.08-2_all.deb) ...
Selecting previously unselected package libfile-fcntllock-perl.
Unpacking libfile-fcntllock-perl (from .../libfile-fcntllock-perl_0.14-2_amd64.deb) ...
Processing triggers for man-db ...
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-3.2.0-4-amd64
Setting up zfs-dkms (0.6.3-1~wheezy) ...
Loading new zfs-0.6.3 DKMS files...
First Installation: checking all kernels...
Building only for 3.2.0-4-amd64
Building initial module for 3.2.0-4-amd64
Done.

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

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

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

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

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

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

depmod.............

DKMS: install completed.
Setting up libdpkg-perl (1.16.15) ...
Setting up dpkg-dev (1.16.15) ...
Setting up spl (0.6.3-7~wheezy) ...
Setting up libuutil1 (0.6.3-1~wheezy) ...
Setting up libnvpair1 (0.6.3-1~wheezy) ...
Setting up libzpool2 (0.6.3-1~wheezy) ...
Setting up libzfs2 (0.6.3-1~wheezy) ...
Setting up zfsutils (0.6.3-1~wheezy) ...
Setting up libalgorithm-diff-perl (1.19.02-2) ...
Setting up libalgorithm-diff-xs-perl (0.04-2+b1) ...
Setting up libalgorithm-merge-perl (0.08-2) ...
Setting up libfile-fcntllock-perl (0.14-2) ...
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-3.2.0-4-amd64
Setting up debian-zfs (7~wheezy) ...
Setting up g++-4.7 (4.7.2-5) ...
Setting up g++ (4:4.7.2-1) ...
update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
Setting up build-essential (11.5) ...
Setting up libstdc++6-4.7-dev (4.7.2-5) ...
PS: For Ubuntu, you have to do this:

# apt-add-repository --yes ppa:zfs-native/stable
# aptitude install debootstrap spl-dkms zfs-dkms ubuntu-zfs

Example:

root@ibm:~# apt-add-repository --yes ppa:zfs-native/stable
gpg: keyring `/tmp/tmp74YZpk/secring.gpg' created
gpg: keyring `/tmp/tmp74YZpk/pubring.gpg' created
gpg: requesting key F6B0FC61 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp74YZpk/trustdb.gpg: trustdb created
gpg: key F6B0FC61: public key "Launchpad PPA for Native ZFS for Linux" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
root@ibm:~# aptitude update
[...useless output removed...]
root@ibm:~# aptitude install debootstrap spl-dkms zfs-dkms ubuntu-zfs
The following NEW packages will be installed:
  debootstrap libnvpair1{a} libuutil1{a} libzfs2{a} libzpool2{a} spl{a} spl-dkms ubuntu-zfs zfs-dkms 
  zfsutils 
The following packages will be upgraded:
  mountall 
1 packages upgraded, 10 newly installed, 0 to remove and 592 not upgraded.
Need to get 4,134 kB of archives. After unpacking 17.6 MB will be used.
Do you want to continue? [Y/n/?] 
[....the output is similar with debian...]

Now you can play with it if you have spare disks:

Create a simple pool (no mirror or raid) and list it afterwards:

zpool create zfs /dev/datavg/zfslv
zpool list

Example:
root@eave:~# zpool create zfs /dev/datavg/zfslv
root@eave:~# zpool list
NAME   SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
zfs   4.97G    90K  4.97G     0%  1.00x  ONLINE  -
root@eave:~# zpool status
  pool: zfs
 state: ONLINE
  scan: none requested
config:

	NAME        STATE     READ WRITE CKSUM
	zfs         ONLINE       0     0     0
	  zfslv     ONLINE       0     0     0

The moment you create a pool, an zfs filesystem will be created also so you can list it also like this (the mount point will be the name of the pool):

root@eave:~# zfs list
NAME   USED  AVAIL  REFER  MOUNTPOINT
zfs    106K  4.89G    29K  /zfs

If you want to delete the zfs pool, you can do it with the following command:

root@eave:~# zpool destroy zfs
root@eave:~# zpool list
no pools available

To enable compression to your zfs pool and list it, do the following:

root@eave:~# zfs set compression=lz4 zfs
root@eave:~# zfs get compressratio zfs
NAME  PROPERTY       VALUE  SOURCE
zfs   compressratio  1.00x  -
Compression test:
root@eave:/zfs# tar -cf test.tar /var/log/
tar: Removing leading `/' from member names
root@eave:/zfs# ls -la
total 10116
drwxr-xr-x  2 root root        3 Dec  1 23:11 .
drwxr-xr-x 26 root root      664 Dec  1 23:06 ..
-rw-r--r--  1 root root 31672320 Dec  1 23:11 test.tar
root@eave:/zfs# zfs get compressratio zfs
NAME  PROPERTY       VALUE  SOURCE
zfs   compressratio  3.05x  -

root@eave:/zfs# cp test.tar /tmp
root@eave:/zfs# du -sh test.tar 
9.9M	test.tar
root@eave:/zfs# du -sh /tmp/test.tar 
31M	/tmp/test.tar

How to create a mirror zfs pool:

zpool create backups mirror oglebkp-part1 sunbkp-part1

Example:
root@pluto:~# zpool create backups mirror oglebkp-part1 sunbkp-part1
root@pluto:~# zpool list
NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
backups  99.5G  92.5K  99.5G     0%  1.00x  ONLINE  -

root@pluto:~# df -h /backups
Filesystem      Size  Used Avail Use% Mounted on
backups          98G     0   98G   0% /backups

If one of your disk was gone form the pool and is back now, you can do the following:

zpool clear backups

Example:
root@pluto:~# zpool status backups
  pool: backups
 state: DEGRADED
status: One or more devices are faulted in response to persistent errors.
	Sufficient replicas exist for the pool to continue functioning in a
	degraded state.
action: Replace the faulted device, or use 'zpool clear' to mark the device
	repaired.
  scan: none requested
config:

	NAME               STATE     READ WRITE CKSUM
	backups            DEGRADED     0     0     0
	  mirror-0         DEGRADED     0     0     0
	    oglebkp-part1  FAULTED      0     0     0  too many errors
	    sunbkp-part1   ONLINE       0     0     0

errors: No known data errors
root@pluto:~# zpool clear backups
root@pluto:~# zpool status backups
  pool: backups
 state: ONLINE
  scan: none requested
config:

	NAME               STATE     READ WRITE CKSUM
	backups            ONLINE       0     0     0
	  mirror-0         ONLINE       0     0     0
	    oglebkp-part1  ONLINE       0     0     0
	    sunbkp-part1   ONLINE       0     0     0

errors: No known data errors

How to replace a disk in a zfs pool:

zpool replace rex sdb sdx

How to check the history of events in a zfs pool:

root@pluto:~# zpool history backups
History for 'backups':
2014-12-07.22:03:38 zpool create backups mirror oglebkp-part1 sunbkp-part1
2014-12-07.22:06:33 zfs set compression=lz4 backups
2014-12-07.22:58:20 zpool clear backups
2014-12-08.09:09:13 zpool scrub backups

How to scrub a zfs pool:

The simplest way to check your data integrity is to initiate an explicit scrubbing of all data within the pool. This operation traverses all the data in the pool once and verifies that all blocks can be read. Scrubbing proceeds as fast as the devices allow, though the priority of any I/O remains below that of normal operations. This operation might negatively impact performance, though the file system should remain usable and nearly as responsive while the scrubbing occurs.
root@pluto:~# zpool scrub backups
root@pluto:~# zpool status backups
  pool: backups
 state: ONLINE
  scan: scrub in progress since Mon Dec  8 09:09:04 2014
    5.26G scanned out of 23.2G at 20.2M/s, 0h15m to go
    0 repaired, 22.63% done
config:

	NAME               STATE     READ WRITE CKSUM
	backups            ONLINE       0     0     0
	  mirror-0         ONLINE       0     0     0
	    oglebkp-part1  ONLINE       0     0     0
	    sunbkp-part1   ONLINE       0     0     0

errors: No known data errors

How to put offline/online a disk in zfs pool:

root@pluto:~# zpool offline backups sdx
root@pluto:~# zpool online backups sdx

How to enable ZFS deduplication and see it's magic:

The basic concept is that when data is written to a ZFS filesystem with dedup turned on, ZFS only stored blocks that are unique within the ZFS pool, rather than storing redundant copies of identical data. See Jeff Bonwick's blog for more information on concepts and implementation.
root@pluto:~# zpool list
NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
backups  99.5G  26.1G  73.4G    26%  1.00x  DEGRADED  -
root@pluto:~# zpool get dedup backups
NAME     PROPERTY    VALUE  SOURCE
backups  dedupratio  1.00x  -

root@pluto:~# zfs get dedup backups
NAME     PROPERTY  VALUE          SOURCE
backups  dedup     off            default
root@pluto:~# zfs set dedup=on backups
root@pluto:~# zfs get dedup backups
NAME     PROPERTY  VALUE          SOURCE
backups  dedup     on             local


root@pluto:/backups/test/v1# ls -la
total 21289
drwxr-xr-x 2 root root        3 Dec  8 23:16 .
drwxr-xr-x 6 root root        6 Dec  8 23:10 ..
-rw-r--r-- 1 root root 22341640 Dec  8 23:16 etc.zip


root@pluto:/backups/test/v1# cp etc.zip ../v2
root@pluto:/backups/test/v1# cp etc.zip ../v3
root@pluto:/backups/test/v1# cp etc.zip ../v4

root@pluto:/backups/test# ls -la */*.zip
-rw-r--r-- 1 root root 22341640 Dec  8 23:16 v1/etc.zip
-rw-r--r-- 1 root root 22341640 Dec  8 23:16 v2/etc.zip
-rw-r--r-- 1 root root 22341640 Dec  8 23:17 v3/etc.zip
-rw-r--r-- 1 root root 22341640 Dec  8 23:20 v4/etc.zip
root@pluto:/backups/test# zpool list
NAME      SIZE  ALLOC   FREE    CAP  DEDUP  HEALTH  ALTROOT
backups  99.5G  26.2G  73.3G    26%  4.00x  DEGRADED  -
You will have to verify if dedup is needed for you because it consumes a lot of memory and sometimes it is not necessary. For example, after you have all your files in place, you can do the following command and see. If the deduplication ratio is less than 2, enabling dedup is not recommended.
In my example below, it is not recommended:
root@pluto:/backups/test# zdb -S backups
Simulated DDT histogram:

bucket              allocated                       referenced          
______   ______________________________   ______________________________
refcnt   blocks   LSIZE   PSIZE   DSIZE   blocks   LSIZE   PSIZE   DSIZE
------   ------   -----   -----   -----   ------   -----   -----   -----
     1     499K   23.5G   14.1G   14.1G     499K   23.5G   14.1G   14.1G
     2    83.9K   4.39G   3.08G   3.08G     188K   9.71G   6.62G   6.62G
     4    55.2K   1.62G    874M    874M     256K   7.06G   3.70G   3.70G
     8    14.6K    172M   91.6M   91.6M     141K   1.51G    841M    841M
    16    1.67K   11.9M   6.89M   6.89M    31.8K    230M    133M    133M
    32      140    298K    236K    236K    5.45K   11.4M   9.00M   9.00M
    64       32   1.03M    743K    743K    2.89K    110M   77.2M   77.2M
   128        6      3K      3K      3K    1.09K    556K    556K    556K
   256       11   1.13M    802K    802K    4.36K    482M    335M    335M
   512        1     512     512     512      942    471K    471K    471K
    1K        1     512     512     512    1.76K    901K    901K    901K
    2K        1     512     512     512    2.11K   1.05M   1.05M   1.05M
 Total     655K   29.7G   18.1G   18.1G    1.11M   42.6G   25.8G   25.8G

dedup = 1.42, compress = 1.66, copies = 1.00, dedup * compress / copies = 2.35

How to create swap device in ZFS with ZVOL:

root@pluto:/backups# [color=green]zfs create -V 1G backups/swap[/color]
root@pluto:/backups# zfs list
NAME           USED  AVAIL  REFER  MOUNTPOINT
backups       70.1G   126G  69.1G  /backups
[color=green]backups/swap  1.03G   127G  16.5K  -[/color]
root@pluto:/backups# [color=green]mkswap /dev/zvol/backups/swap[/color]
mkswap: /dev/zvol/backups/swap: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=2b7167ab-0c05-401a-90f3-5bcecb36663d
root@pluto:/backups# [color=green]swapon -p 16500 /dev/zvol/backups/swap[/color]
root@pluto:/backups# swapon -s
Filename				Type		Size	Used	Priority
/dev/mapper/rootvg-swap                 partition	1048572	13888	-1
/dev/zd0                                partition	1048572	0	16500

How to resize (set quota) a zfs filesystem:

root@uranus:/var/cache# zfs list
NAME           USED  AVAIL  REFER  MOUNTPOINT
data           150K  49.0G    31K  /data
data/fscache    30K  49.0G    30K  /data/fscache
root@uranus:/var/cache# [color=green]zfs set quota=20G data/fscache[/color]
root@uranus:/var/cache# zfs list
NAME           USED  AVAIL  REFER  MOUNTPOINT
data           150K  49.0G    31K  /data
data/fscache    30K  20.0G    30K  /data/fscache

How to speedup zfs on linux:

ZFS on Linux stores xattrs in a hidden folder, as regular files! This is very slow, requiring multiple seeks per xattr, and it doesn't appear to cache very well either.
The fix is to store the data in the inodes, which will boost up the speed too:
# zfs set xattr=sa (pool)

How to create zfs volume with different mount point:

# zfs create -o atime=off -o mountpoint=/var/spool/squid3 cache/squid

How to modify zfs mount point or remove the mount point of a zfs:

You have to modfy the mountpoint value to the desired mount point or to none to remove it.
# zfs set mountpoint=none zfs_device

Example:

root@ibm:~# df -h | grep ibm
ibm                      196G     0  196G   0% /ibm
root@ibm:~# zfs get mountpoint ibm
NAME  PROPERTY    VALUE       SOURCE
ibm   mountpoint  /ibm        default
root@ibm:~# [color=green]zfs set mountpoint=none ibm[/color]
root@ibm:~# zfs get mountpoint ibm
NAME  PROPERTY    VALUE       SOURCE
ibm   mountpoint  none        local
root@ibm:~# zfs list
NAME   USED  AVAIL  REFER  MOUNTPOINT
ibm    120K   196G    30K  none
root@ibm:~# df -h | grep ibm
root@ibm:~# 
root@ibm:~# [color=green]zfs set mountpoint=/bah ibm[/color]
root@ibm:~# zfs list
NAME   USED  AVAIL  REFER  MOUNTPOINT
ibm    120K   196G    30K  /bah
root@ibm:~# df -h | grep bah
ibm                      196G     0  196G   0% /bah

Inspiration:
https://pthree.org/2012/04/17/install-zfs-on-debian-gnulinux/
http://docs.oracle.com/cd/E19082-01/817-2271/gavwg/index.html
https://blogs.oracle.com/jsavit/entry/deduplication_now_in_zfs
http://www.oracle.com/technetwork/articles/servers-storage-dev/o11-113-size-zfs-dedup-1354231.html

Thou shalt not steal!

If you want to use this information on your own website, please remember: by doing copy/paste entirely it is always stealing and you should be ashamed of yourself! Have at least the decency to create your own text and comments and run the commands on your own servers and provide your output, not what I did!

Or at least link back to this website.

Recent content