By Greg Kroah-Hartman
Book Price: $34.99 USD
£24.99 GBP
PDF Price: $24.99
Cover | Table of Contents
Kernel Hacking packages. If your distribution
offers this option, it is easiest to install this instead of
trying to track down all of the individual programs that are needed for
this task.
gcc that should be installed. If you wish to download
the compiler and build it yourself, you can find it at
http://gcc.gnu.org.
gcc you have on your system, run the following command:
$ gcc --version
gcc, does not do all of the compiling on
its own. It needs an additional set of tools known as
binutils to do the linking and assembling of source
files. The binutils package also contains useful
utilities that can manipulate object files in lots of useful ways,
such as to view the contents of a library.
Kernel Hacking packages. If your distribution
offers this option, it is easiest to install this instead of
trying to track down all of the individual programs that are needed for
this task.
gcc that should be installed. If you wish to download
the compiler and build it yourself, you can find it at
http://gcc.gnu.org.
gcc you have on your system, run the following command:
$ gcc --version
gcc, does not do all of the compiling on
its own. It needs an additional set of tools known as
binutils to do the linking and assembling of source
files. The binutils package also contains useful
utilities that can manipulate object files in lots of useful ways,
such as to view the contents of a library.
binutils can usually be found in a distribution package
called (not surprisingly) binutils. If you wish to download
and install the package yourself, you can find it at
http://www.gnu.org/software/binutils.
binutils is the oldest that can
successfully link the kernel.
To determine which version of binutils you have on your system, run the following command:
$ ld -v
make is a tool that walks the kernel source tree to
determine which files need to be compiled, and then calls the compiler and
other build tools to do the work in building the kernel. The kernel
requires the GNU version of util-linux package is a collection of small
utilities that do a wide range of different tasks. Most of these utilities
handle the mounting and creation of disk partitions and manipulation of the
hardware clock in the system.
util-linux
package yourself, you can find it at
http://www.kernel.org/pub/linux/utils/util-linux.
util-linux is the oldest that works properly .
It is recommended that you install the latest version of this package,
because new version support new features added to the kernel.
Bind mounts are one example of an
option in newer kernels, and a newer version of
util-linux is needed in order to have them work
properly.
util-linux package you
have on your system, run the following command:
$ fdformat --version
module-init-tools package is needed if you wish to
use Linux kernel modules. A kernel module is a loadable chunk of code that
can be added to or removed from the kernel while the kernel is running. It
is useful to compile device drivers as modules and then load only the
ones that correspond to the hardware present in the system. All Linux distributions
use modules in order to load only the needed drivers and options for the
system based on the hardware present, instead of being forced to build all
possible drivers and options in the kernel in one large chunk. By
using modules, memory is saved by loading just the code that is needed to
control the machine properly.
-rc versions as development kernels so that people could
help test and debug the changes. After everyone agreed that the
development release was stable enough, it was released as the 2.6.18 kernel.
This whole cycle usually takes about two to three months, depending on a
variety of factors.
-rc versions as development kernels so that people could
help test and debug the changes. After everyone agreed that the
development release was stable enough, it was released as the 2.6.18 kernel.
This whole cycle usually takes about two to three months, depending on a
variety of factors.
http://www.kernel.org.
site shows all of the current kernel versions for the various different
kernel trees, as shown in .
http://www.us.kernel.org/pub/linux/kernel/v2.6/,
shown in .
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz
--17:44:55-- http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz
=> `linux-2.6.17.8.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: 51,707,742 (49M) [application/x-gzip]
100%[=============================================>] 51,707,742 35.25K/s ETA 00:00
18:02:48 (47.12 KB/s) - `linux-2.6.17.8.tar.gz' saved [51707742/51707742]
To download it using curl:
$ curl http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz -o linux-2.6.17.8.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 49.3M 100 49.3M 0 0 50298 0 0:17:08 0:17:08 --:--:-- 100k
$ mkdir ~/linux
Now move the source code into this directory:
$ mv ~/linux-2.6.17.8.tar.gz ~/linux/
And go into the linux/ directory:
$ cd ~/linux $ ls linux-2.6.17.8.tar.gzNow that the source code is in the proper directory, we need to uncompress the tree:
$ tar -xzvf linux-2.6.17.8.tar.gz
The screen will be filled with files that are uncompressed, and you
will be left with the following in the linux/
directory:
$ ls linux-2.6.17.8.tar.gz linux-2.6.17.8/
$ cd linux-2.6.17.10 $ make config make config scripts/kconfig/conf arch/i386/Kconfig * * Linux Kernel Configuration * * * Code maturity level options * Prompt for development and/or incomplete code/drivers (EXPERIMENTAL) [Y/n/?] Y * * General setup * Local version - append to kernel release (LOCALVERSION) [] Automatically append version information to the version string (LOCALVERSION_AUTO) [Y/n/?] Y ...The kernel configuration program will step through every configuration option and ask you if you wish to enable this option or not. Typically, your choices for each option are shown in the format
[Y/m/n/?] The capitalized
letter is the default, and can be selected by just pressing the Enter
key. The four choices are:
y
n
m
?
$ cd linux-2.6.17.10 $ make config make config scripts/kconfig/conf arch/i386/Kconfig * * Linux Kernel Configuration * * * Code maturity level options * Prompt for development and/or incomplete code/drivers (EXPERIMENTAL) [Y/n/?] Y * * General setup * Local version - append to kernel release (LOCALVERSION) [] Automatically append version information to the version string (LOCALVERSION_AUTO) [Y/n/?] Y ...The kernel configuration program will step through every configuration option and ask you if you wish to enable this option or not. Typically, your choices for each option are shown in the format
[Y/m/n/?] The capitalized
letter is the default, and can be selected by just pressing the Enter
key. The four choices are:
y
n
m
?
menuconfig, a GTK+-based
graphical one called gconfig, and a QT-based graphical
one called xconfig.
menuconfig way of configuring a kernel is a console-based program that offers a way to move around the kernel configuration
using the arrow keys on the keyboard. To start up this configuration mode,
enter:
$ make menuconfig
You will be shown a screen much like .
Device Drivers. To enter that menu, move the arrow
key down nine times until the line
Device Drivers ---> is highlighted, as shown in
.
Then press the Enter key. It will move you into the
Device Drivers submenu and show it as illustrated in
.
Generic Driver Options submenu, press
Enter again, and you will see the three
options shown in .
The first two options have a [*] mark by them. That
means that this option is selected (by virtue of the *
being in the middle of the [ ] characters), and that this
option is a yes-or-no option. The third option has a
$ make CHK include/linux/version.h UPD include/linux/version.h SYMLINK include/asm -> include/asm-i386 SPLIT include/linux/autoconf.h -> include/config/* CC arch/i386/kernel/asm-offsets.s GEN include/asm-i386/asm-offsets.h CC scripts/mod/empty.o HOSTCC scripts/mod/mk_elfconfig MKELF scripts/mod/elfconfig.h HOSTCC scripts/mod/file2alias.o HOSTCC scripts/mod/modpost.o HOSTCC scripts/mod/sumversion.o HOSTLD scripts/mod/modpost HOSTCC scripts/kallsyms HOSTCC scripts/conmakehash HOSTCC scripts/bin2c CC init/main.o CHK include/linux/compile.h UPD include/linux/compile.h CC init/version.o CC init/do_mounts.o ...Running make will cause the kernel build system to use the configuration you have selected to build a kernel and all modules needed to support that configuration. While the kernel is building, make will display the individual file names of what is currently happening, along with any build warnings or errors.
$ make -j4
and for a machine with four processors, use:
$ make -j8
If you do not pass a numerical value to the -j option
$ make -j
the build
system will create a new thread for every subdirectory in the kernel tree,
which can easily cause your machine to become unresponsive and take a much
longer time to complete the build. Because of this, it is
recommended that you always pass a number to the -j option.
$ make drivers/usb/serial
Using this syntax, however, will not build the final module images in that
directory. To do that, you can use the M=
argument:
$ make M=drivers/usb/serial
which will build all the needed files in that directory and link the final
module images.
$ sudo ls ~/linux/linux-2.6.17.11/Makefile Password: MakefileEnter either your own password at the password prompt, or the password of the system administrator (root). The choice depends on how the sudo command is set up. If this is successful, and you see the line containing:
Makefilethen you can skip to the next section.
$ su Password: # exit exit $At the password prompt, enter the password of the system administrator (root). When the su program successfully accepts the password, you are transferred to running everything with full root privileges. Be very careful while as root, and do only the minimum needed; then exit the program to continue back as your normal user account.
mkinitrd, so try install that package if you
cannot find the script on your machine.
# make modules_install
This will install all the modules that you have built and place them in
the proper location in the filesystem for the new kernel to properly find.
Modules are placed in the /lib/modules/
KERNEL_VERSION
directory, where mkinitrd, so try install that package if you
cannot find the script on your machine.
# make modules_install
This will install all the modules that you have built and place them in
the proper location in the filesystem for the new kernel to properly find.
Modules are placed in the /lib/modules/
KERNEL_VERSION
directory, where KERNEL_VERSION is the kernel version of
the new kernel you have just built.
# make install
This will kick off the following process:
modules_install phase.
# make modules_install
i386-based kernel, do the
following:
# make kernelversion 2.6.17.11Note that the kernel version will probably be different for your kernel. Use this value in place of the text KERNEL_VERSION in all of the following steps:
# cp arch/i386/boot/bzImage /boot/bzImage-KERNEL_VERSION # cp System.map /boot/System.map-KERNEL_VERSION
#!/bin/sh
#
# installs a kernel
#
make modules_install
# find out what kernel version this is
for TAG in VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION ; do
eval `sed -ne "/^$TAG/s/ //gp" Makefile`
done
SRC_RELEASE=$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION
# figure out the architecture
ARCH=`grep "CONFIG_ARCH " include/linux/autoconf.h | cut -f 2 -d "\""`
# copy the kernel image
cp arch/$ARCH/boot/bzImage /boot/bzImage-"$SRC_RELEASE"
# copy the System.map file
cp System.map /boot/System.map-"$SRC_RELEASE"
echo "Installed $SRC_RELEASE for $ARCH"
$ ls -F /boot | grep grub grub/then you are using the GRUB program to boot with. If this directory is not present, look for the presence of the /etc/lilo.conf file:
$ ls /etc/lilo.conf /etc/lilo.confIf this is present, you are using the LILO program to boot with.
$ info grub
timeout 300 default 0 splashimage=(hd0,0)/grub/splash.xpm.gz title 2.6.16.11 root (hd0,0) kernel /bzImage-2.6.16.11 root=/dev/sda2 vga=0x0305 title 2.6.16 root (hd0,0) kernel /bzImage-2.6.16 root=/dev/sda2 vga=0x0305The line starting with the word
title defines a new
kernel entry, so this file contains two entries. Simply copy the lines from one instance of the
title word to the next one, such as :
title 2.6.16.11 root (hd0,0) kernel /bzImage-2.6.16.11 root=/dev/sda2 vga=0x0305to the end of the file, and edit the version number to contain the version number of the new kernel you just installed. The title does not matter, so long as it is unique, but it is displayed in the boot menu, so you should make it something meaningful. In our example, we installed the
2.6.17.11 kernel, so the final copy of the file
looks like:
timeout 300 default 0 splashimage=(hd0,0)/grub/splash.xpm.gz title 2.6.16.11 root (hd0,0) kernel /bzImage-2.6.16.11 root=/dev/sda2 vga=0x0305 title 2.6.16 root (hd0,0) kernel /bzImage-2.6.16 root=/dev/sda2 vga=0x0305 title 2.6.17.11 root (hd0,0) kernel /bzImage-2.6.17.11 root=/dev/sda2 vga=0x0305
$ cd ~/linux/linux-2.6.17.11
$ cp .config ../good_config
kernel.org website, you will remember that
it contained a list of the current kernel versions that are available for
download:
F to
download the entire source code for the kernel. However, if you click on
the name of the kernel release, it will download a patch file instead:
kernel.org website, you will remember that
it contained a list of the current kernel versions that are available for
download:
F to
download the entire source code for the kernel. However, if you click on
the name of the kernel release, it will download a patch file instead:
$ bzip2 -dv patch-2.6.17.9-10.bz2 patch-2.6.17.9-10.bz2: done $ bzip2 -dv patch-2.6.17.10-11.bz2 patch-2.6.17.10-11.bz2: done $ ls -F good_config linux-2.6.17.9/ patch-2.6.17.10-11 patch-2.6.17.9-10
$ cd linux-2.6.17.9
and run the patch program to apply the first patch
moving the source tree from the 2.6.17.9 to the 2.6.17.10 release:
$ patch -p1 < ../patch-2.6.17.9-10 patching file Makefile patching file block/elevator.c patching file fs/udf/super.c patching file fs/udf/truncate.c patching file include/net/sctp/sctp.h patching file include/net/sctp/sm.h patching file net/sctp/sm_make_chunk.c patching file net/sctp/sm_statefuns.c patching file net/sctp/socket.cVerify that the patch really did work properly and that there are no errors or warnings in the output of the patch program. It is also a good idea to look at the Makefile of the kernel to see the kernel version:
$ $ head -n 5 Makefile VERSION = 2 PATCHLEVEL = 6 SUBLEVEL = 17 EXTRAVERSION = .10 NAME=Crazed Snow-Weasel
$ patch -p1 < ../patch-2.6.17.10-11 patching file Makefile patching file arch/ia64/kernel/sys_ia64.c patching file arch/sparc/kernel/sys_sparc.c patching file arch/sparc64/kernel/sys_sparc.c patching file drivers/char/tpm/tpm_tis.c patching file drivers/ieee1394/ohci1394.c patching file drivers/md/dm-mpath.c patching file drivers/md/raid1.c patching file drivers/net/sky2.c patching file drivers/pci/quirks.c patching file drivers/serial/Kconfig patching file fs/befs/linuxvfs.c patching file fs/ext3/super.c patching file include/asm-generic/mman.h patching file include/asm-ia64/mman.h patching file include/asm-sparc/mman.h patching file include/asm-sparc64/mman.h patching file kernel/timer.c patching file lib/spinlock_debug.c patching file mm/mmap.c patching file mm/swapfile.c patching file net/bridge/netfilter/ebt_ulog.c patching file net/core/dst.c patching file net/core/rtnetlink.c patching file net/ipv4/fib_semantics.c patching file net/ipv4/netfilter/arp_tables.c patching file net/ipv4/netfilter/ip_tables.c patching file net/ipv4/netfilter/ipt_ULOG.c patching file net/ipv4/route.c patching file net/ipx/af_ipx.c patching file net/netfilter/nfnetlink_log.c
make menuconfig or
gconfig or xconfig method to change
different configuration options. But once you have a working
configuration, the only thing that is necessary is to update it with any
new options that have been added to the kernel since the last release. To
do this, the make oldconfig and
make silentoldconfig options should be used.
make oldconfig takes the current kernel configuration in
the .config file, and updates it based on the new
kernel release. To do this, it prints out all configuration questions, and
provides an answer for them if the option is already handled in the
configuration file. If there is a new option, the program stops and asks
the user what the new configuration value should be set to. After
answering the prompt, the program continues on until the whole kernel
configuration is finished.
make silentoldconfig works exactly the same way as
oldconfig does, but it does not print anything to the
screen, unless it needs to ask a question about a new configuration option.
stable kernel series. If this happens, there are no new
questions that need to be answered for the kernel configuration, so the
program continues successfully without any need for user intervention. An
example of this is moving from the 2.6.17.9 to 2.6.17.11 release:
$ cd linux-2.6.17.11 $ make silentoldconfig scripts/kconfig/conf -s arch/i386/Kconfig # # using defaults found in .config #
Mutex debugging
is a new one when switching between certain kernel releases. Here is the
output when this happened:
$ make silentoldconfig
scripts/kconfig/conf -s arch/i386/Kconfig
#
# using defaults found in .config
#
*
* Restart config...
*
*
* Kernel hacking
*
Show timing information on printks (PRINTK_TIME) [Y/n/?] y
Magic SysRq key (MAGIC_SYSRQ) [Y/n/?] y
Kernel debugging (DEBUG_KERNEL) [Y/n/?] y
Kernel log buffer size (16 => 64KB, 17 => 128KB) (LOG_BUF_SHIFT) [16] 16
Detect Soft Lockups (DETECT_SOFTLOCKUP) [Y/n/?] y
Collect scheduler statistics (SCHEDSTATS) [N/y/?] n
Debug slab memory allocations (DEBUG_SLAB) [Y/n/?] y
Memory leak debugging (DEBUG_SLAB_LEAK) [Y/n] y
Mutex debugging, deadlock detection (DEBUG_MUTEXES) [N/y/?] (NEW) y
$ ls /proc/config.gz /proc/config.gzIf the /proc/config.gz filename is present, copy this file to your kernel source directory and uncompress it:
$ cp /proc/config.gz ~/linux/ $ cd ~/linux $ gzip -dv config.gz config.gz: 74.9% -- replaced with configCopy this configuration file into your kernel directory and rename it to .config. Then use it as the basis of the kernel configuration to build the kernel as described in .
$ ls /proc/config.gz /proc/config.gzIf the /proc/config.gz filename is present, copy this file to your kernel source directory and uncompress it:
$ cp /proc/config.gz ~/linux/ $ cd ~/linux $ gzip -dv config.gz config.gz: 74.9% -- replaced with configCopy this configuration file into your kernel directory and rename it to .config. Then use it as the basis of the kernel configuration to build the kernel as described in .