Detecting USB drives at bootup

I have been thinking about how Puppy does this, after I was asked recently about the need to patch file usb.c in 2.6.33+ kernels, for the 'init' script to properly detect USB drives.

The 'init' script in Puppy is able to determine all non-USB drives, which are written to ATADRIVES variable in /etc/rc.d/PUPSTATE.
Then, the init script loads usb_storage module, then waits for USB scanning to settle -- this is where I ran into a problem with 2.6.33+ kernels.

I wrote about the 2.6.33+ problem here:

There are two problems that I want to solve. Firstly, a way to determine which drives are USB, when usb_storage module is already loaded. If I can do this, then usb_storage could be built into the kernel. A bit of reasearch and I found out how:

I find that the layout in /sys keeps changing, so dredging through it gets broken with different kernel versions. However, the "udevadm info -p /sys/block/sdb --query=env" looks good.

Wait until USB drives are available. I still don't know how to do this, without patching usb.c and inserting the "device scan complete" etc. printk's.

I was reading about one distro, can't recall where, they just put in a sleep. Not at all satisfactory.

Posted on 3 Jun 2011, 18:55


Posted on 4 Jun 2011, 5:08 by Dougal
USB Devices
I just use:
case $(readlink /sys/block/$DEV) in */usb[0-9]/*) USBDRIVES="$USBDRIVES $DEV" ;; esac

Posted on 4 Jun 2011, 8:37 by BarryK
Yes, a simple solution.

Posted on 4 Jun 2011, 14:46 by Iguleder
Improved kernel build script
Barry - I'm working on an improved kernel build script. This time it's a Python script which generates the actual build script, to reduce the impact of the human factor even further.

It also comes with a patch that adds a Puppy logo in 224 colors, so people who use a capable framebuffer console should see it.

Another nice feature is support for Linux-libre: the script has a configuration file named "" with a boolean named "LINUX_LIBRE". If you put "True" there, the build script generator will automatically generate a build script which downloads the right Linux-libre scripts and deblobs your kernel.

Here's an example, for ... and this is the configuration file used. Looks pretty tidy!

Posted on 5 Jun 2011, 24:48 by linuxcbon
init structure
The init structure should be (if not mistaken) :
- mount filesystem
- make nodes
- local time
- udevd
- modprobes
- udevd
- loopback
- mount system
- hostname
- logs
- xwin

Posted on 6 Jun 2011, 8:31 by linuxcbon
init usb
I read that the modprobes needed for usb are in this order : usbcore, ehci_hcd, ohci_hcd, usbhid, usb_storage. So no need of waiting ?