Requirements
Well, in order to compile your Linux Kernel, you need at least the following: (already included and updated on most distros)
Hardware
Therefore, the next step is to determine your current hardware, using a terminal move to your home directory (or wherever you wish to save hardware data) and type:
$ lspci > hardware.log
Then we need to have information about our CPU, again, type:
$ cat /proc/cpuinfo > cpuinfo.log
You'll have 2 files now, hardware.log and cpuinfo.log... what for? In order to respond correctly (no, it's not a test, just a cfg file !) some kernel configuration questions in order to tune your machine correctly, this info will come in handy specially when configuring NIC, soundcard, built-in components, etc...
Download kernel source...
We have a bifurcation here and all depends the road you'll take, you candownload a source from your distribution (already packed with all distro hacks,specific hardware support, etc...) or download a "pristine" kernel (community developed, large hardware support, experimental code, etc...). I'll prefer a pristine rathen than a distro pack, if you wish stability and support from your distro then take that way and please READ your distro kernel docs.
Staying with "pristine"? Well, the best place to download the kernel source is athttp://www.kenel.org, but please be generous and use a mirror near you, mirrors shown at http://www.kenel.org/mirrors. Choose a 2.6.x "tar.bz2" tarball and wait (it should not take more than 15 min using a 512 DSL internetconnection).
Extract kernel tarball
Uncompress the tarball as follows:
$ tar jxvf linux-2.6.x.tar.bz2
Replace the "x" with the version you're using. This will generate a directory "linux-2.6.x", get inside and ... let the party begins !
Configure the Linux Kernel
Having a bad day? Try to get a Paracetamol caplet or something because this step is a headache, takes lots of time (30 min at least) in order to configure properly your kernel... one keyword: PATIENCE !
To start configuring, inside the "linux-2.6.x" directory type the following at your terminal:
$ make mrproper
$ make xconfig
The first command will "prepare" some configuration files in order to compile correctly, in the past I received comments of kernel failure, this step seems to correct most of it. The next step will prepare and show your a graphical kernel configuration interface using qt (most of RH-based systems already includes qt), if you receive an error, please refer to your system updater (urpmi, apt, yast, yum ...) and download "qt" and "qt-devel" or any that refers to qt compilers, execution libraries, widgets and source code.
An alternative is to use "menuconfig" in the case you find difficult to get "qt" libraries and source, you can use it by changing "xconfig" with "menuconfig", like this:
$ make menuconfig
This command will need ncurses, but don't worry, most of Linux distros has them already (it is considered as an terminal developing standard to use ncurses ! That's why...)
If everythings smooth a window (or a blue menu inside your terminal) will appear you're ready to start configuring your kernel, open with the editor of your choice the 2 files we saved, remember? (hardware.log and cpuinfo.log) or print it if you wish.
I can't guide you here step-by-step but I can, at least, give to you important tips to follow, please take note:
Compile the Linux Kernel
The final showdown ! Now, after configuring and saving your kernel, type the following at the terminal:
$ make
That's it? Nothing else? No. For "pristine" Linux source tarballs, using the "make" command will build everything you need, using a powerful Intel or AMD processor and a simple configuration will take 10 minutes, this may vary from 7 minutes to 45 minutes or more (old Intel machines). So go and grab a lunch, take a nap or go walk for a while.
When you came back, look at the terminal, if no errors around then... HORAAY !
Install the Linux Kernel Modules
First of all, get root rights and type the following at your terminal:
# make modules_install
This command will install automagically every module you choose, it won't take long, so please wait, after booting with this freshly-baked linux kernel, you can load them as usual.
Prepare your bzImage
This is simple, what you are going to do is to copy 2 files, "System.map" and "bzImage", follow this steps at your terminal (with root right's of course !):
# cp arch/i386/boot/bzImage /boot/bzImage-<version>
# cp System.map /boot/System.map-<version>
# ln -s /boot/System.map-<version> /boot/System.map
<version> refers to the version you downloaded and compiled, this MUST match with this three given instructions.
Create initrd image
Some systems requires this instruction in order to boot the kernel, no problem, just look at "/lib/modules" for the "<version>" you just downloaded and compiled, take this data and do the following inside the "/boot" directory:
# mkinitrd /boot/initrd-<version>.img <version>
If success, nothing will returned, at any errors please read the output and figure it out the correct version you're compiling and installing.
Prepare GRUB and reboot
Finally, prepare "GRUB" for our new kernel image ! first of all, make a backup of /boot/grub/menu.lst and edit this file appending the following matching your new kernel image:
title My Distro (<version>)
title Test Kernel (<version>)
root (hd0,0)
kernel /boot/bzImage-<version> ro root=LABEL=/
initrd /boot/initrd-<version>.img
Please be sure about your HD device, one useful tip is to look and use the configuration from your distro root hd kernel. Be sure about every file path (bzImage and initrd), if everything's OK, then save and... reboot !
Take notes about any event or case
After rebooting, choose "Test Kernel" or any name you input here and check any errors you could have, when you arrive to runlevel 5, run the graphic server, interact with your computer, etc... This information will guide you to any misconfigured kernel parameter or missing module to load, I can't help much around here but If you got a functional system you'll notice that this recent kernel is way more fast than the distro ones... and the confidency that you compiled and tuned it, congratulations ! My job ends here !
Postamble
Thanks for reading ! I hope this would come in handy, before sending any questions or comments, try to read a complete Howto, they include for sure more FAQ's and troubleshooting, this is just an "Starting" guide, I'll appreciate any suggestions, corrections, addings or anything CONSTRUCTIVE. Well, again... Thank's for reading !!!
Reference
http://www.digitalhermit.com/linux/K...ild-HOWTO.html
总结:
#tar jxvf linux-2.6.16.bz2
#cd linux-2.6.16
#make xconfig 或者 make menuconfig
#make
#make modules_install install