summaryrefslogtreecommitdiff
path: root/init
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2017-04-27 17:51:59 -0600
committerAaron Ball <nullspoon@oper.io>2017-04-27 17:51:59 -0600
commitac6116c3bad1256ac1f85da7bbceb636833498d2 (patch)
treeca70d43075dec23aebc8b23825bc7bf9675255e9 /init
parent4355418cdd75371bedaf84a9fa41e56acd136060 (diff)
downloadmkinitramfs-ac6116c3bad1256ac1f85da7bbceb636833498d2.tar.gz
mkinitramfs-ac6116c3bad1256ac1f85da7bbceb636833498d2.tar.xz
Added wait_dev support
Previously, the device wait was hardcoded, regardless of device presence. Now we wait 10 seconds, but if the device is present early, the script can proceed before the threshold is reached. This should speed up boot time by a few seconds.
Diffstat (limited to 'init')
-rwxr-xr-xinit38
1 files changed, 35 insertions, 3 deletions
diff --git a/init b/init
index b0e2828..288f77b 100755
--- a/init
+++ b/init
@@ -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)"

Generated by cgit