Loading modules with cold plugged devices
Isaac Dunham
ibid.ag at gmail.com
Wed Sep 24 18:19:56 UTC 2014
On Wed, Sep 24, 2014 at 07:03:44PM +0200, Natanael Copa wrote:
> On Wed, 24 Sep 2014 14:15:10 +0200
> Luca Ellero <lroluk at gmail.com> wrote:
>
> > Hi,
> > I'm trying to load kernel modules at boot time (if needed) but I don't
> > manage to get it right.
> > My configuration is the following:
> > Pandaboard with U-Boot 2014.07, Linux kernel 3.16 and BusyBox 1.22.1
> >
> > I have an init script /etc/init.d/rcS like this:
> >
> > #!/bin/sh
> > mount -t proc none /proc
> > mount -t sysfs none /sys
> > echo /sbin/mdev > /proc/sys/kernel/hotplug
> > /sbin/mdev -s
> >
> > and a configuration file /etc/mdev.conf containing only the following line:
> >
> > $MODALIAS=.* 0:0 660 @modprobe "$MODALIAS"
> >
> > Modules are correctly loaded if I plug in a device while the system is
> > up and running.
> > For example if I plug-in an USB keyboard the correct module (usbhid) is
> > loaded.
> > But if the keyboard is "cold plugged" (when the system is off) and then
> > I power up the Pandaboard, the module isn't loaded.
> > Even executing "mdev -s" when the system is up doesn't load the module.
> > Doesn't "mdev -s" scan /sys entries and load modules (as mdev.conf
> > points), or am I missing something?
>
> No, it does not trigger hotplug events by scanning /sys.
>
> Alpine Linux does this:
> find /sys -name modalias | xargs sort -u \
> | xargs modprobe -a 2> /dev/null
>
On the Puppy Linux forums[1], it was pointed out that for some hardware,
there was a MODALIAS line in uevent but not a modalias file
(for example, this can miss some Broadcom wireless cards).
Also performance came up; the fastest way was something more like
grep -h MODALIAS /sys/bus/*/devices/*/uevent | \
cut -d= -f2 | xargs modprobe -abq 2>/dev/null
Not that it's really significant for most usage; on an Atom N270 at 1.6GHz,
I tested with echo instead of modprobe and got
0.22 seconds (consistently) for a shell script containing the more
Alpine-like version:
find /sys -name modalias |xargs sort -u |xargs echo
and 0.01-0.02 seconds for a shell script containing this version:
grep -h MODALIAS /sys/bus/*/devices/*/uevent | \
cut -d= -f2 |sort -u |xargs echo
HTH,
Isaac Dunham
[1] http://www.murga-linux.com/puppy/viewtopic.php?p=680067
More information about the busybox
mailing list