forked from openzfs/zfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unlock encrypted root partition over SSH
This commit add a new feature for Debian-based distributions to unlock encrypted root partition over SSH. This feature is very handy on headless NAS or VPS cloud servers. To use this feature, you will need to install the dropbear-initramfs package. Reviewed-By: Brian Behlendorf <[email protected]> Reviewed-By: Tom Caputi <[email protected]> Signed-off-by: Andrey Prokopenko <[email protected]> Signed-off-by: Richard Laager <[email protected]> Closes openzfs#10027
- Loading branch information
Showing
8 changed files
with
92 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
zfs | ||
zfsunlock |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/sh | ||
|
||
PREREQ="dropbear" | ||
|
||
prereqs() { | ||
echo "$PREREQ" | ||
} | ||
|
||
case "$1" in | ||
prereqs) | ||
prereqs | ||
exit 0 | ||
;; | ||
esac | ||
|
||
. /usr/share/initramfs-tools/hook-functions | ||
|
||
copy_exec /usr/share/initramfs-tools/zfsunlock /usr/bin |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/bin/sh | ||
|
||
set -eu | ||
if [ ! -e /run/zfs_fs_name ]; then | ||
echo "Wait for the root pool to be imported or press Ctrl-C to exit." | ||
fi | ||
while [ ! -e /run/zfs_fs_name ]; do | ||
if [ -e /run/zfs_unlock_complete ]; then | ||
exit 0 | ||
fi | ||
sleep 0.5 | ||
done | ||
echo | ||
echo "Unlocking encrypted ZFS filesystems..." | ||
echo "Enter the password or press Ctrl-C to exit." | ||
echo | ||
zfs_fs_name="" | ||
if [ ! -e /run/zfs_unlock_complete_notify ]; then | ||
mkfifo /run/zfs_unlock_complete_notify | ||
fi | ||
while [ ! -e /run/zfs_unlock_complete ]; do | ||
zfs_fs_name=$(cat /run/zfs_fs_name) | ||
zfs_console_askpwd_cmd=$(cat /run/zfs_console_askpwd_cmd) | ||
systemd-ask-password "Encrypted ZFS password for ${zfs_fs_name}:" | \ | ||
/sbin/zfs load-key "$zfs_fs_name" || true | ||
if [ "$(/sbin/zfs get -H -ovalue keystatus "$zfs_fs_name" 2> /dev/null)" = "available" ]; then | ||
echo "Password for $zfs_fs_name accepted." | ||
zfs_console_askpwd_pid=$(ps a -o pid= -o args | grep -v grep | grep "$zfs_console_askpwd_cmd" | cut -d ' ' -f3 | sort -n | head -n1) | ||
if [ -n "$zfs_console_askpwd_pid" ]; then | ||
kill "$zfs_console_askpwd_pid" | ||
fi | ||
# Wait for another filesystem to unlock. | ||
while [ "$(cat /run/zfs_fs_name)" = "$zfs_fs_name" ] && [ ! -e /run/zfs_unlock_complete ]; do | ||
sleep 0.5 | ||
done | ||
else | ||
echo "Wrong password. Try again." | ||
fi | ||
done | ||
echo "Unlocking complete. Resuming boot sequence..." | ||
echo "Please reconnect in a while." | ||
echo "ok" > /run/zfs_unlock_complete_notify |