Linux - Compilazione del nodo (Kernel) Linux -Compilação do núcleo (Kernel)) Linux - Kompilierung des Kerns (Kernel) Linux - Compilation du noyau (Kernel) Linux - Recopilación del núcleo (Kernel)

Compiling the kernel

In this article, compiling the kernel under Linux is explained.
The following explanations are based on version 2.4.20 of kernel, i.e. the most recent version of the kernel at the time this article was written (March 2003). The sources of the most recent version can be downloaded from http://www.kernel.org.

The sources "weigh" between 25 et 30 Mo.

Decompressing the sources

Once the sources have been obtained, you will find a file named tar.bz2 pr tar.gz, depending on the case. Copy them into the directory /usr/src/ of your Linux machine, but do not decompress them immediately.
In the above-mentioned directory, type the following command:

castor@linuxbox:/usr/src$ ls -al
total 8
drwxrwsr-x	2 root	 src		  4096 Feb  8  2002 .
drwxr-xr-x   13 root	 root		 4096 May  1  1980 ..
lrwxrwxrwx	1 root	 src			12 Feb 25 15:39 linux -> linux-2.4.18
drwxr-sr-x	2 root	 src		  4096 Feb 25 15:38 linux-2.4.18
-rw-r--r--	1 root	 root	 27421046 Feb 25 15:37 linux-2.4.20.tar.bz2
castor@linuxbox:/usr/src$

The result may be different on your machine. The first thing to do is to replace the symbolic link linux with the command rm linux.
Then, decompress the tarball which was recovered prior thereto. Make sure you have enough space, the decompressed sources are approx. 200 Mo !!
Then we create a symbolic link linux pointing to the new directory. As the case may be, the directory in which the decompressed sources will be located is already called linux, and it is therefore advisable to rename it with the command mv linux linux-2.4.20.

root@linuxbox:/usr/src# rm linux
rm: remove `linux'? y
root@linuxbox:/usr/src# tar -xjf linux-2.4.20.tar.bz2
root@linuxbox:/usr/src# ln -s linux-2.4.20 linux
root@linuxbox:/usr/src# ls -hal
total 27M
drwxrwsr-x	4 root	 src		  4.0k Feb 25 15:49 .
drwxr-xr-x   13 root	 root		 4.0k May  1  1980 ..
lrwxrwxrwx	1 root	 src			12 Feb 25 15:49 linux -> linux-2.4.20
drwxr-sr-x	2 root	 src		  4.0k Feb 15 15:38 linux-2.4.18
drwxr-xr-x   14 root	 src		  4.0k Nov 29 00:53 linux-2.4.20
-rw-r--r--	1 root	 src		   26M Feb 25 15:37 linux-2.4.20.tar.bz2
root@linuxbox:/usr/src#

Particularities of the Linux kernel: The modules

The Linux kernel is "modular", i.e. certain options, defined as "modules" are only loaded at the time this is requested by the kernel. This allows it to save memory, to the detriment of loading speed. For example, when printing a page every six months, it is not useful to keep the printing templates (parallel port, printer, etc.) permanently in memory. They will only be loaded once the user requests printing.

Before starting the configuration of the kernel, it is therefore important to familiarize oneself with the intended use of the machine under Linux.

Configuring options

There are three commands to configure the sources: make config, make menuconfig, and make xconfig.

The first two are in text mode, the third one requires the X-window system. The choise is yours: the three options are fully equivalent. Only the first option is somewhat more restrictive since it requires a full review of the options.

As to myself, my preference is make menuconfig.

root@linuxbox:/usr/src/linux# make menuconfig
( cd include ; ln -sf asm-i386 asm)
make -C scripts/lxdialog all
make[1]: Entering directory `/usr/src/linux-2.4.20/scripts/lxdialog'
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o checklist.o checklist.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o menubox.o menubox.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o textbox.o textbox.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o yesno.o yesno.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o inputbox.o inputbox.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o util.o util.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o lxdialog.o lxdialog.c
gcc -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -DLOCALE  -DCURSES_LOC="<ncurses.h>" -c -o msgbox.o msgbox.c
gcc -o lxdialog checklist.o menubox.o textbox.o yesno.o inputbox.o util.o lxdialog.o msgbox.o -lncurses
...

At this point in time, we are in the configuration interface.
It consists of several menus, each and every one of which may contain submenus, etc.

It is strongly advised to read the online help for each option.
The information provided below may vary depending on the version of the kernel and the options that were chosen before.

  • Code maturity level options: Only useful for developers.
  • Loadable module support: Indispensable. Allows the use of the modular functionalities of the kernel. Respond YES to all options.
  • Processor type and features: Set of options pertaining to the processor. The first line contains the type of your processor. There is forward compatibility, i.e. when you enter "Pentium-Classic", all processors of the type Pentium and higher will work. It is recommended to specify the type that is closest to your processor.
  • Machine Check Exception: Allows the processor to alert the kernel in the case of any problem. Respond YES.
  • Toshiba Laptop support and Dell laptop support: Respond YES in case you have a portable Toshiba or Dell computer.
  • /dev/cpu/microcode - Intel IA32 CPU microcode support
    /dev/cpu/*/msr - Model-specific register support
    /dev/cpu/*/cpuid - CPU information support 
    These three options may be used without risk; they can optimize management of the processor.
  • High Memory Support: Management of more than 1 GB of RAM. Unless your machine has more than 960 MB of RAM, leave "off".
  • Math emulation: Coprocessor emulation. Only useful for 386 or 486SX.
  • MTRR (Memory Type Range Register) support: Useful except for 386, 486, and Pentium first generation (before PII).
  • Symmetric multi-processing support: Useful for multi-processor machines. Remove on mono-processor machines.
  • Local APIC support on uniprocessors (NEW): Allows the use of "virtual" interruptions generated by the processor. When unsure, respond YES IO-APIC support on uniprocessors: Idem, but for I/O (input/output). When unsure, respond YES
  • Unsynced TSC support: Managemetn of unsynchronized TSC When unsure, respond NO.
  • General setup
  • Networking support: Network support. Respond YES since some programs use this function even on a standalone machine.
  • PCI support: Support of the BUS PCI. Respond YES since you have a 99% chance of having at least one card on this bus, except in the case of very old machines.
  • PCI access mode: Type of access to the PCI bus. The options are "BIOS", "direct", or "any". By choosing "any", the kernel will have access with either of the two methods (recommended).
  • ISA bus support: Support for the le ISA bus. Not useful for recent machines. When unsure, respond YES.
  • PCI device name database: Name base for PCI peripherals. Only respond NO for embedded systems requiring very reduced-size kernels.
  • EISA support: Support for the EISA bus. Same as for the ISA bus
  • MCA support: Support of the BUS MCA (MicroChannel). Only for IBM PS/2.
  • Support for hot-pluggable devices: Support for hot-plug peripherals (PCMCIA, USB, etc.).
  • PCMCIA/CardBus support: Support for PCMCIA cards. Activate if needed.
  • PCI Hotplug Support: Support for hotplug peripherals of the PCI port. Idem.
  • System V IPC: Inter Process Communication, libraries used by some programs. Respond YES.
  • BSD Process Accounting: Allows access to process information on the user level. May be useful for monitoring purposes, for example. Respond YES.
  • Sysctl support: Makes it possible to modify some flags "on the run". Respond YES.
  • Kernel core (/proc/kcore) format: type of binary generated (ELF/A.OUT). Leave the value ELF.
  • Kernel support for xxxx binaries: the different types of binaries the kernel will be able to run. Set them to included or module, at your choice
  • Power Management support: APM et ACPI management. You must respond YES first and then choose the type of support (the choices depend on your type of processor).
  • Ignore USER SUSPEND (NEW): For machines with a BIOS APM, NO is a good choice. On some portable computers, a buggy BIOS will require you to respond YES.i
  • Enable PM at boot time (NEW): Only respond NO if your machine stalls at startup.
  • Make CPU Idle calls when idle (NEW): On some machines, makes it possible to slow down the processor when idle. YES is a good choice.
  • Enable console blanking using APM (NEW): Makes it possible to blank the screen during sessions under consoles.
  • RTC stores time in GMT (NEW): In case you are using another OS on the same machine, respond NO. Otherwise, YES is a good choice.
  • Allow interrupts during APM BIOS calls (NEW): Only put YES in case your linuxbox stalls when put on standby.
  • Use real mode APM BIOS call to power off (NEW): Respond YES in case your PC stalls instand of powering off.
    Memory Technology Devices (MTD): Do not activate this option unless you use peripheral devices such as FLASH memories. This allows the kernel to identify them correctly.
  • Parallel port support: Provides support for the parrallel port.
  • PC-style hardware (NEW): Option for all PCs.
  • Support foreign hardware (NEW): Makes it possible to activate support for "exotic" peripherals.
  • IEEE 1284 transfer modes (NEW): Management of sophisticated transfer modes (EPP and ECP).
  • Plug and Play configuration: Provides support for "plug and play" devices. Consists of Plug and Play support and ISA Plug and Play support; the second one only is possible if the first choice has been activated.
  • Block devices: This is an important section. The "block devices" or peripheral devices in block mode includes most storage devices, such as hard disks and other floppy disks. The data are stored by blocks whose size may vary depending on the medium, but it is fixed for a given medium.
  • Normal floppy disk support: Support for the floppy disk drive.
  • XT hard disk support: Support for old 8 bit hard disks.
  • Loopback device support: support for the loopback device, which is useful, for example, for "mounting" an ISO9660 image prior to recording it for verification purposes.
  • Network block device support: Makes it possible to use network devices as if they were local.
  • RAM disk support: Makes it possible to create a RAMdisk, which is a virtual RAM disk, with the size Default RAM disk size. Mainly useful for machines lacking a storage device (thin client).
  • Per partition statistics in /proc/partitions: Makes it possible to store statistics on your partitions. Only useful to optimize your system. The other options are specific for each type of hardware For more information, please consult the online help.
  • Multi-device support (RAID and LVM): Support for RAID and LVM (Logical Volume Manager). Each option can be selected separately (RAID Lineaire, RAID-0 (striping), RAID-1 (mirroring), RAID-4/RAID-5). Not useful to activate unless you know perfectly well whether your hardware uses RAID. ################################### END OF CORRECT DISPLAY #################################
  • Networking Options: We have arrived at the preference section of GNU/Linux, i.e. the network. In this section, it will be possible to include a number of more or less useful tools.
  • Packet Socket: This option allows some programs to directly communicate with the different network devices installed on the system. For example, the utility TCPDump requires this option.
  • Packet socket: mmapped IO: This option allows the Packet Socket to use a much faster input/output method. This option is not essential.
  • Netlink device emulation: This option only exists for backward compatibility with programs which must use some very specific peripheral devices. Planned to disappear in the more or less near future. Better to activate it, if only in module mode.
  • Network packet filtering: This option is very important. It replaces the former option ipchains of kernels 2.2 and older This is the core of the filtering functions of the Linux package that are used with the iptables utility. This option must be checked without hesitation.
  • Network packet filtering debugging: In turn, this option is only interesting for people who wish to become involved with the developmetn of the NetFilter module.
  • Socket Filtering: Makes it possible to filter any type of sockets, except for TCP sockets. This option must be checked to be able to use of the ppp filtering option. In all other cases, NO is a good choice.
  • Unix domain sockets: This option activates the support for the sockets, which are means for network.connection. A very large number of programs uses them, even in case your machine is stand-alone. They may possibly be compiled as a module, but this is strongly discouraged. Respond YES.
  • TCP/IP networking: Support for the TCP/IP protocol. Respond YES even if your machine is entirely stand-alone.