📄 258-262.html
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Linux, Fourth Edition:Configuring the Linux Kernel</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0789717468//-->
<!--TITLE=Special Edition Using Linux, Fourth Edition//-->
<!--AUTHOR=Jack Tackett//-->
<!--AUTHOR=Jr.//-->
<!--AUTHOR=Steve Burnett//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Que//-->
<!--CHAPTER=13//-->
<!--PAGES=258-262//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="255-258.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="262-262.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Compiling the New Kernel</FONT></H3>
<P>After you answer the various questions to configure your new kernel, you must compile it. The following commands will build the new kernel:
</P>
<!-- CODE SNIP //-->
<PRE>
make dep
make clean
make
</PRE>
<!-- END CODE SNIP //-->
<P>The build process can take anywhere from a few minutes to many hours, depending on your hardware. So relax and order another pizza!
</P>
<P>When the compilation is complete, you need to set up your system to use the new kernel on boot. The new kernel is /usr/src/linux/arch/i386/boot/zImage, and you need to copy this image into the boot directory. But before that you should create a copy of your current kernel image, just in case something goes wrong. To save the old kernel use the following command:</P>
<!-- CODE SNIP //-->
<PRE>
mv /boot/vmlinuz.old /boot/vmlinuz.old
</PRE>
<!-- END CODE SNIP //-->
<P>Then you can copy over the new kernel with this command:
</P>
<!-- CODE SNIP //-->
<PRE>
cp /usr/src/linux/arch/i386/boot/zImage /boot/vmlinuz
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR>• <B>See</B> “Configuring LILO,” <B>p. 214</B><HR></FONT>
</BLOCKQUOTE>
<P>To change the default kernel that Linux boots into, you edit the /etc/lilo.conf file and add another entry for a new kernel. The example in Listing 13.1 shows the addition of the older kernel to the list of operating systems the machine can boot. To do this, you must rename /boot/vmlinuz to /boot/vmlinuz.old with the above commands and then change its label to “old” in lilo.conf as shown in Listing 13.1.
</P>
<P><B>Listing 13.1</B> A Sample /etc/lilo.conf File</P>
<!-- CODE //-->
<PRE>
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/vmlinuz
label=linux
initrd=/boot/initrd
root=/dev/hda1
read-only
image=/boot/vmlinuz.old
label=old
root=/dev/hda1
read-only
</PRE>
<!-- END CODE //-->
<P>After making the changes to /etc/lilo.conf, run the following command
</P>
<!-- CODE SNIP //-->
<PRE>
/sbin/lilo -v
</PRE>
<!-- END CODE SNIP //-->
<P>and the updated lilo will be written to the boot device. From then on when you reboot, the machine will boot into the new kernel (linux) as default instead of the older kernel, with a 50-second delay to give you time to choose the old kernel at the boot prompt if you want to boot that kernel.
</P>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">Building a Modularized Kernel</FONT></H3>
<P>With the introduction of modularization in the Linux 2.0.x kernel, there have been some significant changes in building customized kernels. In the past, you were required to compile support into your kernel if you wanted to access a particular hardware or filesystem component. For some hardware configurations, the size of the kernel could quickly reach a critical level, so to require ready support for items that were used only occasionally was an inefficient use of system resources. With the capabilities of the 2.0.x kernel, if certain hardware components or filesystems are used infrequently, driver modules for them can be loaded on demand. To see the current modules in use, use the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
lsmod
</PRE>
<!-- END CODE SNIP //-->
<P>The output, shown below, lets you know what modules are loaded and how they loaded, as well as how many pages of memory they are using:
</P>
<!-- CODE SNIP //-->
<PRE>
Module Pages Used by
isofs 5 1 (autoclean)
ne2k-pci 1 1 (autoclean)
8390 2 [ne2k-pci] 0 (autoclean)
BusLogic 20 4
</PRE>
<!-- END CODE SNIP //-->
<P>Only Red Hat Linux/Intel and Red Hat Linux/SPARC support modular kernels; Red Hat Linux/Alpha users must build a monolithic kernel as described in the earlier section “Building a New Kernel.” These instructions provide you with the knowledge required to take advantage of the power and flexibility available through kernel modularization.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>You need to have already installed the kernel-headers and kernel-source packages. Also, you must issue all commands from the /usr/src/linux directory.<HR></FONT>
</BLOCKQUOTE>
<P>To make the modules, go to /usr/src/linux and run the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
make modules
</PRE>
<!-- END CODE SNIP //-->
<P>Then use this command to install the modules run:
</P>
<!-- CODE SNIP //-->
<PRE>
make modules-install
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading9"></A><FONT COLOR="#000077">Working with Kernel Modules</FONT></H4>
<P>Now that you have compiled and installed the modules, you are ready to extend your kernel with loadable modules. Table 13.2 shows the basic commands that are available.
</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 13.2</B> Module Commands Available in Linux
<TR>
<TH WIDTH="25%" ALIGN="LEFT"><B>Command</B>
<TH ALIGN="LEFT"><B>Description</B>
<TR>
<TD COLSPAN="2"><HR>
<TR>
<TD><TT>lsmod</TT>
<TD>Lists the modules currently loaded in the kernel
<TR>
<TD><TT>insmod</TT>
<TD>Inserts a specified module into the kernel
<TR>
<TD><TT>rmmod</TT>
<TD>Removes the specified module from the kernel
<TR>
<TD><TT>depmod</TT>
<TD>Creates a dependency file for use by <TT>modprobe</TT>
<TR>
<TD><TT>modprobe</TT>
<TD>Loads modules from a list generated by <TT>depmod</TT>
</TABLE>
<P>If you are running X Windows, you can take advantage of the <TT>kerneld</TT> daemon from the Control Panel (shown in Figure 13.5) to work with modules from a GUI instead of from a command line. Clicking this button brings up the Kernel Configurator dialog box shown in Figure 13.6.</P>
<P><A NAME="Fig5"></A><A HREF="javascript:displayWindow('images/13-05.jpg',112,426 )"><IMG SRC="images/13-05t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/13-05.jpg',112,426)"><FONT COLOR="#000077"><B>FIG. 13.5</B></FONT></A> The <TT>kerneld</TT> menu button. The Control Panel provides access to many administrative functions, including working with <TT>kerneld</TT>.
</P>
<P><A NAME="Fig6"></A><A HREF="javascript:displayWindow('images/13-06.jpg',449,258 )"><IMG SRC="images/13-06t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/13-06.jpg',449,258)"><FONT COLOR="#000077"><B>FIG. 13.6</B></FONT></A> The Kernel Configurator dialog box. Working with kernel modules is easy with the X interface to <TT>kerneld</TT>.
</P>
<P>To list the currently loaded modules, use the <TT>lsmod</TT> command. To add a module you have compiled to the kernel, either you can use the following command</P>
<!-- CODE SNIP //-->
<PRE>
insmod module-name
</PRE>
<!-- END CODE SNIP //-->
<P>or you can click the Add button on the kerneld dialog box and specify the module (see Figure 13.7).
</P>
<P><A NAME="Fig7"></A><A HREF="javascript:displayWindow('images/13-07.jpg',248,102 )"><IMG SRC="images/13-07t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/13-07.jpg',248,102)"><FONT COLOR="#000077"><B>FIG. 13.7</B></FONT></A> The Choose Module Type dialog box. Adding modules is a breeze using X Windows.</P>
<P>To delete a module from the kernel, either use this command
</P>
<!-- CODE SNIP //-->
<PRE>
rmmod module-name
</PRE>
<!-- END CODE SNIP //-->
<P>or select the module from the list displayed in Figure 13.6 and click the Remove button.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading10"></A><FONT COLOR="#000077">Restarting <I>kerneld</I>
</FONT></H4>
<P>The changes you make with the Kernel Daemon Configuration tool will be made in the /etc/conf.modules file, which <TT>kerneld</TT> reads whenever it is started. Listing 13.2 provides a sample listing.</P>
<P><B>Listing 13.2</B> A Sample /etc/conf.modules File</P>
<!-- CODE SNIP //-->
<PRE>
alias scsi_hostadapter BusLogic
alias eth0 ne2k-pci
</PRE>
<!-- END CODE SNIP //-->
<P>To restart <TT>kerneld</TT>, you can use the tool shown in Figure 13.6 and click the Restart Kerneld button. You can also restart the daemon via the command line, as shown here:</P>
<!-- CODE SNIP //-->
<PRE>
/etc/rc.d/init.d/kerneld stop
/etc/rc.d/init.d/kerneld start
</PRE>
<!-- END CODE SNIP //-->
<P>Restarting <TT>kerneld</TT> does not cause any modules that are currently in use to be reloaded, but <TT>kerneld</TT> will use the configuration when it loads modules in the future.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="255-258.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="262-262.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -