LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (http://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Detecting the CD drive (or other hardware) without udev? (http://www.linuxquestions.org/questions/linux-kernel-70/detecting-the-cd-drive-or-other-hardware-without-udev-538119/)

synx 03-16-2007 04:51 PM

Detecting the CD drive (or other hardware) without udev?
 
I'm learning how to make an initrd for a liveCD, and I'm running into a bootstrapping problem. udev is darned hard to set up, with many dependancies, and I'd like to do that later in the boot process after I've mounted the liveCD. But in order to access the liveCD in the first place, I need to detect which hardware is the CD drive, and which device is associated with it. In addition I need to know what drivers the computer may need to access this CD drive (i.e. if it's a SCSI drive on a strange host bus).

My plan is (was) to collect all the possible drivers I might need, then insmod them one by one, then rmmod the ones that failed. Once I insmod the right module, the kernel will report it has detected new CD hardware, and I can break out of the CD detection loop, and continue to prepare my root file system. I looked at Morphix's initrd, and briefly at the debian-installer's "detect-cd" script, and though it seemed like they were doing something like that, one thing kept eluding me.

How does the kernel report when it has detected new hardware, and that the hardware is a CD drive?

I'm pretty sure it has something to do with creating a /sbin/hotplug program, and once I insmod the right driver, the kernel will ...exec /sbin/hotplug? With informative device info in... environment variables? I can't find any documentation about hotplug though, except that it's important for enabling udev. I don't want to do udev though because at this stage I'm only in a temporary root, and I'll have the real root setup later, which udev can populate. One concern I have though is the possible race condition: if I insmod a module, how long do I pause the script before checking if a /dev/cdrom symlink has appeared? There seem to be programs for that waiting period related to udev, such as udevsettle. Is there any way I could make a temporary stripped down udev setup perhaps, just for detecting the cd drive?

After I've got the CD device, I was going to mount it on /static, and make a tmpfs filesystem on /dynamic, then unionfs both of them together, and use the unionfs as my real root. Then I can pull out udev, and run init, and the whole shebang to get the computer up and running, but before I have the CD device mounted on /static, all I want to do is detect the CD hardware with a minimum of auxiliary kernel modules needed to communicate with it.

synx 03-16-2007 10:31 PM

Well, here's what I've got so far. When I run
Code:

$ udevinfo -a -p $(udevinfo -q path -n /dev/hdd)
on my own CD/DVD drive (/dev/hdd), the first entry has no information whatsoever about the fact it's a CD drive. The "parent device" on the other hand, has ATTRS{media} of "cdrom". If I can match by the parent device then I can use that (and udev) to identify the hardware that are CD drives. It'd be nice if I could make them all /dev/cdrom/N : N=0-999 in case of multiple CD drives, then just loop through searching each for the right format and root filesystem. I don't see how to do that though, as udev .rules files don't seem to have any kind of loop or counter support.

Seems like a simplified udev configuration is the best way to do it, even in an initrd. Correct me if I'm wrong of course.


All times are GMT -5. The time now is 12:00 AM.