Fix false assertion in dmu_tx_dirty_buf() on cloning
[zfs.git] / contrib / initramfs / zfsunlock
blobcf8e45249024e7d19510bc25600feae03a4e584d
1 #!/bin/sh
3 set -eu
4 if [ ! -e /run/zfs_fs_name ]; then
5 echo "Wait for the root pool to be imported or press Ctrl-C to exit."
6 fi
7 while [ ! -e /run/zfs_fs_name ]; do
8 if [ -e /run/zfs_unlock_complete ]; then
9 exit 0
11 sleep 1
12 done
13 echo
14 echo "Unlocking encrypted ZFS filesystems..."
15 echo "Enter the password or press Ctrl-C to exit."
16 echo
17 zfs_fs_name=""
18 if [ ! -e /run/zfs_unlock_complete_notify ]; then
19 mkfifo /run/zfs_unlock_complete_notify
21 while [ ! -e /run/zfs_unlock_complete ]; do
22 zfs_fs_name=$(cat /run/zfs_fs_name)
23 zfs_console_askpwd_cmd=$(cat /run/zfs_console_askpwd_cmd)
24 systemd-ask-password "Encrypted ZFS password for ${zfs_fs_name}:" | \
25 /sbin/zfs load-key "$zfs_fs_name" || true
26 if [ "$(/sbin/zfs get -H -ovalue keystatus "$zfs_fs_name" 2> /dev/null)" = "available" ]; then
27 echo "Password for $zfs_fs_name accepted."
28 zfs_console_askpwd_pid=$(ps | awk '!'"/awk/ && /$zfs_console_askpwd_cmd/ { print \$1; exit }")
29 if [ -n "$zfs_console_askpwd_pid" ]; then
30 kill "$zfs_console_askpwd_pid"
32 # Wait for another filesystem to unlock.
33 while [ "$(cat /run/zfs_fs_name)" = "$zfs_fs_name" ] && [ ! -e /run/zfs_unlock_complete ]; do
34 sleep 1
35 done
36 else
37 echo "Wrong password. Try again."
39 done
40 echo "Unlocking complete. Resuming boot sequence..."
41 echo "Please reconnect in a while."
42 echo "ok" > /run/zfs_unlock_complete_notify