January 17

Linux: Compiling ZFS on Red Hat/Centos

 

 

Installing ZFS on a CentOS 6 Linux server

 

The ZFS file system for Linux comes as source code, which you build into loadable kernel modules (this is how they get around the license incompatibilities). The implementation also contains the userland utilities (zfs, zpool, etc.) most Solaris admins are used to, and they act just like their Solaris counterparts! Nice!

 

Testing occurred on a CentOS 6 machine, specifically 6.5:

 

$ cat /etc/redhat-release
CentOS release 6.5 (Final)

 

Install dependencies:

 

$ yum install gcc kernel-devel zlib-devel libuuid-devel libblkid-devel libselinux-devel parted lsscsi rpm-build

 

Once these are installed you can retrieve and build spl and zfs packages from:

 

http://zfsonlinux.org/download.html

Once downloaded do the following:

 

$ tar xfvz spl-0.6.0-rc14.tar.gz

$ cd spl-0.6.*

 

$ ./configure

$ make rpm

 

$ rpm -Uvh *.x86_64.rpm

 

Preparing...                ########################################### [100%]
   1:spl-modules-devel      ########################################### [ 33%]
   2:spl-modules            ########################################### [ 67%]
   3:spl                    ########################################### [100%]

 

$ wget http://github.com/downloads/zfsonlinux/zfs/zfs-0.6.0-rc6.tar.gz

 

$ tar xfvz zfs-0.6.0-rc14.tar.gz

$ cd zfs-0.6.*

 

$ ./configure

$ make rpm

 

$ rpm -Uvh *.x86_64.rpm

 

Preparing...                ########################################### [100%]
   1:zfs-test               ########################################### [ 17%]
   2:zfs-modules-devel      ########################################### [ 33%]
   3:zfs-modules            ########################################### [ 50%]
   4:zfs-dracut             ########################################### [ 67%]
   5:zfs-devel              ########################################### [ 83%]
   6:zfs                    ########################################### [100%]

 

If everything went as planned you now have the ZFS kernel modules and userland utilities installed! To begin using ZFS you will first need to load the kernel modules with modprobe:

 

$ modprobe zfs

 

To verify the module loaded you can tail /var/log/messages:

 

Feb 12 17:54:27 centos6 kernel: SPL: Loaded module v0.6.0, using hostid 0x00000000
Feb 12 17:54:27 centos6 kernel: zunicode: module license 'CDDL' taints kernel.
Feb 12 17:54:27 centos6 kernel: Disabling lock debugging due to kernel taint
Feb 12 17:54:27 centos6 kernel: ZFS: Loaded module v0.6.0, ZFS pool version 28, ZFS filesystem version 5

 

And run lsmod to verify they are there:

 

$ lsmod | grep -i zfs

 

zfs                  1038053  0
zcommon                42478  1 zfs
znvpair                47487  2 zfs,zcommon
zavl                    6925  1 zfs
zunicode              323120  1 zfs
spl                   210887  5 zfs,zcommon,znvpair,zavl,zunicode

 

To create our first pool we can use the zpool utilities create option:

 

$ zpool create mysqlpool mirror sdb sdc

 

The example above created a mirrored pool out of the sdb and sdc block devices. We can see this layout in the output of `zpool status`:

 

$ zpool status -v

 

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

	NAME        STATE     READ WRITE CKSUM
	mysqlpool   ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    sdb     ONLINE       0     0     0
	    sdc     ONLINE       0     0     0

errors: No known data errors

 

Awesome! Since we are at pool version 28 lets disable atime updates and enable compression and deduplication:

 

$ zfs set compression=on mysqlpool

 

$ zfs set dedup=on mysqlpool

 

$ zfs set atime=off mysqlpool

 

For a somewhat real world test, I stopped one of my MySQL slaves, mounted the pool on /var/lib/mysql, synchronized the previous data over to the ZFS file system and then started MySQL. No errors to report, and MySQL is working just fine. Next up, I trash one side of the mirror and verified that resilvering works:

 

$ dd if=/dev/zero of=/dev/sdb

 

$ zpool scrub mysqlpool

 

I let this run for a few minutes then ran `zpool status` to verify the scrub fixed everything:

 

$ zpool status -v

 

  pool: mysqlpool
 state: ONLINE
status: One or more devices has experienced an unrecoverable error.  An
	attempt was made to correct the error.  Applications are unaffected.
action: Determine if the device needs to be replaced, and clear the errors
	using 'zpool clear' or replace the device with 'zpool replace'.
   see: http://www.sun.com/msg/ZFS-8000-9P
 scan: scrub repaired 966K in 0h0m with 0 errors on Sun Feb 12 18:54:51 2012
config:

	NAME        STATE     READ WRITE CKSUM
	mysqlpool   ONLINE       0     0     0
	  mirror-0  ONLINE       0     0     0
	    sdb     ONLINE       0     0   175
	    sdc     ONLINE       0     0     0

By: Matty
Modified By: nighthawk


Copyright 2021. All rights reserved.

Posted January 17, 2014 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. Securely email me using - PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B