From 606c29f0ecf20c53a3e8572b9ea7086fd7824a13 Mon Sep 17 00:00:00 2001 From: Jonathon Hall Date: Wed, 9 Nov 2022 14:02:03 -0500 Subject: [PATCH] Extract enable_usb_storage() from mount-usb enable_usb_storage() inserts usb-storage.ko if not already loaded, then waits for USB storage devices to appear. Signed-off-by: Jonathon Hall --- initrd/bin/mount-usb | 13 +------------ initrd/etc/functions | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/initrd/bin/mount-usb b/initrd/bin/mount-usb index 70b1c097..ea7abd3a 100755 --- a/initrd/bin/mount-usb +++ b/initrd/bin/mount-usb @@ -5,18 +5,7 @@ TRACE "Under /bin/mount-usb" enable_usb - -if ! lsmod | grep -q usb_storage; then - timeout=0 - echo "Scanning for USB storage devices..." - insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \ - || die "usb_storage: module load failed" - while [[ $(list_usb_storage | wc -l) -eq 0 ]]; do - [[ $timeout -ge 8 ]] && break - sleep 1 - timeout=$(($timeout+1)) - done -fi +enable_usb_storage if [ ! -d /media ]; then mkdir /media diff --git a/initrd/etc/functions b/initrd/etc/functions index aca6849f..007c2c1f 100755 --- a/initrd/etc/functions +++ b/initrd/etc/functions @@ -81,6 +81,24 @@ confirm_totp() echo } +# Enable USB storage (if not already enabled), and wait for storage devices to +# be detected. If USB storage was already enabled, no wait occurs, this would +# have happened already when USB storage was enabled. +enable_usb_storage() +{ + if ! lsmod | grep -q usb_storage; then + timeout=0 + echo "Scanning for USB storage devices..." + insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \ + || die "usb_storage: module load failed" + while [[ $(list_usb_storage | wc -l) -eq 0 ]]; do + [[ $timeout -ge 8 ]] && break + sleep 1 + timeout=$(($timeout+1)) + done + fi +} + list_usb_storage() { TRACE "Under /etc/functions:list_usb_storage"