A friend of mine likes to try ZFS on CentOS 7, therefore I decide to make a guide for him. The following instructions have been well tested on CentOS 7.
Before you decide to put ZFS in a production use, you should be aware of the following:
- ZFS is originally designed to work with Solaris and BSD system. Because of the legal and licensing issues, ZFS cannot be shipped with Linux.
- Since ZFS is open source, some developers port the ZFS the Linux, and make it run at the kernel level via dkms. This works great as long as you don’t update the kernel. Otherwise the ZFS will not be loaded with the new kernel.
- In a ZFS/Linux environment, it is a bad idea to update the system automatically.
- For some odd reasons, ZFS/Linux will work with server grade or gaming grade computers. Do not run ZFS/Linux on entry level computers.
By default, ZFS is not available in the standard CentOS repository. We will need to include some 3rd party repositories here.
sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm sudo rpm -Uvh https://forensics.cert.org/cert-forensics-tools-release-el7.rpm sudo rpm -Uvh http://download.zfsonlinux.org/epel/zfs-release.el7_3.noarch.rpm sudo yum update -y sudo yum groupinstall -y "Development Tools" "Development Libraries" "Additional Development" sudo yum install -y kernel-devel kernel-headers
It is very likely that the system will install a new kernel. You may want to reboot the computer before installing the ZFS.
Please make sure that the system does not update automatically. If you need to update the system, please exclude the kernel and related modules from the update.
sudo nano /etc/yum.conf exclude=kernel*
Now you are on the latest kernel. Let’s install the ZFS:
sudo yum install -y zfs sudo /sbin/modprobe zfs
Now, you can create a simple stripped ZFS. Stripped ZFS gives you the best performances and zero data protections. When referencing the disks, we don’t want to use /dev/sd*, instead, we want to use the device id directly, e.g., /dev/disk/by-id/wwn-0x8000c8004e8ac11a
ls /dev/disk/by-id/ lrwxrwxrwx 1 root root 9 Jan 3 21:49 wwn-0x8000c8004e8ac11a -> ../../sde lrwxrwxrwx 1 root root 9 Jan 3 21:49 wwn-0x8000c8008ad0a22d -> ../../sdd lrwxrwxrwx 1 root root 9 Jan 3 21:49 wwn-0x8000c8008b4f6338 -> ../../sda lrwxrwxrwx 1 root root 9 Jan 3 21:49 wwn-0x8000c8008b52144c -> ../../sdc lrwxrwxrwx 1 root root 9 Jan 3 21:49 wwn-0x8000c8008b59a553 -> ../../sdb
Once you identify the list of the hard disks, we can create a simple stripped ZFS. This will create a ZFS under /storage. You can replace storage to anything you like.
#We are going to create a ZFS pool with three disks. You can add more if you like. For stripped design, the higher number of disks, the faster the IO speed. zpool create -f storage /dev/disk/by-id/device1 /dev/disk/by-id/device2 /dev/disk/by-id/device3
storage is like a big umbrella. Under this umbrella, we will need to create multiple “partitions” for storing data.
zfs create storage/mydata
If you have a fast CPU like i7, you may want to turn on the compression. This will reduce the amount of data write to the system, and it will improve the overall performance.
sudo zfs set compression=lz4 storage
Finally we want to change the ownership and the permissions
#Assuming that you are part of the wheel group sudo chown -R root:wheel /storage sudo chmod -R g+rw /storage
Now, run df and you should be able to see the ZFS in your system.
#df -h Filesystem Size Used Avail Use% Mounted on storage 6.8T 128K 6.8T 1% /storage storage/mydata 13T 6.1T 6.8T 48% /storage/mydata
You can monitor the health of the ZFS system.
#sudo zpool status pool: storage state: ONLINE config: NAME STATE READ WRITE CKSUM storage ONLINE 0 0 0 wwn-0x8000c8004e8ac11a ONLINE 0 0 0 wwn-0x8000c8008ad0a22d ONLINE 0 0 0 wwn-0x8000c8008b4f6338 ONLINE 0 0 0 wwn-0x8000c8008b52144c ONLINE 0 0 0 errors: No known data errors
For some very odd reasons, ZFS will not be loaded automatically. We want to make sure that ZFS will be loaded after reboot.
#sudo nano /etc/crontab #Add the following: @reboot root sleep 10; zpool import -a;
Now you can try to test the ZFS by running dd or copying a big file to the ZFS. If you are not happy with the configurations, you can always destroy it and re-create the ZFS again.
sudo zpool destroy storage
- Running ZFS on Linux: Things you should know and be aware of
- ZFS Performance: Mirror VS RAIDZ VS RAIDZ2 vs RAIDZ3 vs Striped
- How to fix ZFS after updating to a newer kernel
- How to improve ZFS performance