Created
October 24, 2019 20:01
-
-
Save deviantintegral/abcae92a193c304289821461f8a9ce5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Place this in /etc/initramfs-tools/scripts/init-premount/zfs-unlock and | |
# run update-initramfs -u to include the script. | |
# | |
# This initramfs script handles mounting encrypted pools from a keyfile | |
# and not a passphrase. The main use case is keeping datasets encrypted so | |
# disks can be safely discarded if they partially fail and can't be easily | |
# wiped. | |
# | |
# The keyfile is placed on a USB key with the label KEYS, and is unmounted | |
# when done. | |
# | |
# root-on-zfs hasn't been tested yet. | |
# Change to the name of your pool. | |
POOL="pool" | |
PREREQ="udev zfs" | |
prereqs() | |
{ | |
echo "$PREREQ" | |
} | |
case $1 in | |
prereqs) | |
prereqs | |
exit 0 | |
;; | |
esac | |
. /scripts/functions | |
. /etc/zfs/zfs-functions | |
exec >/run/initramfs/initramfs-zfs.debug 2>&1 | |
set -x | |
# Custom content starts here. | |
# ------------ | |
# Source the default setup variables. | |
[ -r '/etc/default/zfs' ] && . /etc/default/zfs | |
# ------------ | |
# Support debug option | |
if grep -qiE '(^|[^\\](\\\\)* )(zfs_debug|zfs\.debug|zfsdebug)=(on|yes|1)( |$)' /proc/cmdline | |
then | |
ZFS_DEBUG=1 | |
mkdir /var/log | |
exec 2> /var/log/boot.debug | |
set -x | |
fi | |
# ------------ | |
# Load ZFS module etc. | |
if ! load_module_initrd; then | |
disable_plymouth | |
echo "" | |
echo "Failed to load ZFS modules." | |
/sbin/modprobe zfs || panic "modprobe zfs failed. Manually load the modules and exit." | |
fi | |
zfs_log_begin_msg "Mounting keys." | |
mkdir -p /media/keys | |
mount -o ro,umask=0377 /dev/disk/by-label/KEYS /media/keys | |
zfs_log_end_msg | |
zfs_log_begin_msg "Loading keys and pools..." | |
# Don't mount file systems to prevent locks when we pivot root. | |
zpool import -N $POOL || panic "zpool import failed." | |
zfs load-key -a || panic "zfs load-key import failed." | |
zfs_log_end_msg | |
umount /media/keys |
This was on Ubuntu 18.04 - I haven't upgraded that host to 20.04 yet. I also don't have root on zfs as I was waiting to upgrade to 20.04 to do that. That installer looks great, thanks for the link!
My suggestion would be to install first with a normal interactive passphrase, and then iterate on the above. Worst case is you have to do attended (re)boots until it's working. On 18.04 the original version of this script is at /usr/share/initramfs-tools/scripts/zfs
so it may be worth comparing that for any changes.
Yes it's a good alternative installer, you are welcome.
Thank you for your response and sorry for the late reply, I'll try your solution and iterate on it.
If I find a working solution I'll add a link here for reference.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @deviantintegral, I recently setup my home server with Ubuntu 20.04 (Server) with
/boot
and/
on ZFS.Root is encrypted (I've used this great tool saveriomiroddi/zfs-installer) and now I would like to automatically unlock the root pool using this tool.
Have you tested it with Ubuntu Server 20.04? If not on which distro did you use it?