?? linux-kernel.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><TITLE>Josh's Linux Guide - Compiling a New Kernel</TITLE> <META NAME="Description" CONTENT="A Linux guide on compiling a new kernel from the viewpoint of a beginner."> <META NAME="Keywords" CONTENT="beginners, Linux, #LinuxHelp, Joshua, Go, kernel, new, Josh"></HEAD><LINK REL="stylesheet" TYPE="text/css" HREF="default.css"><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#7F007F"> <H2><A NAME="0">Compiling a New Kernel</A></H2><FONT SIZE="-1"><B>Created on: April 4, 1998</B></FONT><BR><FONT SIZE="-1"><B>Last Modified: April 20, 1999</B></FONT><BR><FONT SIZE="-1"><B>Development stage: Alpha</B></FONT><BR><P>The kernel is a file that is the most important part of any operatingsystem. The kernel sets up a basic interface between the hardware andsoftware. It's also what distinguishes Linux from other Unix operatingsystems. Most of what people think is Linux is actually from the FreeSoftware Foundation and other GNU authors. In addition to hardware, theLinux kernel is responsible for supporting protocols like TCP, IP, PPP,and all the filesystems out there.</P><P>Compiling the kernel should be one of the easiest things to do, but aswith most things dealing with Linux, there are problems people encounteralong the way. Let's just save that thought for later.</P><OL> <LI><A HREF="#dl">Downloading and Unpacking the Kernel Source</A> <UL> <LI><A HREF="#dl-dl">Download</A> <LI><A HREF="#dl-mirrors">Kernel.org Mirror Sites</A> <LI><A HREF="#dl-unpack">Unpacking the source</A> <LI><A HREF="#dl-patch">Patching</A> <LI><A HREF="#dl-depend">Checking Dependencies</A> </UL> <LI><A HREF="#compile">Compiling the Kernel</A> <UL> <LI><A HREF="#compile-configure">Configuring the Kernel</A> <LI><A HREF="#compile-compile">Compiling the Kernel</A> <LI><A HREF="#compile-notes">Notes on Compiliation</A> </UL> <LI><A HREF="#install-lilo">Installing LILO</A> <LI><A HREF="#notes">Various Authors' Notes</A></OL><H3><A NAME="1"><A NAME="dl">Downloading and Unpacking the Kernel Source</A></A></H3><P>This is the first (and arguably most frustrating) step in the kernelupgrade process.</P><H4><A NAME="2"><A NAME="dl-dl">Downloading the Kernel</A></A></H4><P>The latest Linux kernel can be downloaded from the following sites withthe file name <TT>linux-x.y.z.tar.gz</TT>, "x" is the"2" in <TT>linux-2.2.4</TT>, "y" is the "2",and "z" is the "4". When the "y" value isodd-numbered, as such in "2.1.109", it is a development kernel(like beta software, but less stable) and isn't considered to be stableenough for the average Linux user. If you're reading this document, you'reprobably much better off with a stable kernel. <EM>As of the writing ofthis document, there is no development tree. 2.2.x is your bestbet!</EM></P><H4><A NAME="3"><A NAME="dl-mirrors">Kernel.org Mirror Sites</A></A></H4><P>The Linux kernel source can be downloaded from the following sites.</P><UL> <LI><A HREF="ftp://ftp.kernel.org/pub/linux/kernel/v2.2/">kernel.org (ftp.kernel.org/pub/linux/kernel/v2.2/)</A> <LI><A TARGET="_top" HREF="ftp://sunsite.unc.edu/pub/Linux/kernel/v2.2/">Sunsite (sunsite.unc.edu/pub/Linux/kernel/v2.2/)</A> <LI>ftp://ftp.XX.kernel.org/, where XX is your ISO-country code (United Kingdom = ftp.uk.kernel.org; Canada = ftp.ca.kernel.org; Russia = ftp.ru.kernel.org; etc)</UL><P>Once you find the kernel you want to install, download it into thedirectory <TT>/usr/src/</TT>. This is a moderately large file (at least10MB as a gzip'd tarball for the 2.2.x kernel), so go do something elsewhile downloading it. Of course, if you've got a fast connection, then itwon't take as long to download. Generally you want the latest version ofthe latest stable kernel: currently 2.2.zz. Remember that ftp sites go inraw numerical order - <TT>linux-2.2.1.tar.gz</TT> comes before<TT>linux-2.2.12</TT> on the list, even though<TT>linux-2.2.12.tar.gz</TT> is newer. This should not be an issue forseveral months, as <TT>2.2.4</TT> is the current version (25mar1999).</P><H4><A NAME="4"><A NAME="dl-unpack">Unpacking the Kernel Sources</A></A></H4><P>When you're done downloading it, extract it with <TT>tar -zxvflinux-2.2.zz.tar.gz</TT>, where linux-2.2.zz.tar.gz is the file that youdownloaded. This will extract everything into the <tt>linux</tt>subdirectory. It might take a while, so be patient. If you have compiledthe kernel before (or installed any kernel header/source packages), youwill need to <tt>mv</tt> the old files out of the way before unpacking thekernel. Simply do <TT>mv linux/ linux-2.0.35/</TT>, or whatever versionof the kernel the headers/source is for.</P><H4><A NAME="5"><A NAME="dl-patch">Patching</A></A></H4><P>If you're downloading a new kernel and don't already have the sourcelying around, you can't patch yet. If you're downloading a kernel forthe first time, skip this subsection and go on to the next one.</P><P>It's such a big drag to download the entire kernel source tree everytime a new version comes out, so I recommend using patches. A patchcontains information on the differences between a previous version and thecurrent one. For example, if you have kernel 2.2.5 and want to upgrade to2.2.6, you need to get the patch that contains the differences between2.2.5 and 2.2.6.</P><P>Kernel patches have filenames such as <TT>patch-2.2.6.bz2</TT>. In thisexample, it's the patch to upgrade from 2.2.5 to 2.2.6. You shoulddownload patches into the <TT>/usr/src/linux/</TT> directory. Depending onwhat compression format you downloaded the patch in, you uncompress itdifferently. For bzip2, the compression format this patch uses, you usethe commandline <TT>bzcat patch-2.2.6.bz2 | patch -p1</TT>. If youdownloaded it in a gzipped format, you would type <TT>zcat patch-2.2.6.gz| patch -p1</TT>.</P><P>At first, the term <I>patch</I> gave me a connotation that this wasonly a quick fix. (I had a mental image of a piece of cloth sewed on tocover a hole on a jacket.) It's not really that. It's just something thatfixes the source tree accordingly.</P><H4><A NAME="6"><A NAME="dl-depend">Checking Dependencies</A></A></H4><P>When compiling and running the kernel, the system expects certainthings to be in place. For example, you need to have a compiler to getfrom the source code to a binary format the system can execute. You alsoneed the <TT>modutils</TT> if you plan on using modules, and<TT>autofs</TT> for automounting, etc. To know what the most recentversions are, see the file <TT>linux/Documentation/Changes</TT>. This filewill list what packages you need, what the base version is (lowest versionyou need to compile--it's usually a good idea to try out the newestversion of a given package), and where to get new copies of them. Thisfile also contains vast amounts of unneeded information. What you're mostinterested in is the table of most recent versions and the info on gettingnew versions.</P><P>Here's a sample of the most recent version chart (taken from Changesfor 2.2.3):</P><PRE>Current Minimal Requirements**************************** Upgrade to at *least* these software revisions before thinking you'veencountered a bug! If you're unsure what version you're currentlyrunning, the suggested command should tell you.- Kernel modules 2.1.121 ; insmod -V- Gnu C 2.7.2.3 ; gcc --version- Binutils 2.8.1.0.23 ; ld -v- Linux libc5 C Library 5.4.46 ; ls -l /lib/libc.so.*- Linux libc6 C Library 2.0.7pre6 ; ls -l /lib/libc.so.*- Dynamic Linker (ld.so) 1.9.9 ; ldd --version or ldd -v- Linux C++ Library 2.7.2.8 ; ls -l /usr/lib/libg++.so.*- Procps 1.2.9 ; ps --version- Procinfo 15 ; procinfo -v</PRE><P>Now, if you run a libc5 system (most older distributions), you will nothave a libc6. And some of these packages are entirely optional -- if youdon't currently have it, you probably don't need it, assuming your systemhas the ability to compile C programs.</P><P>So, you need to go through the list and double-check your dependencies. If something is old, look further down in Changes for itshomepage/distribution site. Let's say your Module utilities wereoutdated. You'd look further down in Changes and find the lines:</P><PRE>Modules utilities=================The 2.1.121 release:ftp://ftp.us.kernel.org/pub/linux/kernel/v2.1/modutils-2.1.121.tar.gz</PRE><P>Which, gives you the release number and a location to download themost recent version.</P><P>After you download the updated files, you will need to move them to anappropriate location (9 out of 10 hackers agree on <TT>/usr/local</TT> asa stuff-compiled-locally directory), and unpack them (<TT>tar xzffoobar-1.2.3.tar.gz</TT>). Most kernel packages are well-behaved and willuntar into their own subdirectory. <TT>cd</TT> into this directory and<EM>follow their instructions</EM>, usually found in INSTALL or README(<TT>less INSTALL</TT> or <TT>less README</TT>). If these directions fail, mail us. But not until you've read theinstructions. We'll probably grab the package and try installing itourselves, to see if it's broken or not.</P><P>You should now have your kernel downloaded, unpacked into<TT>/usr/src/linux</TT>, and all the things you need installed.</P><H3><A NAME="7">Compiling the Kernel</A></H3><P>Now that most of the hard work is taken care of, it's time tobegin the dull part!</P><P>Here is a basic outline of the kernel-compilation process:</P><UL><LI><TT>cd /usr/src/linux</TT> (just in case you're in the wrong directory)<LI><TT>make mrproper</TT><LI><TT>make menuconfig</TT> (If this doesn't work out, use <TT>make config</TT>)<LI><TT>make dep</TT><LI><TT>make clean</TT><LI><TT>make zImage (Usually the longest part of the process)</TT><LI><TT>make modules</TT><LI><TT>make modules_install</TT><LI><TT>cp arch/i386/boot/zImage /boot/vmlinuz-2.2.zz-new</TT><LI>(edit <TT>/etc/lilo.conf</TT>)<LI><TT>lilo</TT><LI><TT>reboot</TT> (no need to do it immediately but the new kernel won't be loaded until you reboot)</UL><P>I will not go into great detail about what every command above does; ifyou want to know, read the <AHREF="http://sunsite.unc.edu/LDP/HOWTO/Kernel-HOWTO.html"TARGET="_top">Linux Kernel HOWTO</A>.</P><P>Start by doing <TT>cd /usr/src/linux</TT> and <TT>make mrproper</TT>. These first two steps simply clean up any cruft that might haveaccidentally been left in the source tree by the development team. Thenread on.</P><H4><A NAME="8"><A NAME="compile-configure">Configuring the Kernel</A></A></H4><P>Like all other powerful software, the Linux kernel has to beconfigured. This is done during the <TT>make menuconfig</TT> step. <TT>make menuconfig</TT> starts an application that allows you to browsethrough the options available for the kernel and make settings. To movearound, use the arrow keys. Enter allows you to open up a menu, and tabgets you down to the "buttons" at the bottom. When you want a specificpart of the system compiled into the kernel, hit 'y' while it ishighlighted. If you realize that you don't need or don't want something,go back and hit 'n' over it. If you just want to try something out or useit occasionally, you can usually compile it as a module. All this (andmore) is documented in <TT>menuconfig</TT>'s docs.</P><P>While doing <TT>make menuconfig</TT>, a lot of the things that you haveto configure are pre-set, so if you don't know what it is, leave it alone.However, if you are pretty sure it won't hurt to disable support forsomething in the kernel, disable it, because the defaults are not alwaysright for everybody. I usually have to change the settings a little bit tokeep my kernel small.</P><P>If you use <TT>make menuconfig</TT>, you can hit "?" if you're not surewhat an option does. This will bring up a small amount of text describingthem, and usually a hint as to what the best option is if you don't knowwhat it is (some things don't have a ? screen, so you're best off to gowith the defaults on those if you're not sure what they do)</P><H4><A NAME="9"><A NAME="compile-compile">Compiling the Kernel</A></A></H4><P>After you finish configuring things, do <tt>make dep; make clean</TT>.This does a few technical things regarding dependencies and oldcompiliations lying around. 蛅's just something you need to do and need not worry about as to why.</P><P>Next, do <tt>make zImage</tt>. This may take a long time dependingon your system (on my K6-2-300/64M it takes about 10 minutes with Xrunning. On my friend's 386sx-16/8M it took several hours withnothing else running; on another friend's dual p100/48M it takes about14mins -jbm). Usually it's a good idea to watch it compile and keepan eye on possible warning messages. In particular, <tt>signal 11</tt>messages are Bad News. If you get any <tt>signal 11</tt>s, see the <AHREF="#compile-notes-sig11">note on sig11</A>. Another common problemis the kernel being too big. If your kernel is too big, try doing<tt>make bzImage</tt> after the <tt>make zImage</tt>. A<tt>zImage</TT> is a gzip'd kernel--it's compressed down to a moremanageble size, which makes booting a little slower. A<tt>bzImage</tt> is a bigger zImage kernel. (It still uses gzip.) I(jbm) have to use <tt>make bzImage</tt> because my kernel has gottentoo large for <tt>zImage</tt>. If you have use a <tt>bzImage</tt>,please replace the references to <tt>zImage</tt> with<tt>bzImage</tt>. It's a common problem and most people probably use<B><TT>make bzImage</TT></B> anyway these days.</P><P><tt>make modules; make modules_install</TT>: these compile and'install' any modules you selected. You will also need to set up the
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -