site  contact  subhomenews

Detecting USB drives at bootup

June 03, 2011 — BarryK
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:
http://bkhome.org/archive/blog2/201002/2633-usb-drive-detection-problem.html

ONE
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:
http://stackoverflow.com/questions/3493858/linux-how-to-map-a-blockdevice-to-a-usb-device

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.

TWO
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.

Comments

USB Devices
Username: Dougal
I just use: case $(readlink /sys/block/$DEV) in */usb[0-9]/*) USBDRIVES="$USBDRIVES $DEV" ;; esac

Simple
Username: BarryK
"Dougal, Yes, a simple solution.

Improved kernel build script
Username: Iguleder
"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 "config.py" 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. [url=http://pastebin.com/RZhMhx4C]Here[/url]'s an example, for 2.6.32.41 ... and [url=http://pastebin.com/cBxa1BB2]this[/url] is the configuration file used. Looks pretty tidy!

init structure
Username: linuxcbon
"The init structure should be (if not mistaken) : - mount filesystem - make nodes - local time - udevd - modprobes - udevd - loopback - mount system - hostname - logs - xwin


Tags: woof