I have been poking my nose around the init script and I have found a 'better' way to detect when the usb-storage module has identified the usb-storage devices, so that we can then proceed to mount them.
Basically we scan the dmesg output for the count of devices that are usb-storage, and the count of usbstorage devices that have been scanned, and wait for the number to be the same.
I have split the function into two components, because there is an enforced pause after loading usb-storage, it does a pause so that any device 'just plugged in' has time to 'spin up', in case it is a real hard disk.
To use them:
Code: Select all
usbstoragefunc
sleep 1
usbstoragefunc_completeion
Code: Select all
usbstoragefunc
insmod /lib/modules/${KERNVER}/cdrom.ko #before ide-cd.
insmod /lib/modules/${KERNVER}/ide-cd.ko
#might as well do this too...
insmod /lib/modules/${KERNVER}/sr_mod.ko
#ide zip or ide ls-120 drive?...
[ ! "`dmesg | grep "ATAPI FLOPPY"`" = "" ] && insmod /lib/modules/${KERNVER}/ide-floppy.ko
#I dunno why, a bit further down complains needs nls_cp437 and nls_iso8859-1.
insmod /lib/modules/${KERNVER}/nls_cp437.ko
insmod /lib/modules/${KERNVER}/nls_iso8859-1.ko
#filesystems...
[ -f /lib/modules/${KERNVER}/reiserfs.ko ] && insmod /lib/modules/${KERNVER}/reiserfs.ko
[ -f /lib/modules/${KERNVER}/ntfs.ko ] && insmod /lib/modules/${KERNVER}/ntfs.ko
#...my 2.6.16.7 has reiserfs and ntfs builtin, leave these lines for other kernels.
insmod /lib/modules/${KERNVER}/unionfs.ko
usbstoragefunc_completeion
Code: Select all
usbstoragefunc() {
if [ "$USB" ];then
#k2.6: annoying, lsmod reports usb-storage.ko as usb_storage if loaded...
if [ "`lsmod | grep "^usb_storage"`" = "" ];then
echo "USB-Storage: Loading usb-storage module"
insmod /lib/modules/${KERNVER}/usb-storage.ko &
echo "USB-Storage: Detecting connected device(s)..."
fi
fi
}
usbstoragefunc_completeion() {
if [ "$USB" ];then
#k2.6: annoying, lsmod reports usb-storage.ko as usb_storage if loaded...
if [ ! "`lsmod | grep "^usb_storage"`" = "" ];then
SLPCNT="0";
USBSTORAGES="0";
USBSTORAGESAVAILABLE="0";
while true;do
USBSTORAGES="`/bin/dmesg | grep -o "usb-storage: device found at.*" | wc -l | sed -e 's/ //g'`";
USBSTORAGESAVAILABLE="`/bin/dmesg | grep -o "usb-storage: device scan complete" | wc -l | sed -e 's/ //g'`";
if [ $USBSTORAGES -gt 0 ]; then
if [ $USBSTORAGES -eq $USBSTORAGESAVAILABLE ]; then
echo "USB-Storage: Device scan complete, found $USBSTORAGESAVAILABLE devices"
break
fi
fi
if [ $SLPCNT -gt 50 ]; then
echo "USB-Storage: Device scan time-out $SLPCNT secs, found $USBSTORAGESAVAILABLE of $USBSTORAGES device(s)."
break
fi
sleep 1
SLPCNT=`expr $SLPCNT + 1`
done
echo ""
fi
fi
}
Would anyone else like to give it a go?
Jesse