rhl52.htm
来自「linux的初学电子书」· HTM 代码 · 共 2,314 行 · 第 1/5 页
HTM
2,314 行
<HTML>
<HEAD>
<TITLE>Red Hat Linux Unleashed rhl52.htm </TITLE>
<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/htindex.htm">
<LINK REL="Next" HREF="rhl53.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl53.htm">
<LINK REL="Previous" HREF="rhl51.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl51.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<A NAME="I0"></A>
<H2>Red Hat Linux Unleashed rhl52.htm</H2>
<P ALIGN=LEFT>
<A HREF="rhl51.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl51.htm" TARGET="_self"><IMG SRC="purprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/index.htm" TARGET="_self"><IMG SRC="purtoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A>
<A HREF="rhl53.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhl53.htm" TARGET="_self"><IMG SRC="purnext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E401" >Upgrading and Installing New Kernel Software</A>
<LI>
<A HREF="#E68E402" >Compiling the Kernel from Source Code</A>
<LI>
<A HREF="#E68E403" >Adding Drivers to the Kernel</A>
<LI>
<A HREF="#E68E404" >Upgrading Libraries</A>
<LI>
<A HREF="#E68E405" >Developing Modules</A>
<LI>
<A HREF="#E68E406" >The Red Hat Live File System</A>
<LI>
<A HREF="#E68E407" >An Introduction to the Linux Source Tree</A>
<LI>
<A HREF="#E68E408" >A Brief Introduction to ELF</A>
<LI>
<A HREF="#E68E409" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E52"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>52</B></FONT></CENTER></H1>
<BR>
<A NAME="E67E52"></A>
<H2 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>Working with the Kernel</B></FONT></CENTER></H2>
<BR>
<P>This chapter will look at:
<BR>
<UL>
<LI>How to install and recompile the kernel of Linux
<BR>
<BR>
<LI>How to add new software to the kernel
<BR>
<BR>
<LI>How to install new versions of the shared libraries
<BR>
<BR>
<LI>The steps necessary to create a new Linux kernel
<BR>
<BR>
</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.
<BR>
<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.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>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 this chapter looks at only the basics.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<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.
<BR>
<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.
<BR>
<BR>
<A NAME="E68E401"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Upgrading and Installing New Kernel Software</B></FONT></CENTER></H3>
<BR>
<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.
<BR>
<P>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.
<BR>
<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.
<BR>
<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 versions of
the operating system, but there is a lot to be said for having a stable, functioning operating system.
<BR>
<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 five 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.
<BR>
<BR>
<A NAME="E68E402"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Compiling the Kernel from Source Code</B></FONT></CENTER></H3>
<BR>
<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.
<BR>
<P>Kernel sources for new releases of Linux are available from CD-ROM distributions, FTP sites (see <A HREF="rhlxa.htm" tppabs="http://202.113.16.101/%7eeb%7e/Red%20Hat%20Linux%20Unleashed/rhlxa.htm">Appendix A</A>, "Linux FTP Sites and Newsgroups"), 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.
<BR>
<P>Patch releases are sometimes numbered differently and do not require the entire source of the kernel to install. They just require 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.
<BR>
<P>Most kernel source programs are maintained as a gzipped tar file. Unpack the files into a subdirectory called /usr/src, 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 README file in one of the three /usr/src subdirectories, linux, linux-1.2.13, or redhat for more instructions.
<BR>
<P>Often, unpacking the gzipped tar file in /usr/src creates a subdirectory called /usr/src/linux, which can overwrite your last version of the kernel source. Before starting the unpacking process, rename or copy any existing /usr/src/linux (or whatever
name is used with the new kernel) so you have a backup version in case of problems.
<BR>
<P>After the kernel source has been unpacked, you need to create two symbolic links to the /usr/include directory, if they are not created already or set by the installation procedure. Usually, the link commands required are
<BR>
<PRE>
<FONT COLOR="#000080">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 /usr/src/linux. Without these links, the upgrade or installation of a new kernel cannot proceed.
<BR>
<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 gcc or g++ (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; occasionally, new kernel features are added that are not supported by older versions of gcc or g++.
<BR>
<P>Check the file /usr/src/linux/Makefile (or whatever path the Makefile is in with your source distribution). There will be a line in the file that defined the ROOT_DEV, which is the device that is used as the root file system when Linux boots. Usually
the line looks like this:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ROOT_DEV = CURRENT</FONT></PRE>
<P>If you have any other value, make sure it is correct for your file-system configuration. If the Makefile has no value, set it as shown in the preceding code line.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>It's a good idea to run make clean; make depend; make mrproper before rebuilding the kernel to make sure all old files are removed.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The compilation process begins when you change to the /usr/src/linux directory and issue the following command:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">make config</FONT></PRE>
<P>This command invokes the make 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.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE>Be sure that you are running either /bin/bash or /bin/sh before you run make. Running another shell such as tcsh may cause you problems with the make files.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>The config 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?)
<BR>
<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 command
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">make dep</FONT></PRE>
<P>If the software you are installing does not have a dep file, check with the release or installation notes to ensure that the dependencies are correctly handled by the other steps.
<BR>
<P>After that, you can finally compile the new kernel. The command to start the process is
<BR>
<PRE>
<FONT COLOR="#000080">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 /usr/src/linux). The make zdisk is really necessary for creating a boot disk, and therefore expects a blank, unformatted disk in the floppy drive and
will ask you for one as it runs. Not all releases or upgrades to the kernel support compressed image compilation.
<BR>
<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:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">cp Image /dev/fd0</FONT></PRE>
<P>To be safe, copy the old kernel to a known image and then copy the newly created image to the root. This would be accomplished with these two commands:
<BR>
<PRE>
<FONT COLOR="#000080">mv /vmlinuz /vmlinuz.oldcp /usr/src/linux/arch/i386/boot/zImage /vmlinuz</FONT></PRE>
<P>Now all that remains is to reboot the system and see if the new kernel loads properly. If there are any problems, boot from a floppy, restore the old kernel, and start the process again. Check the documentation supplied with the release source code for
any information about problems you may encounter or steps that may have been added to the process.
<BR>
<BR>
<A NAME="E68E403"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Adding Drivers to the Kernel</B></FONT></CENTER></H3>
<BR>
<P>You may want to link in new device drivers or special software to the kernel without going through the upgrade process of the kernel itself. This is often necessary when you add a new device to the system, such as a multiport board or an optical drive,
that should be loaded during the boot process. Alternatively, you may be adding special security software that must be linked into the kernel.
<BR>
<P>The add-in kernel software usually has installation instructions provided, but the general process is to locate the source in a directory that can be found by the kernel-recompilation process (such as the /usr/src directory). To instruct the make
utility to add the new code to the kernel, you often need to modify the Makefile. These modifications may be performed manually or by an installation script. Some software has its own Makefile supplied for this reason.
<BR>
<P>At this point, it's time to begin the kernel recompilation with the new software added into the load. The process is the same as shown in the preceding section; the kernel is installed in the boot location or set by LILO. Typically, the entire process
takes about 10 minutes and is quite trouble-free, unless the vendor of the kernel modification did a sloppy job. Make sure that the source code provided for the modification will work with your version of the Linux kernel by reading any text files that
accompany the code and software-compatibility files included with most distributions of Linux.
<BR>
<P>The latest version numbers to look for are found in the newsgroup discussions. To see the version of kernel source tree to build your kernel, use the command: uname -a. The version number of your kernel should be 1.2.13 or higher.
<BR>
<BR>
<A NAME="E68E404"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Upgrading Libraries</B></FONT></CENTER></H3>
<BR>
<P>Most of the software on a Linux system is set to use shared libraries (a set of subroutines used by many programs). When you see the message
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">Incompatible library version</FONT></PRE>
<P>displayed after you have performed an upgrade to the system and you try to execute a utility, it means that the libraries have been updated and need to be recompiled. Most libraries are backward compatible, so existing software should work properly even
after a library upgrade.
<BR>
<P>Library upgrades occur less frequently than kernel upgrades, and you can find them in the same places. There are usually documents that guide you to the latest version of a library, or there may be a file explaining which libraries are necessary with
new versions of the operating system kernel.
<BR>
<P>Most library upgrades are gzipped tar files, and the process for unpacking them is the same as for kernel source code—except that the target directories are usually /lib, /usr/lib, and /usr/include. Usually, any files that have the extension .a or
.aa go in the /usr/lib directory. Shared library image files, which have the format libc.so.version, are installed into /lib.
<BR>
<P>You may have to change symbolic links within the file system to point to the latest version of the library. For example, if you are running library version libc.so.4.4.1 and upgrade to libc.so.5.2.18, you must remove the old link and reset the symbolic
link set in /lib to this libc.so.5.2.18 file. The command is:
<BR>
<BR>
<PRE>
<FONT COLOR="#000080">ln -sf /lib/libc/so/4/4/1 /lib/libc.so.5.2.18</FONT></PRE>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?