On 2/24/12, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > You haven't said what you need. > > For example, suppose you're running an older kernel, and your init > script finds a bunch of USB devices and then exits. At that moment you > plug in a USB flash drive. Clearly the script will not have been able > to find it. How do you deal with that? > > There's still more to this. The "scan complete" message you mentioned > earlier gets printed when the SCSI layer has been told to scan the > device. But the SCSI layer can perform its scanning asynchronously, > and in particular, SCSI disks are always registered asynchronously. > Therefore the "scan complete" message doesn't mean that the attached > device has been fully scanned. > Yes I have said what I need. The 'init' script finds drives present at bootup. Any USB drive, usually when Puppy is booting off that drive, will be present. As I said, udev is used after switch_root, and anything plugged in after bootup is handled. I remember looking at another tiny Linux with a small initramfs that also did not use udev (or any variant) in the initramfs, and they just put in a big "sleep" to wait for, hopefully, the slowest USB drives. We wait until all USB drives are reported as found, and the "scan complete" for all of them. What we found is that the drives are discovered fairly promptly, but we have a suitable sleep to make sure all are found, then wait for the "scan complete" messages, but then wait for the drives to become ready. It works 100% on a huge range of hardware. If you are curious, here is the code. This runs as a parallel process to the main 'init' script: USBSTORAGES=0 ; CNTUSB=0 while [ $USBSTORAGES -eq 0 ];do sleep 1 echo -n "." > /dev/console CNTUSB=$(($CNTUSB+1)) [ $CNTUSB -gt 5 ] && break #v412 bug, ubuntu kernel, got duplicate 'device found at 2', need 'sort -u'... USBSTORAGES=`/bin/dmesg | grep "usb-storage: device found at" | sort -u | wc -l` [ $USBSTORAGES -eq 0 ] && break AVAILABLEUSBSTORAGES=`/bin/dmesg | grep "usb-storage: device scan complete" | wc -l` [ $USBSTORAGES -ne $AVAILABLEUSBSTORAGES ] && USBSTORAGES=0 done #i want this to work with kernel that does not have my usb-storage patch, feedback is that 3 secs is enough... while [ $CNTUSB -lt 3 ];do sleep 1 CNTUSB=$(($CNTUSB+1)) echo -en "\\033[1;33m.\\033[0;39m" >/dev/console #yellow dot done #wait for usb partitions to become available... #entries in /sys/block show up, but ex /sys/block/sda/sda1 takes a bit longer... #note, if usb card-reader plugged in but no cards inserted, this will timeout... #note, will also timeout if usb optical drive (sr), but ok, they need extra time... ALLUSBDRVS="`find /sys/block -maxdepth 1 -name 'sd*' -o -name 'sr*' | xargs -l readlink 2>/dev/null | grep '/usb[0-9]' | rev | cut -f 1 -d '/' | rev | tr '\n' ' '`" [ "$ALLUSBDRVS" = " " ] && ALLUSBDRVS="" for ONEDRV in $ALLUSBDRVS do while [ ! -e /sys/block/${ONEDRV}/${ONEDRV}1 ];do sleep 1 echo -en "\\033[1;31m.\\033[0;39m" >/dev/console #red dot CNTUSB=$(($CNTUSB+1)) [ $CNTUSB -gt 6 ] && break done #force update of /proc/partitions... dd if=/dev/${ONEDRV} of=/dev/null bs=512 count=1 >/dev/null 2>&1 done Regards, Barry Kauler -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html