diff options
author | Michael Weiss <dev.primeos@gmail.com> | 2017-04-04 21:19:38 +0200 |
---|---|---|
committer | Michael Weiss <dev.primeos@gmail.com> | 2017-04-05 20:39:03 +0200 |
commit | a6420e13a2ed7a6dfe4463db5d92cd45b2bfa6a9 (patch) | |
tree | d944ad02e38f75a875b4f246bb4f2d0921ce9ad9 | |
parent | 2ba604f292b0f61247b6eab8ee20593a5899e610 (diff) |
luksroot: Wait for the header (device) to appear
The LUKS header can be on another device (e.g. a USB stick). In my case it can take up to two seconds until the partition on my USB stick is available (i.e. the decryption fails without this patch). This will also remove some redundancy by providing the shell function `wait_target` and slightly improve the output (one "." per second and a success/failure indication after 10 seconds instead of always printing "ok").
-rw-r--r-- | nixos/modules/system/boot/luksroot.nix | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/nixos/modules/system/boot/luksroot.nix b/nixos/modules/system/boot/luksroot.nix index 8978b73749b70..6e867b6743989 100644 --- a/nixos/modules/system/boot/luksroot.nix +++ b/nixos/modules/system/boot/luksroot.nix @@ -6,29 +6,38 @@ let luks = config.boot.initrd.luks; openCommand = name': { name, device, header, keyFile, keyFileSize, allowDiscards, yubikey, ... }: assert name' == name; '' - # Wait for luksRoot to appear, e.g. if on a usb drive. - # XXX: copied and adapted from stage-1-init.sh - should be - # available as a function. - if ! test -e ${device}; then - echo -n "waiting 10 seconds for device ${device} to appear..." - for try in $(seq 10); do - sleep 1 - if test -e ${device}; then break; fi - echo -n . - done - echo "ok" - fi + + # Wait for a target (e.g. device, keyFile, header, ...) to appear. + wait_target() { + local name="$1" + local target="$2" + + if [ ! -e $target ]; then + echo -n "Waiting 10 seconds for $name $target to appear" + local success=false; + for try in $(seq 10); do + echo -n "." + sleep 1 + if [ -e $target ]; then success=true break; fi + done + if [ $success = true ]; then + echo " - success"; + else + echo " - failure"; + fi + fi + } + + # Wait for luksRoot (and optionally keyFile and/or header) to appear, e.g. + # if on a USB drive. + wait_target "device" ${device} ${optionalString (keyFile != null) '' - if ! test -e ${keyFile}; then - echo -n "waiting 10 seconds for key file ${keyFile} to appear..." - for try in $(seq 10); do - sleep 1 - if test -e ${keyFile}; then break; fi - echo -n . - done - echo "ok" - fi + wait_target "key file" ${keyFile} + ''} + + ${optionalString (header != null) '' + wait_target "header" ${header} ''} open_normally() { |