From a2d50a10f7fc4a34e1ded95519fdb4536798e2a1 Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Tue, 14 Jan 2020 17:07:53 -0600 Subject: [PATCH] mount-usb: replace fixed timeout with drive detection Rather than wait a fixed 5s for the usb storage kernel modules to load, and the user to insert a drive, check for new USB drives inserted every 1s with a 5s timeout. Signed-off-by: Matt DeVillier --- initrd/bin/mount-usb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/initrd/bin/mount-usb b/initrd/bin/mount-usb index 94946675..0ac031cb 100755 --- a/initrd/bin/mount-usb +++ b/initrd/bin/mount-usb @@ -5,9 +5,16 @@ enable_usb if ! lsmod | grep -q usb_storage; then - insmod /lib/modules/usb-storage.ko \ + count=$(ls /dev/sd* 2>/dev/null | wc -l) + timeout=0 + echo "Scanning for USB storage devices..." + insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \ || die "usb_storage: module load failed" - sleep 5 + while [[ $count == $(ls /dev/sd* 2>/dev/null | wc -l) ]]; do + [[ $timeout -ge 4 ]] && break + sleep 1 + timeout=$(($timeout+1)) + done fi if [ ! -d /media ]; then