summaryrefslogtreecommitdiffstats
path: root/contrib/dracut/90zfs/mount-zfs.sh.in
diff options
context:
space:
mode:
authorMatthew Thode <[email protected]>2018-01-18 18:20:34 +0000
committerBrian Behlendorf <[email protected]>2018-01-18 10:20:34 -0800
commit7da8f8d81bf1fadc2d9dff10f0435fe601e919fa (patch)
treec7cfb694f5a0fbf8a9645863476d1445d0ebdbb0 /contrib/dracut/90zfs/mount-zfs.sh.in
parent79c3270476b7140220c7946dd0a709a31bb9ed1b (diff)
Run zfs load-key if needed in dracut
'zfs load-key -a' will only be called if needed. If a dataset not needed for boot does not have its key loaded (home directories for example) boot can still continue. zfs:AUTO was not working via dracut, so we still need the generator script to do its thing. Reviewed-by: Richard Yao <[email protected]> Reviewed-by: Manuel Amador (Rudd-O) <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: loli10K <[email protected]> Signed-off-by: Matthew Thode <[email protected]> Closes #6982 Closes #7004
Diffstat (limited to 'contrib/dracut/90zfs/mount-zfs.sh.in')
-rwxr-xr-xcontrib/dracut/90zfs/mount-zfs.sh.in27
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/dracut/90zfs/mount-zfs.sh.in b/contrib/dracut/90zfs/mount-zfs.sh.in
index e7f217736..36f07d667 100755
--- a/contrib/dracut/90zfs/mount-zfs.sh.in
+++ b/contrib/dracut/90zfs/mount-zfs.sh.in
@@ -56,6 +56,33 @@ ZFS_DATASET="${ZFS_DATASET:-${root#zfs:}}"
ZFS_POOL="${ZFS_DATASET%%/*}"
if import_pool "${ZFS_POOL}" ; then
+ # Load keys if we can or if we need to
+ if [ $(zpool list -H -o feature@encryption $(echo "${ZFS_POOL}" | awk -F\/ '{print $1}')) == 'active' ]; then
+ # if the root dataset has encryption enabled
+ if $(zfs list -H -o encryption "${ZFS_DATASET}" | grep -q -v off); then
+ # figure out where the root dataset has its key, the keylocation should not be none
+ while true; do
+ if [[ $(zfs list -H -o keylocation "${ZFS_DATASET}") == 'none' ]]; then
+ ZFS_DATASET=$(echo -n "${ZFS_DATASET}" | awk 'BEGIN{FS=OFS="/"}{NF--; print}')
+ if [[ "${ZFS_DATASET}" == '' ]]; then
+ rootok=0
+ break
+ fi
+ else
+ rootok=1
+ break
+ fi
+ done
+ [[ "${rootok}" -eq 0 ]]&& return 1
+ # decrypt them
+ TRY_COUNT=5
+ while [ $TRY_COUNT != 0 ]; do
+ zfs load-key "${ZFS_DATASET}"
+ [ $? == 0 ] && break
+ ((TRY_COUNT-=1))
+ done
+ fi
+ fi
# Let us tell the initrd to run on shutdown.
# We have a shutdown hook to run
# because we imported the pool.