📄 doc037.htm
字号:
<html><body><a href="doc038.html"><img src=../icons/next.gif alt="Next"></a><a href="doc000.html"><img src=../icons/up.gif alt="Up"></a><a href="doc036.html"><img src=../icons/previous.gif alt="Previous"></a><a href="doc000.html"><img src=../icons/contents.gif alt="Contents"></a><a href="doc123.html"><img src=../icons/index.gif alt="Index"></a><hr><h2><a name="s5.1">5.1 Building a Custom Kernel</a></h2><title>Building a Custom Kernel</title><a name="i87"><a name="i88"><p>With the introduction of modularization in the Linux 2.0.<em>x</em> kernelthere have been some significant changes in building customizedkernels. In the past you were required to compile support into yourkernel if you wanted to access a particular hardware or filesystemcomponent. For some hardware configurations the size of the kernelcould quickly reach a critical level. To require ready support foritems that were only occasionally used was an inefficient use of systemresources. With the capabilities of the 2.0.<em>x</em> kernel, if there arecertain hardware components or filesystems that are used infrequently,driver modules for them can be loaded on demand. For information onhandling kernel modules see Chapter <a href="doc057.html#s8">8</a>, Section<a href="doc063.html#s8.6">8.6</a>.<p><h3><a name="s5.1.1">5.1.1 Building a modularized kernel</a></h3><title>Building a modularized kernel</title><p>Only Red Hat Linux/Intel and Red Hat Linux/SPARC support modular kernels; Red Hat Linux/Alphausers must build a monolithic kernel (see Section <a href="doc037.html#s5.1.3">5.1.3</a>below).<p>These instructions provide you with the knowledge required to takeadvantage of the power and flexibility available through kernelmodularization. If you do not wish to take advantage ofmodularization, please see Section <a href="doc037.html#s5.1.3">5.1.3</a> for anexplanation of the different aspects of building and installing amonolithic kernel. It is assumed that you have already installed the<tt>kernel-headers</tt> and <tt>kernel-source</tt> packages and that youissue all commands from the <tt>usr/src/linux/</tt> directory.<p>It is important to begin a kernel build with the source tree in a knowncondition. Therefore, it is recommended that you begin with thecommand <tt>make mrproper</tt>. This will remove any configuration filesalong with the remains of any previous builds that may be scatteredaround the source tree. Now you must create a configuration file thatwill determine which components to include in your new kernel.Depending upon your hardware and personal preferences there are threemethods available to configure the kernel.<p><ul><p><li><tt>make config</tt> An interactive text program. Components arepresented and you answer with <tt>Y</tt> (yes), <tt>N</tt> (no), or <tt>M</tt>(module).<p><li><tt>make menuconfig</tt> A graphic, menu driven program. Components are presented in a menu of categories, you select the desired components in the same manner used in the Red Hat Linux installation program. Toggle the tag corresponding to the item you want included; <b>Y</b> (yes),<b>N</b> (no), or <b>M</b> (module).<p><li><tt>make xconfig</tt> An X Windows program. Components are listedin different levels of menus, components are selected using a mouse. Again, select <b>Y</b> (yes), <b>N</b> (no), or <b>M</b> (module).<p></ul><p><b>Please Note:</b> In order to use <tt>kerneld</tt> (see Section <a href="doc063.html#s8.6">8.6</a>for details) and kernel modules you must answer <b>Yes</b> to<b>kerneld support</b> and <b>module version(CONFIG_MODVERSIONS) support</b> in the configuration.<p><b>Please Note:</b> If you are building a Linux/Intel kernel on (or for) amachine that uses a ``clone'' processor (for example, one made by Cyrixor AMD), it is recommended to choose a <b>Processor type</b> of<b>386</b>.<a name="i89"><a name="i90"><a name="i91"><a name="i92"><a name="i93"><a name="i94"><p>If you wish to build a kernel with a configuration file(<tt>/usr/src/linux/.config</tt>) that you have already created with oneof the above methods, you can omit the <tt>make mrproper</tt> and<tt>make config</tt> commands and use the command <tt>make dep</tt> followedby <tt>make clean</tt> to prepare the source tree for the build.<p>The next step consists of the actual compilation of the source codecomponents into a working program that your machine can use to boot.The method described here is the easiest to recover from in the eventof a mishap. If you are interested in other possibilities details canbe found in the Kernel-HOWTO or in the <tt>Makefile</tt> in<tt>/usr/src/linux</tt> on your Linux system.<p><ul><p><li>Build the kernel with <tt>make boot</tt>.<p><li>Build any modules you configured with <tt>make modules</tt>.<p><li>Move the old set of modules out of the way with:<p><pre>rm -rf /lib/modules/2.0.29-oldmv /lib/modules/2.0.29 /lib/modules/2.0.29-old</pre><p>Of course, if you have upgraded your kernel, replace <tt>2.0.29</tt>with the version you are using.<p><li>Install the new modules (even if you didn't build any) with<tt>make modules_install</tt>.<p></ul><p>If you have a SCSI adapter and made your SCSI driver modular, build anew <tt>initrd</tt> image (see Section <a href="doc037.html#s5.1.2">5.1.2</a>). Note that thereare few practical reasons to make the SCSI driver modular in a customkernel.<p>In order to provide a redundant boot source to protect from a possible error in a new kernel you should keep the originalkernel available. Adding a kernel to the LILO menu is as simple asrenaming the original kernel in <tt>/boot</tt>, copying the new kernel to <tt>/boot</tt>, adding a few lines in <tt>/etc/lilo.conf</tt> and running <tt>/sbin/lilo</tt>. Here is an example of the default <tt>/etc/lilo.conf</tt> file shipped with Red Hat Linux:<blockquote><font size=-1><tt><pre>boot=/dev/hdamap=/boot/mapinstall=/boot/boot.bprompttimeout=100image=/boot/vmlinuz label=linux root=/dev/hda1 read-only</pre></tt></font></blockquote><p>Now you must update <tt>/etc/lilo.conf</tt>. If you built a new initrd image you must tell LILO to use it. In this example of <tt>/etc/lilo.conf</tt> we have added four lines at the bottom of the file to indicate another kernel to boot from. We have renamed <tt>/boot/vmlinuz</tt> to <tt>/boot/vmlinuz.old</tt>and changed its label to ``old''. We have also added an initrd line for the new kernel:<p><blockquote><font size=-1><tt><pre>boot=/dev/hdamap=/boot/mapinstall=/boot/boot.bprompttimeout=100image=/boot/vmlinuz label=linux initrd=/boot/initrd root=/dev/hda1 read-onlyimage=/boot/vmlinuz.old label=old root=/dev/hda1 read-only</pre></tt></font></blockquote><a name="i95"><p>Now when the system boots and you press <tt>[Tab]</tt> at the LILO<tt>boot:</tt> prompt two choices will be shown;<p><blockquote><font size=-1><tt><pre>LILO boot:linux old</pre></tt></font></blockquote><p>To boot the new kernel (<tt>linux</tt>) simply press <tt>[Enter]</tt>, or waitfor LILO to time out. If you want to boot the old kernel (<tt>old</tt>),simply enter <tt>old</tt> and press <tt>[Enter]</tt>.<p>Here is a summary of the steps;<ul><li><tt>mv /boot/vmlinuz /boot/vmlinuz.old</tt><li><tt>cp /usr/src/linux/arch/i386/boot/zImage /boot/vmlinuz</tt><li>edit <tt>/etc/lilo.conf</tt><li>run <tt>/sbin/lilo</tt></ul><p>You can begin testing your new kernel by rebooting your computer andwatching the messages to ensure your hardware is detected properly.<p><h3><a name="s5.1.2">5.1.2 Making an initrd image</a></h3><title>Making an initrd image</title><a name="i96">An <tt>initrd</tt> image is needed for loading your SCSI module at boottime. The shell script <tt>/sbin/mkinitrd</tt> can build a proper<tt>initrd</tt> image for your machine if the following conditions are met:<p><ul><p><li>The loopback block device is available.<p><li>The <tt>/etc/conf.modules</tt> file has a line for your SCSIadapter; for example: <p><pre>alias scsi_hostadapter BusLogic</pre><p></ul><p>To build the new <tt>initrd</tt> image, run <tt>/sbin/mkinitrd</tt>with parameters such as this:<p><blockquote><font size=-1><tt><pre> /sbin/mkinitrd /boot/newinitrd-image 2.0.12</pre></tt></font></blockquote><p>where <tt>/boot/newinitrd-image</tt> is the file to use for your newimage, and <tt>2.0.12</tt> is the kernel whose modules (from<tt>/lib/modules</tt>) should be used in the <tt>initrd</tt> image (notnecessarily the same as the version number of the currently runningkernel).<p><h3><a name="s5.1.3">5.1.3 Building a monolithic kernel</a></h3><title>Building a monolithic kernel</title><a name="i97"><p>To build a monolithic kernel you follow the same steps as building a modularized kernel with a few exceptions. <p><ul><p><li>When configuring the kernel only answer <b>Yes</b> and<b>No</b> to the questions (don't make anything modular).<p><li>Omit the steps: <p><pre>make modulesmake modules_install</pre><p><li>Edit the file <tt>/etc/rc.d/rc.sysinit</tt> and comment out theline <tt>depmod -a</tt> by inserting a ``#'' at the beginning of the line.<p></ul><p><p><hr><a href="doc038.html"><img src=../icons/next.gif alt="Next"></a><a href="doc000.html"><img src=../icons/up.gif alt="Up"></a><a href="doc036.html"><img src=../icons/previous.gif alt="Previous"></a><a href="doc000.html"><img src=../icons/contents.gif alt="Contents"></a><a href="doc123.html"><img src=../icons/index.gif alt="Index"></a><hr></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -