⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch56.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 4 页
字号:


<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>

 -->










<font face="Arial,Helvetica" size="-1" color="#006666">

<b>Linux</b></font><p>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">











 

























<UL>



	<LI><A HREF="#Heading1">- 56 -</A>



	<UL>



		<LI><A HREF="#Heading2">Working with the Kernel</A>



		<UL>



			<LI><A HREF="#Heading3">WARNING</A>



			<LI><A HREF="#Heading4">Upgrading and Installing New Kernel Software</A>



			<LI><A HREF="#Heading5">CAUTION</A>



			<LI><A HREF="#Heading6">Compiling the Kernel from Source Code</A>



			<LI><A HREF="#Heading7">Adding Drivers to the Kernel</A>



			<LI><A HREF="#Heading8">Upgrading Libraries</A>



			<LI><A HREF="#Heading9">An Introduction to the Linux Source Tree</A>



			<LI><A HREF="#Heading10">Making Loadable Modules for Linux</A>



			<LI><A HREF="#Heading11">The rc.modules File</A>



			<LI><A HREF="#Heading12">Summary</A>



		</UL>



	</UL>



</UL>







<P>



<HR SIZE="4">







<H2 ALIGN="CENTER"><A NAME="Heading1<FONT COLOR="#000077">- 56 -</FONT></H2>



<H2 ALIGN="CENTER"><A NAME="Heading2<FONT COLOR="#000077">Working with the



Kernel</FONT></H2>



<P><I>by Kamran Husain and Tim Parker</I></P>



<P>IN THIS CHAPTER</P>







<UL>



	<LI>Upgrading and Installing New Kernel Software 



	<P>



	<LI>Compiling the Kernel from Source Code 



	<P>



	<LI>Adding Drivers to the Kernel 



	<P>



	<LI>Upgrading Libraries 



	<P>



	<LI>An Introduction to the Linux Source Tree 



	<P>



	<LI>Making Loadable Modules for Linux 



	<P>



	<LI>The rc.modules File 



</UL>







<P>This chapter will look at







<UL>



	<LI>How to install and recompile the kernel of Linux



	<P>



	<LI>How to add new software to the kernel



	<P>



	<LI>How to install new versions of the shared libraries



	<P>



	<LI>The steps necessary to create a new Linux kernel



	<P>



	<LI>How to use the kernel source files



	<P>



	<LI>Using dynamic modules



	<P>



	<LI>An introduction to the ELF format



</UL>







<P>Usually, you will want to leave the kernel alone, except when you are performing



a major upgrade or installing a new device driver that has special kernel modifications.



The details of the process are usually supplied with the software. However, this



chapter gives you a good idea of the general process.</P>



<P>Few people will want to change the details in the kernel source code, because



they lack the knowledge to do so (or have enough knowledge to know that hacking the



kernel can severely damage the system). However, most users will want to install



new versions of Linux, add patches, or modify the kernel's behavior a little.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading3<FONT COLOR="#000077"><B>WARNING: </B></FONT>Don't modify



	the kernel unless you know what you are doing. If you damage the source code, your



	kernel may be unusable, and in the worst cases, your file system may be affected.



	Take care and follow instructions carefully. You need to know several things about



	kernel manipulation, and we can only look at the basics in this chapter.



<HR>







</DL>







<P>Several versions of Linux are commonly used, with a few inconsistencies between



them. For that reason, the exact instructions given here may not work with your version



of Linux. However, the general approach is the same, and only the directory or utility



names may be different. Most versions of Linux supply documentation that lists the



recompilation process and the locations of the source code and compiled programs.</P>







<P>Before you do anything with the kernel or utilities, make sure you have a good



set of emergency boot disks, and preferably a complete backup on tape or diskette.



Although the process of modifying the kernel is not difficult, every now and then



it does cause problems that can leave you stranded without a working system. Boot



disks are the best way to recover, so make at least one extra set.



<H3 ALIGN="CENTER"><A NAME="Heading4<FONT COLOR="#000077">Upgrading and Installing



New Kernel Software</FONT></H3>



<P>Linux is a dynamic operating system. New releases of the kernel, or parts of the



operating system that can be linked into the kernel, are made available at regular



intervals to users. Whether or not you want to upgrade to the new releases is up



to you and usually depends on the features or bug fixes that the new release offers.



You will probably have to recompile and relink the kernel when new software is added,



unless it is loaded as a utility or device driver.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading5<FONT COLOR="#000077"><B>CAUTION:</B> </FONT>You should avoid



	upgrading your system with every new release for a couple of reasons. The most common



	problem with constant upgrades is that you may be stuck with a new software package



	that causes backward compatibility problems with your existing system or that has



	a major problem with it that was not patched before the new software was released.



	This can cause you no end of trouble. Most new software releases wipe out existing



	configuration information, so you have to reconfigure the packages that are being



	installed from scratch.



<HR>







</DL>







<P>Another problem with constant upgrades is that the frequency with which new releases



are made available is so high that you can probably spend more time simply loading



and recompiling kernels and utilities than actually using the system. This becomes



tiresome after a while. Because most major releases of the Linux operating system



are available, the number of changes to the system is usually quite small. Therefore,



you should read the release notes carefully to ensure that the release is worth the



installation time and trouble.</P>







<P>The best advice is to upgrade only once or twice a year, and only when there is



a new feature or enhancement to your system that will make a significant difference



in the way you use Linux. It's tempting to always have the latest and newest version



of the operating system, but there is a lot to be said for having a stable, functioning



operating system, too.</P>



<P>If you do upgrade to a new release, bear in mind that you don't have to upgrade



everything. The last few Linux releases have changed only about 5 percent of the



operating system with each new major package upgrade. Instead of replacing the entire



system, just install those parts that will have a definite effect, such as the kernel,



compilers and their libraries, and frequently used utilities. This saves time and



reconfiguration.



<H3 ALIGN="CENTER"><A NAME="Heading6<FONT COLOR="#000077">Compiling the Kernel



from Source Code</FONT></H3>



<P>Upgrading, replacing, or adding new code to the kernel is usually a simple process:



You obtain the source for the kernel, make any configuration changes, compile it,



and then place it in the proper location on the file system to run the system properly.



The process is often automated for you by a shell script or installation program,



and some upgrades are completely automated--you don't need to do anything except



start the upgrade utility.</P>



<P>Kernel sources for new releases of Linux are available from CD-ROM distributions,



FTP sites (see Appendix A, &quot;FTP Sites and Newsgroups&quot;), user groups, and



many other locations. Most kernel versions are numbered with a version and a patch



level, so you will see kernel names such as 1.12.123, where 1 is the major release,



12 is the minor version release, and 123 is the patch number. Most sites of kernel



source code maintain several versions simultaneously, so check through the source



directories for the latest version of the kernel.</P>



<P>Patch releases are sometimes numbered differently and do not require the entire



source of the kernel to install. They require just the source of the patch. In most



cases, the patch overlays a section of existing source code and a simple recompilation



is all that's necessary to install the patch. Patches are released quite frequently.</P>



<P>Most kernel source programs are maintained as a gzipped <TT>tar</TT> file. Unpack



the files into a subdirectory called <TT>/usr/src</TT>, which is where most of the



source code is kept for Linux. Some versions of Linux keep other directories for



the kernel source, so you may want to check any documentation supplied with the system



or look for a <TT>README</TT> file in the <TT>/usr/src</TT> directory for more instructions.</P>



<P>Often, unpacking the gzipped <TT>tar</TT> file in <TT>/usr/src</TT> creates a



subdirectory called <TT>/usr/src/linux</TT>, which can overwrite your last version



of the kernel source. Before starting the unpacking process, rename or copy any existing



<TT>/usr/src/linux</TT> (or whatever name is used with the new kernel) so you have



a backup version in case of problems.</P>



<P>After the kernel source has been unpacked, you need to create two symbolic links



to the <TT>/usr/include</TT> directory, if they are not created already or set by



the installation procedure. Usually, the link commands required are<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">ln -sf /usr/src/linux/include/linux /usr/include/linux



ln -sf /usr/src/linux/include/asm /usr/include/asm



</FONT></PRE>



<P>If the directory names shown are different from your version of Linux, substitute



the new directory names for <TT>/usr/src/linux</TT>. Without these links, the upgrade



or installation of a new kernel cannot proceed.</P>



<P>After the source code has been ungzipped and untarred and the links have been



established, the compilation process can begin. You must have a version of <TT>gcc</TT>



or <TT>g++</TT> (the GNU C and C++ compilers) or some other compatible compiler available



for the compilation. You may have to check with the source code documentation to



make sure you have the correct versions of the compilers, because occasionally new



kernel features are added that are not supported by older versions of <TT>gcc</TT>



or <TT>g++</TT>.</P>



<P>Check the file <TT>/usr/src/linux/Makefile</TT> (or whatever path the <TT>Makefile</TT>



is in with your source distribution). There will be a line in the file that defines



the <TT>ROOT_DEV</TT>, which is the device that is used as the <TT>root</TT> file



system when Linux boots. Usually the line looks like this:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">ROOT_DEV = CURRENT



</FONT></PRE>



<P>If you have any other value, make sure it is correct for your file system configuration.



If the <TT>Makefile</TT> has no value, set it as shown in the preceding code line.</P>



<P>The compilation process begins when you change to the <TT>/usr/src/linux</TT>



directory and issue the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">make config



</FONT></PRE>



<P>This command invokes the <TT>make</TT> utility for the C compiler. The process



may be slightly different for some versions of Linux, so you should check with any



release or installation notes supplied with the source code.</P>



<P>The <TT>config</TT> program issues a series of questions and prompts that you



need to answer to indicate any configuration issues that need to be completed before



the actual compilation begins. These may be about the type of disk drive you are



using, the CPU, any partitions, or other devices, such as CD-ROMs. Answer the questions



as well as you can. If you are unsure, choose the default values or the choice that



makes the most sense. The worst case is that you might have to redo the process if



the system doesn't run properly. (You do have an emergency boot disk ready, don't



you?)</P>



<P>Next, you have to set all the source dependencies. This is a step that is commonly



skipped, and it can cause several problems if it is not performed for each software



release. Issue the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">make dep



</FONT></PRE>



<P>If the software you are installing does not have a <TT>dep</TT> file, check with



the release or installation notes to ensure that the dependencies are correctly handled



by the other steps.</P>



<P>After that, you can finally compile the new kernel. The command to start the process



is<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">make zImage



make zdisk



make zlilo



</FONT></PRE>



<P>This compiles the source code and leaves the new kernel image file in the current



directory (usually <TT>/usr/src/linux</TT>). If you want to create a compressed kernel



image, you can use the command<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">make zImage



</FONT></PRE>



<P>Not all releases or upgrades to the kernel support compressed image compilation.</P>



<P>The last step in the process is to copy the new kernel image file to the boot



device or a boot floppy. Use the following command to place the file on a floppy:<FONT

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -