old-www/LDP/LG/issue29/nelson.html

216 lines
8.7 KiB
HTML

<!--startcut ==========================================================-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>Mastering Kernel Modules with Caldera LG#29</title>
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<!--endcut ============================================================-->
<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<h1><font color="maroon">Mastering Kernel Modules with Caldera</font></h1>
<H4>By <a href="mailto:nelson@er.doe.gov">David Nelson</a></H4>
</center>
<P> <HR> <P>
You shouldn't have to read this article. The concept of Linux kernel
modules is fairly simple. Unfortunately, information needed to compile,
install and use modules is scattered over several HOWTOs, READMEs,
and man pages. Plus, the files which need to be modified are in several
obscure directories.
<p>
I finally wrote this cookbook approach to get myself, and you, started.
Once you are up and running with modules, you can dig into the details
later. I tested this material on an X86 processor running Caldera Open
Linux 1.1, which is close to Red Hat 4.2. You mileage with other
processors and distributions may vary.
<p>
Why use modules? Modules let you compile a small, fast kernel, then
install and remove device drivers on demand. Without modules the Linux
kernel could bloat to resemble a certain commercial OS.
<p>
First, I recommend that you compile a base kernel
that includes all essential capabilities for your system without
modules. I know this sounds like we are going backwards, but you don't
want to lose the ability to boot up because you messed up your modules.
The README in usr/src/linux is your guide, but basically you execute
the command:
<pre>
make mrproper; make xconfig
</pre>
(or <tt>menuconfig</tt> or <tt>config</tt>) to include
all needed capabilities, then run:
<pre>
make dep; make clean; make zImage
</pre>
Save your kernel configuration to a file named kernelconf.base, in case you need to
recompile. The xconfig menu prompts you to save and load configuration
files. If you use menuconfig or config, the current configuration is in
the file /usr/src/linux/.config; copy that file to kernelconf.base. If you
configured too big a kernel, final compilation will fail. If this
happens, execute <tt>make&nbsp;bzImage</tt> instead of zImage.
Your compiled
kernel will be in the directory /usr/src/linux/arch/i386/boot.
<p>
You might have made a mistake in compiling your base kernel, so don't
throw away your old one. If you are running LILO, rename your new
kernel to zImage.base and copy it to the location of your current kernel,
usually / or /boot. Add a section to /etc/lilo.conf that lets you
select either your default or base kernel on boot up. My lilo.conf
is shown here minus some comment lines:
<pre>
# general section
boot = /dev/hda3
install = /boot/boot.b
message = /boot/message
prompt
timeout = 50
# default entry
image = /bzImage
label = linux
root = /dev/hda3
read-only
# base kernel
image = /zImage.base
label = base
root = /dev/hda3
read-only
</pre>
The important addition to lilo.conf is the last section
(<tt>#base&nbsp;kernel</tt>) which tells LILO about your new kernel.
Also, be sure lilo.conf
has <tt>prompt</tt> and <tt>timeout</tt> lines. Now execute
<tt>lilo</tt> and then reboot.
LILO will pause giving the prompt <tt>boot:</tt>. If you hit TAB, you will be
given the choices <tt>linux</tt> and <tt>base</tt>. Enter
<tt>base</tt>, and your new kernel will
boot. You may get complaining messages about bad module dependencies,
but if your base kernel is complete that shouldn't bother you. If
something goes wrong, reboot and enter <tt>linux</tt> (or just wait the
timeout interval) and your old kernel will boot. Make sure you have a
working base kernel before proceeding. With this approach you
never burn your bridges (or kernel) behind you.
<p>
If you don't use LILO, make a boot floppy for your base kernel. To do
this, insert a floppy and execute <tt>make&nbsp;zdisk</tt>, instead of zImage.
<p>
You are now ready to compile a kernel with modules tailored to your
system. Execute the same commands as above, but when you execute xconfig or
menuconfig pick some features to compile as modules. I suggest
you experiment first by picking nice-to-have, but not-necessary,
modules to add to zImage.base. Good choices might be printer support or
floppy support (unless you are booting from the floppy). Save your
configuration as kernelconf.mod in case you need to go back. Also,
write down which modules you are compiling. To know exactly which
modules are compiled, I suggest you move or delete your old modules (if
any). The Caldera release includes a lot of modules. They are in
/lib/modules/2.0.29. I moved my old ones into subdirectories rather
than deleting them in case I needed to back up. If you are working
with a different release of the kernel, instead of subdirectory 2.0.29
you will have a subdirectory corresponding to your release number.
<p>
After executing <tt>make&nbsp;zImage</tt>, run:
<pre>
make modules; make modules_install
</pre>
As before, move (using <b>cd</b>) to the directory containing zImage,
rename it zImage.mod and
move it to the directory where LILO will look for it. Put a new section at
the bottom of lilo.conf to let you boot this kernel with the label
<tt>modules</tt>. If you don't use LILO, make another zDisk.
<p>
Now, execute
<tt>depmod -aq</tt>. This creates /lib/modules/2.0.29/modules.dep, needed by
module utilities. Next, execute the following:
<pre>
modprobe -c | grep -v '^path' > /etc/conf.modules
</pre>
This command sets up another file needed by the module utilities.
<p>
Now reboot, choosing label <tt>modules</tt> at the boot prompt.
Next, move to the
/etc/modules/2.0.29 directory. It should contain a file with a very long name
like the following:
<pre>
#1 Tue Feb 11 20:36:48 MET 1997.default
</pre>
This file is read at boot time by /etc/rc.d/rc.modules. It contains a
list of the default modules loaded when the kernel boots. You
need to change both the name and the contents. Fixing the name is the hard
part. In directory /etc/modules/2.0.29 execute the commands:
<pre>
FILE=i`uname -v`.default
cp &quot;#1 Tue&quot;* &quot;$FILE&quot;
</pre>
This magic creates a file with the name that rc.modules will look for
on bootup. The name is based on the time when the kernel was compiled.
If you recompile the kernel, you must repeat the magic.
<p>
Edit this file to contain just the modules you want loaded at bootup.
For example, it might contain the lines
<pre>
floppy
lp
</pre>
which would load the floppy and printer modules, assuming you compiled
them as modules. To get your editor to accept this file, you may need to put
quotes around the name.
<p>
To load a module manually, execute
<tt>insmod&nbsp;'modname'</tt>. To remove it execute
<tt>rmmod&nbsp;'modname'</tt>. To tell which
modules are currently loaded, execute <tt>lsmod</tt>.
<p>
The best toy is <b>kerneld</b>; it automatically loads and unloads modules as
needed. Assume you have compiled the floppy driver as a module. Check
whether it is loaded by executing lsmod. If it is, remove it by
executing <tt>rmmod floppy</tt>. Then execute
<tt>kerneld</tt>.
Now execute <tt>mount&nbsp;/mnt/floppy</tt>
(or whatever mounts your floppy). Magically, kerneld
installs the floppy module when needed. It will also uninstall modules
which haven't been used for a while, keeping your kernel lean and mean.
<p>
You now know enough to experiment with modules without crashing your
kernel on bootup. Read the Module mini-HOWTO, the kerneld mini-HOWTO, and
the man pages for the utilities to become a real expert. Happy
moduling!
<p><HR> <P>
<h3>Resources</h3>
<p><HR> <P>
<A HREF="http://www.linuxresources.com/LDP/HOWTO/mini/Modules.html">
Module mini-HOWTO</A>
<p>
<A HREF="http://www.linuxresources.com/LDP/HOWTO/mini/Kerneld.html">
kerneld mini-HOWTO</A>
<!--===================================================================-->
<P> <hr> <P>
<center><H5>Copyright &copy; 1998, David Nelson <BR>
Published in Issue 29 of <i>Linux Gazette</i>, June 1998</H5></center>
<!--===================================================================-->
<P> <hr> <P>
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
ALT="[ FRONT PAGE ]"></A>
<A HREF="./prelz.html"><IMG SRC="../gx/back2.gif"
ALT=" Back "></A>
<A HREF="./coldiron.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
<P> <hr> <P>
<!--startcut ==========================================================-->
</BODY>
</HTML>
<!--endcut ============================================================-->