diff options
-rwxr-xr-x | init | 38 |
1 files changed, 35 insertions, 3 deletions
@@ -114,6 +114,38 @@ function setup_encrypted { # +# Waits up to a threshold (in seconds) for the specified path to appear as a +# block device. A check for device presence occurs once per second. +# +# If the device appears within the threshold time, the function returns early +# with error code 0 (all is well - no need to wait more). +# +# If the block device fails to appear within the threshold time, the function +# returns code 2 (not found) +# +# @param dev Path to the device to wait for +# @param timeout Maximum time (in seconds) to wait for the device to appear +# +wait_dev() { + local dev=${1} + local timeout=${2} + + local wait=0 + + while [ ${wait} -lt ${timeout} ]; do + # If the path exists as a block device, exit the wait loop + [ -b "${dev}" ] && return 0 + # Increment the wait counter + wait=$(( wait + 1 )) + # Wait another second for the device to appear + sleep 1 + done + + return 2 +} + + +# # Main function to keep the main operations code nicely separated from the # rest. # @@ -140,11 +172,11 @@ function main { log "Root device: ${ROOTDEV}" - log "Waiting a few seconds for devices to settle." - sleep 2 + log "Waiting up to 10 seconds for root device to appear." + wait_dev "${ROOTDEV}" 10 # Drop to maintenance shell if root device does not exist. - if [[ ! -b ${ROOTDEV} ]]; then + if [[ $? -ne 0 ]]; then log "ERROR: Root device ${ROOTDEV} does not exist or can not be accessed." log " Dropping to maintenance shell for troubleshooting." log " (You may just need to wait longer for the root device)" |