0071-0073.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 358 行
HTML
358 行
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Configuring and Building Kernels</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=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=05 //-->
<!-- PAGES=0053-0074 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0068-0070.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0074-0074.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-71"><P>Page 71</P></A>
<P>Before you begin, however, be prepared to wait. Depending on system speed, available
memory, and other processes, compiling the kernel can take from 10 minutes for a fast Pentium to
1.5 hours for a slow i386. The process will also slow down your system for other tasks. If you
are sharing CPU time with other people, you might want to wait until the CPU is less busy
before embarking on this task.
</P>
<P>The magic command to start the build is as follows:
</P>
<!-- CODE SNIP //-->
<PRE>
make dep;make clean;make zImage
</PRE>
<!-- END CODE SNIP //-->
<P>This line actually contains three commands in one. The first one,
make dep, actually takes your configuration and builds the corresponding dependency tree. This process determines
what gets compiled and what doesn't. The next step,
make clean, erases all previous traces of a compilation so as to avoid any mistakes in which version of a feature gets tied into the kernel. <BR>
Finally, make zImage does the full compilation. After the process is complete, the kernel is
compressed and ready to be installed.
</P>
<TABLE BGCOLOR=#FFFF99><TR><TD>NOTE</TD></TR><TR><TD>
<BLOCKQUOTE>
As the kernel compiles, all the commands necessary to do the actual compilation will
scroll down your screen. Although you don't need to understand the compilation process
in detail, having some background in C programming and
Makefiles is useful. Having this knowledge typically makes troubleshooting a little easier because the error messages
make more sense. If you do not have this sort of background, look out for messages such as
<BR>
<!-- CODE SNIP //-->
<PRE>
make:***[directory/file.o] Error 1
</PRE>
<!-- END CODE SNIP //-->
<BR><BR>
where [directory/file.o] is the file at which the compilation failed. Take note of the
first message starting with gcc after the preceding line. For example, if the output looks like
<BR>
<!-- CODE //-->
<PRE>
gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2
Â-fomit-frame-pointer -fno-strength-reduce -pipe -m486 -malign-loops=2
Â-malign-jumps=2 -malign-functions=2 -DCPU=586 -c -o init/main.o init/main.c
init/main.c:53: warning: function declaration isn't a prototype
init/main.c: In function `main':
init/main.c:53: storage class specified for parameter `_stext'
[...]
make:***[init/main.o] Error 1
</PRE>
<!-- END CODE //-->
<BR><BR>
you're interested in the line that says
<BR><BR>
<!-- CODE SNIP //-->
<PRE>init/main.c:53: warning function declaration isn't a prototype
</PRE>
<!-- END CODE SNIP //-->
<BR><BR>
Be sure to include this information when requesting
help.
</BLOCKQUOTE></TD></TR></TABLE>
<P>Before you can install the new kernel, you need to compile the corresponding modules.
You do so by using the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
make modules
</PRE>
<!-- END CODE SNIP //-->
<P>Again, watch for errors in the compilation.
</P>
<A NAME="PAGENUM-72"><P>Page 72</P></A>
<H3><A NAME="ch05_ 23">
Installing the Kernel
</A></H3>
<P>After the kernel and its corresponding modules are compiled, you're ready to start the
installation.
</P>
<P>Begin by checking the current /boot directory to see which kernels are presently installed.
Most kernels' filenames begin with the vmlinuz string, but if you aren't sure, check the
/etc/lilo.conf file to see which kernels are currently offered at boot time and their locations. (See Chapter
3 for additional information about LILO.)
</P>
<P>After you know what the current kernels are, copy the file
/usr/src/linux/arch/i386/boot/zImage from the kernel source tree to
/boot, and give it an appropriate new name. For
example, the sample kernel is the first kernel compiled with SCSI support in it, so you can use the
following copy command:
</P>
<!-- CODE SNIP //-->
<PRE>
cp /usr/src/linux/arch/i386/boot/zImage /boot/vmlinuz-2.0.30-scsi
</PRE>
<!-- END CODE SNIP //-->
<P>The unique name enables you to see easily why that kernel is different from the others.
</P>
<P>With the kernel in place, you're ready to start installing the appropriate kernel modules.
As you do with the kernel, you should make a backup of the existing modules before installing
the new ones.
</P>
<P>To make a backup of the current modules, go into the
/lib/modules directory and rename the current kernel version number to something else. For example, if the current version is
2.0.30, you can use the following:
</P>
<!-- CODE SNIP //-->
<PRE>
cd /lib/modules
mv 2.0.30 2.0.30-working
</PRE>
<!-- END CODE SNIP //-->
<P>This command renames the modules to
2.0.30-working so that, in the event the new
modules don't work as advertised, you can erase the new ones and rename this directory to
2.0.30 and regain control of the system.
</P>
<P>After you back up the modules, change back into the kernel source directory
and type
</P>
<!-- CODE SNIP //-->
<PRE>
make modules_install
</PRE>
<!-- END CODE SNIP //-->
<P>to install the modules into the
/lib/modules/version_number directory, where
version_number is the version number of the kernel you just compiled.
</P>
<P>Finally, you need to edit the /etc/lilo.conf file to make your new kernel one of the boot
time options. Do not remove the currently working kernel as an option! You will need it in case
the new kernel doesn't work the way you expect it to. Remember to rerun LILO after
making changes. Reboot and then test your results.
</P>
<A NAME="PAGENUM-73"><P>Page 73</P></A>
<TABLE BGCOLOR=#FFFF99><TR><TD>WARNING</TD></TR><TR><TD><BLOCKQUOTE>
When loading your kernel for the first time after a reboot, you might get the error that
the kernel is too large. This happens because the kernel is compressed during the
build procedure and then decompressed at boot time. Because of the nature of the Intel
architecture, the kernel must be able to decompress within the first 1MB of memory, and if it
can't, the system can't boot.
<BR>
If you receive the "Kernel is too large" message, reboot and choose your old
backup kernel to boot from.
<BR>
At this point you have two choices: You can either go reconfigure your kernel and
trim down unnecessary items by either not including them or using them as modules, or you
can use make bzImage to build a kernel that can work around the kernel
size limitation.
</BLOCKQUOTE></TD></TR></TABLE>
<H3>
Recovering from Faulty Kernels
</H3>
<P>While you're learning the nuances of the Linux kernel and its parameters, you might
make some mistakes and need to recover the system in its prior state. Having backed up your
kernels and modules (you did that, right?), this process is relatively easy.
</P>
<P>Begin by rebooting the system into single user mode. At the
lilo: prompt, select the previously working kernel to boot with the kernel parameter
single. As it boots up, you will notice errors as part of the process. Don't worry; the errors are caused by the mismatched modules
in the /lib/modules directory.
</P>
<P>After you log in, go to the /lib/modules directory and erase the current module
installation. For example, if you renamed your old modules
2.0.30-working and your new modules are 2.0.30, then use the following command:
</P>
<!-- CODE SNIP //-->
<PRE>
rm -rf 2.0.30
</PRE>
<!-- END CODE SNIP //-->
<P>Using this command removes all the current modules for the broken kernel. With the
broken programs gone, rename the stable kernel with its original name and reboot. This
procedure should give you full control of your system
again.
</P>
<H3><A NAME="ch05_ 24">
Summary
</A></H3>
<P>The kernel is the heart of Linux as well as one of its key features; other versions of UNIX
have kernels three to four times the size without three to four times the functionality. Of
course, this kernel provides the added benefit of the source code as well.
</P>
<P><CENTER>
<a href="0068-0070.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0074-0074.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?