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.

- Test environment: three encrypted ZFS pools
- Why you should stop writing to ZFS after deleting files
- Connecting a physical disk to Windows in bhyve
- How to recover files from encrypted ZFS pools
- Test results and recovery limitations
- Frequently Asked Questions
- Comments
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.
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.

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.

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:

| Pool | Unlock method | State after data loss |
|---|---|---|
passpool | Passphrase | Some files deleted, pool exported, GPT partition intact. |
keypool | Key file | Some files deleted, pool exported, GPT partition intact. |
despasspool | Different passphrase | Some 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.

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.

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.

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.

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.

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).

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.

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

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.

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.

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.

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.

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.

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.



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.

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.


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.






