Extract initramfs data

June 23, 2026

When you need to access an encrypted ZFS system from rescue mode, you can extract the unlock scripts and keys from the initramfs:

#!/bin/bash
mkdir -p /mnt/temp
mount -L BOOT /mnt/temp
mkdir -p ~/temp
pushd ~/temp
xz -dc < $(ls -tr1 /mnt/temp/initramfs* | tail -n 1) | cpio -idmv
cp root/unlock.sh root/loop.crypt ~
popd
cryptsetup luksOpen ~/loop.crypt key
cat temp/root/unlock.sh | grep luksOpen | grep UUID | while read line; do bash -c "$line"; done
/sbin/zpool import -f -R /mnt/gentoo tank
umount /mnt/temp
mount -L BOOT /mnt/gentoo/boot
zpool status

This script mounts the boot partition, extracts the latest initramfs, retrieves the unlock script and encrypted keyfile, then uses them to open the LUKS volumes and import the ZFS pool.