Configuration & Building the Linux Kernel
文章作者:Omni
信息来源:邪恶八进制信息安全团队(
www.eviloctal.com)
-[ SUMMARY ]---------------------------------------------------------------------
0x00: Introduction
0x01: Tools
0x02: Download The Kernel Source
0x03: Kernel Configuration
0x04: Building the Kernel
0x05: Installing our Kernel
0x06: Bootloader
0x07: Conclusion
---------------------------------------------------------------------------------
---[ 0x00: Introduction ]
Hello to everybody!!
With this paper I will go to explain how to configure and build your Linux
Kernel; that is the "critical" task for lots of Linux users and sometimes for
System Administrators.
-----------------------------------------------------------------------------[/]
---[ 0x01: Tools ]
This is an important paragraph that you must read carefully to understand which
tools you need for the Linux Kernel Configuration and Building process.
1. The Compiler
As you know the Linux kernel is written in the C language; with a little bit
of assembly language.. So; if you wanna build your kernel you need a C
compiler; and the GNU C Compiler is one of the most important tool we need.
Where to find it?
Surf the net and download it from:
http://gcc.gnu.org.
[ Recommendation ]
My opinion is not to get the latest gcc version because sometimes the newest
gcc releases could have some bugs and don't build the linux kernel properly.
$ gcc --version
gcc (GCC) 3.4.6
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2. The Linker
After gcc we need also a set of others utilities known as binutils; to do
the linking and assembling the source code.
You can find what you need here:
http://www.gnu.org/software/binutils.
$ ld -v
GNU ld version 2.15.92.0.2 20040927
3. The.. Make
Make is a tool that walks in the kernel source tree to determine which files
we need to compile and then it calls the compiler, or the binutils to do the
works..
You can find it here:
http://www.gnu.org/software/make.
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i486-slackware-linux-gnu
4. Others
There are others tools like:
(-) module-init-tools to manage and use the Linux Kernel Modules
# depmod -V
module-init-tools 3.2.2
(-) File System Tools to configure, create and fix disk partitions
# tune2fs
tune2fs 1.38 (30-Jun-2005)
# fsck.jfs -V
fsck.jfs version 1.1.11, 05-Jun-2006
processing started: 5/1/2007 10.56.41
# reiserfsck -V
reiserfsck 3.6.19 (2003
www.namesys.com)
These are the principals.. but there are other tools to use
XFS filesystem, to use Quotas functionality of the kernel and much more.
(-) util-linux
Lots of these are utilities handle the mounting, creating of disk partions
and manipulating the Hardware Clock in the System.
-----------------------------------------------------------------------------[/]
---[ 0x02: Download The Kernel Source ]
Eheheh.. where to find the Linux Kernel?
http://www.kernel.org
Download it with wget or curl or.. what you want and move it into /usr/src:
# wget
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.tar.gz
--11:26:12--
http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.21.tar.gz
=> `linux-2.6.21.tar.gz'
Resolving
www.kernel.org... 204.152.191.5, 204.152.191.37
Connecting to
www.kernel.org|204.152.191.5|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 55,328,580 (53M) [application/x-gzip]
100%[===================================>] 55,328,580 233.60K/s ETA 00:00
11:30:08 (229.99 KB/s) - `linux-2.6.21.tar.gz' saved [55328580/55328580]
For a easy way to determine which is the latest version of the kernel you can
surf the net and use the informations available at:
http://www.kernel.org/kdist/finger_banner
The latest stable version of the Linux kernel is: 2.6.21.1
The latest snapshot for the stable Linux kernel tree is: 2.6.21-git4
The latest 2.4 version of the Linux kernel is: 2.4.34.4
The latest prepatch for the 2.4 Linux kernel tree is: 2.4.35-pre4
The latest 2.2 version of the Linux kernel is: 2.2.26
The latest prepatch for the 2.2 Linux kernel tree is: 2.2.27-rc2
The latest -mm patch to the stable Linux kernels is: 2.6.21-rc7-mm2
Now we have the kernel source; so we can uncompress it:
# tar -xzvf linux-2.6.17.8.tar.gz
# pwd;ls -al
/usr/src
total 54128
drwxr-xr-x 9 root root 4096 2007-05-01 11:37 .
drwxr-xr-x 18 root root 4096 2006-12-22 20:17 ..
lrwxrwxrwx 1 root root 15 2007-04-06 18:54 linux -> linux-2.6.17.13
[...]
drwxr-xr-x 19 root root 4096 2007-04-26 05:08 linux-2.6.21
-rw-r--r-- 1 root root 55328580 2007-04-26 05:23 linux-2.6.21.tar.gz
[...]
-----------------------------------------------------------------------------[/]
---[ 0x03: Kernel Configuration ]
The Linux Kernel configuration is kept in a file called .config in the top
directory of the kernel source code tree. This file is very important; so we have
to create it. It could be created from a old configuration (that works well),
from "scratch" or from a default configuration.
(-) From old configuration file: we have to copy the previous kernel configuration
file and put it in the new kernel directory:
# cd linux-2.6.21
# cp ../linux-2.6.17.13/.config .config
# ls -a
. COPYING Makefile crypto ipc scripts
.. CREDITS README drivers kernel security
.config [...]
As you can see we have the .config file borrowed :D from the linux 2.6.17.13
configuration file!
After that we can do a make oldconfig; the kernel configuration program
ask us if we wish to enable some options as show below:
# make oldconfig
Blowfish cipher algorithm (CRYPTO_BLOWFISH) [Y/n/m/?] y
- y stay for: biuld directly into the kernel
- n stay for: leave out of the kernel
- m stay for: build as a module
- ? stay for: print a description of the packet
(-) From Scratch: we have to create our config file from 0; but this take a
very long time; because the kernel contains lots of different configuration
options.
# cd linux-2.6.21
# make config
(-) Default Options: every kernel version could be configured with a
"default" configuration.
# cd linux-2.6.21
# make defconfig
Now we have the .config file (the basic configuration file) in our directory;
so we can modify the configuration with:
# make menuconfig
(I think that is the best way ;) )
You can choose your options by the "Enter" Button and you can navigate into the
kernel options by scrolling the keyboard arrows!
We can also use: (More easy)
# make xconfig
or
#make gconfig
-----------------------------------------------------------------------------[/]
---[ 0x04: Building the Kernel ]
Ok dudes, now it's time to build our kernel!
Ok, let's run make; that cause the kernel build system with our configuration
selected before.
# make
[...]
After some times (it depends from your PC) we have built our kernel.
-- [ A little tips that could be useful ] --
If our machine have MORE THAN ONE processor we can use a cool option "-j number";
and with this options we can build our kernel more quickly. So, for a "comuputer"
with 2 processors we use:
# make -j4
The number given to the -j options corresponds to twice the number of processors in
our system!
[!!] If you do not pass a numerical value to -j our machine can take much more
time to complete the building process.
-----------------------------------------------------------------------------[/]
---[ 0x05: Installing our Kernel ]
We have almost finished our Kernel configuration and setup.
Now, let's try to install all modules that we have built.
Modules installed and built are placed in the directory /lib/modules/KERNEL_VERSION
where (as you know) KERNEL_VERSION is the kernel version we have just installed!
# make modules_install
.. Let's see if we have the modules in our directory:
# cd;/lib/modules; ls -al
# cd /lib/modules; ls -al
total 24
drwxr-xr-x 6 root root 4096 2007-05-02 19:58 .
drwxr-xr-x 6 root root 4096 2006-10-01 00:38 ..
drwxr-xr-x 4 root root 4096 2006-09-02 02:28 2.4.33.3
drwxr-xr-x 4 root root 4096 2007-04-06 19:55 2.6.17.13-smp
drwxr-xr-x 3 root root 4096 2007-05-02 19:58 2.6.21
drwxr-xr-x 3 root root 4096 2007-05-01 13:19 2.6.21-smp <---- OOOK
Now we have to copy the kernel image and some others important file too in the
/boot directory as shown below:
# cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.21-smp
# cp System.map /boot/System.map-2.6.21-smp
-----------------------------------------------------------------------------[/]
---[ 0x06: Bootloader ]
Which bootloader do you use?
--- [ GRUB
We have to edit /boot/grub/menu.lst :
[I've not GRUB; I take this configuration from an other PC]
[...]
title Debian GNU/Linux, kernel 2.6.17.13-smp
root (hd0,0)
kernel /boot/vmlinuz-2.6.17.13-smp root=/dev/hda1 ro
savedefault
# Here is the new kernel Added
title 2.6.21-smp
root (hd0,0)
kernel /boot/vmlinuz-2.6.21-smp root=/dev/hda1 ro
[...]
Reboot.. and hope! :D
--- [ LiLo
We have to edit /etc/lilo.conf :
[...]
# Linux bootable partition config begins
image = /boot/vmlinuz-2.6.17.13-smp
root = /dev/sda6
label = Linux
read-only
# Linux bootable partition config ends
# Here is the new kernel Added
image = /boot/vmlinuz-2.6.21-smp
root = /dev/sda6
label = Linux_2.6.21
read-only
# End Linux 2.6.21
[...]
Save changes with lilo -v and then reboot the system!
-----------------------------------------------------------------------------[/]
---[ 0x07: Conclusion ]
This is the end of my short introduction to the Linux Kernel Configuration & Building
guide; I hope that it could be useful for you!
For any problem, suggestion or what you want please mail me at:
omnipresent @ email . it
or if you want
omni @ playhack . net
-----------------------------------------------------------------------------[/]
\=============[EOF]=====================================/