How to Recover Files from Encrypted ZFS Pools

Accidentally deleting files from encrypted ZFS or destroying an entire pool does not necessarily mean permanent data loss. This article shows how to use Hetman Partition Recovery to recover files from ZFS pools protected by a passphrase or a key file, and how to find data after destroying a pool with zpool destroy and deleting its GPT partition in FreeBSD.

How to Recover Files from Encrypted ZFS Pools

Stop using the source drive as soon as data is lost. Do not create new pools, format or initialize the drive, or run repair or structural recovery operations on the original. If the drive can be read safely, create a full disk image and work with the copy. If there are signs of physical failure, avoid stressing the drive with repeated scans.

For this test, we use Hetman Partition Recovery, available for Windows, Linux and macOS. All three pools in our experiment reside on one physical drive, so no multi-disk array reconstruction is required. For multi-disk configurations, see our separate guide to RAIDZ and Stripe recovery.

Go to view
How to Recover Files from Encrypted ZFS Pools

How to Recover Files from Encrypted ZFS Pools

Test environment: three encrypted ZFS pools

We used a Dell PowerEdge server running FreeBSD 15.1. On a separate physical drive of approximately 55 GB, we created a GPT partition table and three partitions of approximately 18 GB each, using each partition for a separate ZFS pool. In FreeBSD the device was named /dev/mfid1; the GPT labels were p1_pass, p2_key and p3_pass. The test uses a single block device; the controller’s underlying configuration and the physical media type were not established.

Three 18 GB freebsd-zfs partitions on the GPT device mfid1
The initial GPT contains p1_pass, p2_key and p3_pass, with approximately 1 GB still free.

Native ZFS encryption is configured at the dataset level, not for the entire partition table or physical disk. ZFS uses keys to access the contents of encrypted datasets. The encryption, keyformat and keylocation properties define the relevant settings. All three pools were created with ashift=12 (4 KiB) and aes-256-gcm encryption. For passpool and despasspool we set keyformat=passphrase and keylocation=prompt; for keypool we set keyformat=raw and keylocation=file:///root/zfs-keys/keypool.key. A raw ZFS key is 32 bytes long; its contents are not shown in the screenshots. The zpool list command reported each test pool as ONLINE with a size of 17.5G.

FreeBSD terminal: creation of three pools with aes-256-gcm, ashift=12 and passphrase or raw keys
The creation commands and zpool list output confirm the initial encryption settings.

We populated all three pools with test files in several formats: BMP, JPG, PNG, DOCX, XLSX, MP4, RAR and ZIP, including nested directories. Thunar shows confirmation of permanent deletion of 16 selected files from the General directory on passpool. The other pools were prepared similarly. The following three data loss scenarios were tested:

Thunar: confirmation of permanent deletion of 16 selected files in /passpool/General
This laboratory operation simulates the loss of some data from an intact pool.
PoolUnlock methodState after data loss
passpoolPassphraseSome files deleted, pool exported, GPT partition intact.
keypoolKey fileSome files deleted, pool exported, GPT partition intact.
despasspoolDifferent passphraseSome files deleted, pool destroyed, partition entry removed from GPT.

The first two pools were exported immediately after file deletion. In the lab, the third was destroyed with zpool destroy despasspool, then its partition was removed from the GPT.

Pool destruction and partition deletion were performed solely to simulate data loss on a test disk. Do not repeat these operations on a drive from which you need to recover data.

FreeBSD Control Panel: mfid1p3 deleted, two 18 GB partitions and 19 GB of free space
After deletion of the third partition, no GPT entry describes its area.

For recovery we used a Windows 10 virtual machine on the same server, running under bhyve and managed with bhyvemgr. The Windows system virtual disk resides on the server’s system drive, separate from the physical drive under examination.

Why you should stop writing to ZFS after deleting files

ZFS uses Copy-on-Write: modified blocks are written to new locations and references are then updated. Old blocks that are no longer in use may be freed and reused. Their temporary presence on the drive does not guarantee recovery.

Changes are batched into transaction groups (Transaction Groups, TXG). When the next group is committed, the new pool state is persisted on disk. The TXG number may increase when files are copied, edited or deleted, directories are created, items are renamed or permissions are changed. Background services can also write logs and temporary files.

Even reading a file may update its metadata: when the atime property is enabled, ZFS may write its last access time. The screenshot shows TXG values of 942 and 954 while working with passpool. The increase illustrates changes to the pool state, but does not prove that a particular deleted file was overwritten.

Thunar and FreeBSD terminal: TXG 942 and 954 in passpool
File activity changed the persisted pool state; this does not prove that a specific file was overwritten.

On SSDs and other discard-capable devices, freed blocks can become inaccessible after TRIM even without ordinary overwriting. Do not initiate TRIM or continue normal use of the pool. If the pool is already exported or destroyed, do not import it with write access merely to inspect it.

If a suitable backup or ZFS snapshot created before the deletion exists, it may be an easier source of data. Snapshot recovery is not demonstrated here: we analyze the on-disk structures directly.

Connecting a physical disk to Windows in bhyve

You can connect the drive directly to a computer, use a USB adapter or docking station, or work with a full disk image. Remote access over SSH requires support in the chosen software; SSH was not used in this test. Our method presents the entire physical drive to a virtual machine without removing it from the server.

First identify the correct drive by its parameters. Stop FreeBSD from accessing it: shut down applications and services using the relevant pools. In our test the intact pools were already exported. A normal export of an active pool may commit pending transactions, so for critical data first assess how to stop writes and create a copy safely.

Shut down the virtual machine. In bhyvemgr, find the directory containing its files and open bhyve_config.conf in a text editor.

Windows 10 configuration in bhyvemgr
The physical drive is added to an existing virtual machine separately from its system disk.

The added controller used PCI address 0.7.0 in our test. Choose a free address in your own configuration. For a SATA drive, specify an AHCI controller and an hd port type. Below is the actual configuration block added for port 0. In your own environment, replace /dev/mfid1 with the verified name of the entire target device, not an individual partition.

pci.0.7.0.device=ahci
pci.0.7.0.port.0.type=hd
pci.0.7.0.port.0.path=/dev/mfid1
pci.0.7.0.port.0.ro=true
pci.0.7.0.port.0.nodelete=true

The ro=true parameter prevents the guest system from writing to the source device, and nodelete=true disables emulation of TRIM/Discard requests from the guest. Presenting the entire drive allows the software to examine both the existing partitions and the area of the deleted GPT partition.

pci.0.7.0 block in bhyve_config.conf: /dev/mfid1, ro=true, nodelete=true
Presenting the entire device via AHCI restricts writes and discard from the guest.

These settings do not protect the drive from writes by the FreeBSD host itself. Do not allow simultaneous use of the source drive by the host. After starting Windows, decline any prompt to initialize or format the attached device.

How to recover files from encrypted ZFS pools

STEP 1. Detect the drive and lost partition

Launch Hetman Partition Recovery (version 5.4, Unlimited Edition, in the test) and find the connected drive. In our test it appears as BHYVE SATA DISK. The software lists it as Disk 5 (GPT), 55.38 GB. Inspect its properties and verify the size to avoid confusing it with the Windows system disk.

Hetman Partition Recovery 5.4: Disk 5, BHYVE SATA DISK, GPT, 55.38 GB
Capacity helps distinguish the test device from the Windows system disk and other attached drives.

The program detected two intact partitions containing passpool and keypool and automatically found the area of the former despasspool. Select each area and check its name, size and detected ZFS file system. The lost area is shown as Local Disk 0 (despasspool), 19.37 GB, with status Locked and path /dev/gpt/p3_pass. This is the size of the detected area, not the confirmed original partition size (18 GB).

Local Disk 0 (despasspool), ZFS, 19.37 GB, Locked, /dev/gpt/p3_pass
The software located the lost area without writing a partition entry back into GPT; its displayed size is not the original partition size.

Deleting the GPT entry and destroying the pool did not erase all its structures in this experiment. The remaining metadata allowed the software to recognize the area. Detecting the pool does not automatically grant access to encrypted contents: the corresponding key is required.

STEP 2. Unlock ZFS with a passphrase and find deleted files

Double-click passpool. In the Unlock Disk window, enter the passphrase used for its encrypted dataset and click Unlock.

Unlock Disk dialog for passpool with passphrase entry
Access to encrypted contents requires the correct passphrase.

After unlocking, choose Fast scan. A fast scan uses the available file system structures to find files and directories.

Selecting Fast scan in Hetman Partition Recovery for ZFS
A fast scan is the first stage of data discovery in this test.

The discovered General directory displays both existing and previously deleted files. Deleted files are marked with a red cross. Preview the files you need before saving them. The results show thumbnails of previously deleted PNG, DOCX, XLSX and MP4 files, confirming access to their contents.

General directory in passpool: thumbnails of existing and deleted PNG, MP4, DOCX and XLSX files
Correct thumbnails confirm access to the contents of the corresponding deleted files after passphrase unlocking.

STEP 3. Unlock ZFS with a key file

For keypool, select Key file in the Unlock Disk dialog and specify the corresponding key file. In our test we had placed a copy in a folder accessible to Windows, outside the drive under examination. The screenshot shows keypool.key selected on the Windows desktop.

Selecting Key file to unlock keypool
The key file replaces manual passphrase entry.

Click Unlock and run Fast scan. When the scan finishes, open the discovered directories. In the test, existing and previously deleted files were also found on keypool, including correct thumbnails of PNG, DOCX, XLSX and MP4 files.

General directory in keypool: file thumbnails with and without red crosses
Unlocking with a raw key provided access to the contents of specific deleted files.

Keep a backup copy of the key separate from the encrypted drive and protect it from unauthorized access. Without the correct passphrase or another valid key, the software cannot decrypt the data. It does not bypass ZFS encryption.

STEP 4. Recover files after zpool destroy and GPT partition deletion

Open the automatically detected despasspool. Do not recreate the pool or restore the GPT on the source disk. Destroying a pool does not remove encryption from its data.

In the Unlock Disk dialog, enter the passphrase for this particular dataset (it differs from the passpool passphrase in our experiment) and click Unlock. Run Fast scan.

Unlock dialog for the detected despasspool
Valid decryption credentials are required even after the pool has been destroyed.

In the test, a fast scan was sufficient to find all test files from this pool. All discovered files are marked as deleted, including those that had not been individually deleted before the pool was destroyed. This reflects the loss of the original structure, not an individual deletion of every file.

General in Local Disk 0 (despasspool): files and a directory marked with red crosses
Even files without the deleted suffix that remained before pool destruction are marked Deleted.

If a fast scan does not find the required files, try Full analysis on a safe copy of the drive, selecting ZFS from the file system list. The wizard offers this option. It was not needed in our test. Full analysis cannot restore physically erased blocks or replace missing keys or critical encryption metadata.

STEP 5. Preview and save files

Inspect the discovered data in the preview pane. In the demonstration, we previewed several file types from despasspool: images, documents and videos. Expand the preview to full screen if necessary.

Preview of png_14mb.png in the detected despasspool
Displaying the photograph confirms access to the contents of a file that was present before the pool was destroyed.
Text preview of doc_24kb_deleted.docx in despasspool
Readable text confirms access to the contents of a previously deleted document.
Playback of a deleted MP4 in despasspool
The video frame and playback position at 00:12 confirm access to the contents of the selected MP4.

A file’s name, size and icon alone only confirm that its metadata was found. A correct thumbnail in Hetman Partition Recovery is generated from the actual contents of the discovered file and is strong evidence of recoverability, but does not establish byte-for-byte identity of all other files.

Select the files and folders you need and click Recovery. In the wizard, choose to save to disk, specify a destination folder on another physical drive, and start recovery.

Save to hard disk: path C:\Restored Files\, five selected files, 25.86 MB
The destination is the VM's system disk, separate from the device under examination.

Do not save the results to the source physical disk, even if another partition on it appears free. Writes can destroy data that could still be recovered.

After completion, open the destination folder and check the saved files in the appropriate applications. In the demonstration, five selected files (25.86 MB according to the wizard) were saved to C:\Restored Files on the VM’s system disk. File Explorer shows DOCX, JPG, PNG, RAR and XLSX files; a PNG image is also shown opening. This is not an integrity check of all five files.

Windows File Explorer: five recovered files in C:\Restored Files
DOCX, JPG, PNG, RAR and XLSX were exported, confirming that the selected files were saved, not the entire dataset.
Recovered PNG image open in Windows
After export, the image opens outside Hetman's preview window.

Test results and recovery limitations

In all three scenarios, Hetman Partition Recovery recognized the relevant ZFS areas, unlocked the encrypted datasets with the corresponding passphrases or key file and found files using Fast scan. Existing and deleted files were found in both intact pools; for the destroyed pool, files that had remained before its destruction were also found. The contents of selected files were checked in preview; the demonstration also saved five files from despasspool to the VM’s system disk and opened one of them in Windows.

Recovery depends on the survival of data blocks, file system and encryption metadata, the availability of the correct key, the volume of writes after data loss and the device’s TRIM behavior. The test did not establish a universal TXG limit or compare the entire set byte for byte with the originals. Recovering files is not the same as restoring the pool for normal operation.

Keep independent backups of your data and encryption keys. If files are lost, stop using the drive as soon as possible and perform the analysis without writing to the source.

Vladimir Artiukh

Author: , Technical Writer

Vladimir Artiukh is a technical writer for Hetman Software, as well as the voice and face of their English-speaking YouTube channel, Hetman Software: Data Recovery for Windows. He handles tutorials, how-tos, and detailed reviews on how the company’s tools work with all kinds of data storage devices.

Oleg Afonin

Editor: , Technical Writer

Oleg Afonin is an expert in mobile forensics, data recovery and computer systems. He often attends large data security conferences, and writes several blogs for such resources as xaker.ru, Elcomsoft and Habr. In addition to his online activities, Oleg’s articles are also published in professional magazines. Also, Oleg Afonin is the co-author of a well-known book, Mobile Forensics - Advanced Investigative Strategies.

Recommended For You