Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm planning to setup a set of 3x 2TB 7200rpm drives as a LUKS-encrypted Z-RAID pool in Linux (for a NAS solution).

My understanding of the problem at hand is that the only way to achieve this is to luksFormat every physical device and then assemble a zpool out of unlocked LUKS containers.

I have the following concerns with this:

  • Wouldn't it significantly impede write performance? In this setup redundant data is encrypted several times because LUKS is not "aware" of Z-RAID. In LUKS-on-mdadm solution data is encrypted once and merely written to disks multiple times. My CPU supports Intel AES-NI.

  • Will ZFS be aware of disk failures when operating on device-mapper LUKS containers as opposed to physical devices? How about deduplication and other ZFS features?

share|improve this question
I wouldn't do it. Sounds failure-prone. – ewwhite Apr 5 '14 at 23:01
Why not leave the devices unencrypted and encrypt the file system instead? – MadHatter Apr 9 '14 at 13:53
@MadHatter Because it's ZFS. You can't do that. – Michael Hampton Apr 9 '14 at 13:55
Fine (I'll take your word for it). Make a single large ZFS containing a single large file, loopback mount it and encrypt that. – MadHatter Apr 9 '14 at 13:56
Never, ever, create a large file and loopback it with ZFS. You're gone screw up your pool to an unusable speed when CoW run out of space for it's operations. – Vinícius Ferrão Apr 10 '14 at 5:14
up vote 15 down vote accepted

One of the servers that I administrate runs the type of configuration that you describe. It has six 1TB hard drives with a LUKS-encrypted RAIDZ pool on it. I also have two 3TB hard drives in a LUKS-encrypted ZFS mirror that are swapped out every week to be taken off-site. The server has been using this configuration for about three years, and I've never had a problem with it.

If you have a need for ZFS with encryption on Linux then I recommend this setup. I'm using ZFS-Fuse, not ZFS on Linux. However, I believe that would have no bearing on the result other than ZFS on Linux will probably have better performance than the setup that I am using.

In this setup redundant data is encrypted several times because LUKS is not "aware" of Z-RAID. In LUKS-on-mdadm solution data is encrypted once and merely written to disks multiple times.

Keep in mind that LUKS isn't aware of RAID. It only knows that it's sitting on top of a block device. If you use mdadm to create a RAID device and then luksformat it, it is mdadm that is replicating the encrypted data to the underlying storage devices, not LUKS.

Question 2.8 of the LUKS FAQ addresses whether encryption should be on top of RAID or the other way around. It provides the following diagram.

Filesystem     <- top
Raw partitions
Raw disks      <- bottom

Because ZFS combines the RAID and filesystem functionality, your solution will need to look like the following.

RAID-Z and ZFS Filesystem  <-top
Raw partitions (optional)
Raw disks                  <- bottom

I've listed the raw partitions as optional as ZFS expects that it will use raw block storage rather than a partition. While you could create your zpool using partitions, it's not recommended because it'll add a useless level of management, and it will need to be taken into account when calculating what your offset will be for partition block alignment.

Wouldn't it significantly impede write performance? [...] My CPU supports Intel AES-NI.

There shouldn't be a performance problem as long as you choose an encryption method that's supported by your AES-NI driver. If you have cryptsetup 1.6.0 or newer you can run cryptsetup benchmark and see which algorithm will provide the best performance.

This question on recommended options for LUKS may also be of value.

Given that you have hardware encryption support, you are more likely to face performance issues due to partition misalignment.

ZFS on Linux has added the ashift property to the zfs command to allow you to specify the offset for your hard drives. According to the linked FAQ, ashift=12 would tell it that you are using drives with a 4K block size.

The LUKS FAQ states that a LUKS partition has an alignment of 1 MB. Questions 6.12 and 6.13 discuss this in detail and also provide advice on how to make the LUKS partition header larger. However, I'm not sure it's possible to make it large enough to ensure that your ZFS filesystem will be created on a 4K boundary. I'd be interested in hearing how this works out for you if this is a problem you need to solve. Since you are using 2TB drives, you might not face this problem.

Will ZFS be aware of disk failures when operating on device-mapper LUKS containers as opposed to physical devices?

ZFS will be aware of disk failures insofar as it can read and write to them without problems. ZFS requires block storage and doesn't care or know about the specifics of that storage and where it comes from. It only keeps track of any read, write or checksum errors that it encounters. It's up to you to monitor the health of the underlying storage devices.

The ZFS documentation has a section on troubleshooting which is worth reading. The section on replacing or repairing a damaged device describes what you might encounter during a failure scenario and how you might resolve it. You'd do the same thing here that you would for devices that don't have ZFS. Check the syslog for messages from your SCSI driver, HBA or HD controller, and/or SMART monitoring software and then act accordingly.

How about deduplication and other ZFS features?

All of the ZFS features will work the same regardless of whether the underlying block storage is encrypted or not.


  1. ZFS on LUKS-encrypted devices works well.
  2. If you have hardware encryption, you won't see a performance hit as long as you use an encryption method that's supported by your hardware. Use cryptsetup benchmark to see what will work best on your hardware.
  3. Think of ZFS as RAID and filesystem combined into a single entity. See the ASCII diagram above for where it fits into the storage stack.
  4. You'll need to unlock each LUKS-encrypted block device that the ZFS filesystem uses.
  5. Monitor the health of the storage hardware the same way you do now.
  6. Be mindful of the filesystem's block alignment if you are using drives with 4K blocks. You may need to experiment with luksformat options or other settings to get the alignment you need for acceptable speed.
share|improve this answer
+1 For finding a way to make this work with examples. – ewwhite Apr 10 '14 at 14:22
1 MiB is already evenly divisible by 4KiB, so you should be correctly aligned all the way up to ashift=20 (which I don't think will be necessary within my career) provided you used raw disks. – Michael Hampton Apr 10 '14 at 14:36
Just one more thing: I'm voting up your answer because it's what OP expected, and is well written, so it's shure better than mine answer. – Vinícius Ferrão Apr 10 '14 at 14:44
@ViníciusFerrão: Also take note that FreeBSD and FreeNAS are using an identical approach for ZFS encryption. geli is used to create an encrypted device and the plaintext data is made available via a second device which ZFS uses. See the second bullet point at – Starfish Apr 10 '14 at 18:55
@CMCDragonkai Since both L2ARC and SLOG devices contain bits and pieces of data from your pool, if you are encrypting the storage in order to provide confidentiality (which is often the point of using encrypted storage in the first place), you almost certainly want to run any L2ARC and SLOG devices similarly encrypted as well. – Michael Kjörling Jan 20 at 10:03

The first thing to keep in mind is that ZFS should never be used this way.

ZFS isn't a common filesystem, it consists of a RAID-layer, filesystem and even fileserver, as ZFS natively supports NFS for example.

Think ZFS as an hardware controller, when the ZFS is the software running in the controller, your system RAM is the controller cache (ARC) and your x86 CPU is the CPU on the controller.

Said that ZFS expects raw disks without any layer on top of it. Don't even consider a RAID controller in middle of ZFS and disks. Just use plain HBA cards or controllers flashed to IT (JBOD) mode, so it can handle, for example, SMART Errors.

ZFS is absurdly complex to setup and use, it's not a common filesystem and it should be used correctly to avoid unrecoverable dataloss. Due to it's copy-on-write nature with automatic checksumming there are no recovery tools for ZFS. When you lost a pool it's almost right that you need to rollup backups.

Don't even consider ZFS deduplication if you don't have available system RAM to do this. Dedup tables can get easily gigabytes in size, and if you don't have available RAM to load the dedup table you end up with an unmountable pool. So please, if you want to save space, enable lz4 compression on your pool, it will save space and will increase IOPS, since the block lookups will take less time.

If you need crypto, you should use the ZFS cryptography instead.

And finally, ZFS is a memory hunger. Some recommendations says that you need 1GB of RAM per 1TB of raw disk space. This is mainly due the ZFS nature and it's caches. Anything with less than 8GB of RAM should not be used with ZFS.

Consider using ZFS appliances if you only want a NAS/SAN/DAS, like FreeNAS or NexentaStor. They are free to use.

share|improve this answer
"If you need crypto, you should use the ZFS cryptography instead." Which ZFS implementations that run on Linux implement ZFS encryption? – Michael Kjörling Apr 10 '14 at 12:08
ZFS doesn't handle SMART errors. It doesn't operate at the hardware level, so it doesn't know about the health of the hardware. ZFS interfaces with block storage devices and can only tell if it's having problem reading or writing to those devices. If ZFS is saying that it is having read, write, or checksum errors then you will need to check syslog to see what the underlying problem is. – Starfish Apr 10 '14 at 12:08
@Starfish sorry for bad writing. I wanted to say that you shouldn't use a RAID controller for SMART checks. ZFS isn't aware of SMART checks as you said. You're right. I'll fix up my text just changing the order of the sentences. – Vinícius Ferrão Apr 10 '14 at 14:19
Could you please provide an explanation of why "ZFS should never be used this way"? That is an extraordinary claim, and I don't see anything in your answer to support that. – Starfish Apr 12 '14 at 6:11
This is nonsense. Even though ZFS consists of many layers of functionality, there is no reason you need to use them all, and in fact many of the layers have been ripped out in various implementations on FreeBSD, Linux, and others. My company has been running ZFS filesystems on top of LUKS- and GELI-encrypted devices on top of various RAID devices (hardware and software) for many years, sometimes even with virtualization inbetween, with great performance and no problem, and it's not because we're lucky. Incidentally, ZFS is not a a hardware controller by our industry's definition of the term. – ruief Nov 14 '15 at 7:21

An alternative implementation is to create a ZVOL block device (, use LUKS to encrypt the newly created ZVOL and then create an ext4 (or other) filesystem on top of the encrypted block device.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.