[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: three questions about modules



From: "Benjamin Black" <bhb8@columbia.edu>
To: <debian-user@lists.debian.org>
Sent: Sunday, April 22, 2001 1:50 AM
Subject: three questions about modules

>1.) the default behavior for debian seems to be to run modprobe on all
>modules listed in /etc/modules at boot time, without -k (autoclean).  is
>there a way to change this behavior?
>
>2.) i've looked through some of the kernel docs, but it seems that the
>only place i can find the names that the kernel uses to refer to
>devices, i.e. char-major-14 for sound, is in the documentation for each
>specific module, and most of the time it's not even listed there.  where
>can i find a list of all the names that the kernel uses for devices when
>it calls modprobe to load a module?

Device drivers in the Linux kernel are accessed through a pair of numbers
called the major and minor number.  The major number specifies which driver
should be used (each driver is accessed through a unique major number) - the
minor number specifies which instance/device is being accessed.

There is a kind of file called a device special file while associates a name
with a
major/minor number pair.  These device files are what (mostly) make up the
/dev
directory.  You can see the major/minor number pair associated with a device
special file in a long directory listing.  For example, the device special
files /dev/hda,
/dev/hda1, /dev/hda2 and /dev/hda3 are:

brw-rw----    1 root     disk       3,   0 Feb 23  1999 /dev/hda
brw-rw----    1 root     disk       3,   1 Feb 23  1999 /dev/hda1
brw-rw----    1 root     disk       3,   2 Feb 23  1999 /dev/hda2
brw-rw----    1 root     disk       3,   3 Feb 23  1999 /dev/hda3

These all have major number 3, and minor numbers 0 to 3 respectively.  There
are
actually two types of devices: character devices and block devices - the 'b'
in the first
column of the directory listing tells us that these refer to block devices.

Now, back to the aliases.  If a program tries to access a device major
number that the
kernel doesn't know how to handle (because there's no driver currently
loaded that
has registered with that major number), the kernel will construct a module
name according
to the pattern:

<type>-major-<major number>

and try to load that module.

For example, on my laptop I have the device special file:

crw-r--r--    1 root     root       161,   0 Feb 23  1999 /dev/ircommnew0

and the entry in /etc/modules.conf:

alias char-major-161 ircomm-tty

which means that if I try to access /dev/ircommnew0, the kernel will
automatically load
the ircomm-tty module if it's not already loaded.

That's _one_ way the kernel works out which module it should use to provide
a service - for
this method, the listing you're looking for is given by constructing the
appropriate name from
the data given by ls -l /dev.

There are other ways too - for example, if you try to bring up a network
interface that doesn't exist,
the kernel will try to load a module by that name.  That's why you add

alias eth0 <network card module name>

to your modules.conf - when you try to bring up eth0, it will load the
correct module for your network
card.

I hope that's a least a little illuminating.

>
>3.) i installed the kernel-image-2.4.3-686 package that was recently
>uploaded to unstable, and i'm perplexed.  my root partition uses ext2 as
>its filesystem, yet when i run lsmod, i see the ext2 module listed.  how
>is this possible?  does kernel 2.4 use some kind of voodoo magic that
>lets it read my kernel image off my root partition without knowing
>anything about the filesystem used to store it?  the only thing i can
>think of is that the new kernel package also uses an initrd image... is
>this how it is accomplishing this amazing feat, superior even to
>bootstrapping?  if so, please explain; i know nothing about initrd and
>what it does--the only thing i know about ramdisks is from my dos days
>when i could make a virtual drive out of ram and run programs super
>duper fast off of it.
>
>/ben
>

initrd allows a ramdisk to be created already initialised with data (from an
image file).  This means that you could have the ext2 module in the ramdisk
image, so that you can load it from the ramdisk, and then use it to mount
the
'real' root partition.

I'm not 100% on the way this works - I think the safest answer is "yes, it
_is_ voodoo".

    - Kevin.

>
>--
>|_    |_ | _  _ |_   PGP public key: http://www.wilykit.com/wilykit.key
>|_) . |_)|(_|(_ |\          "Never rub another man's rhubarb." -- Joker
>




Reply to: