Linux Kernel

From SHellium Wiki
Jump to: navigation, search
Geographylogo.png In other languages: English | Afrikaans | Albanian | Arabic | Brazilian | Bulgarian | Catalan | Chinese | Croatian | Czech | Danish | Dutch | Esperanto | Estonian | Filipino | Finnish | Flemish | French | German | Greek | Hebrew | Hindi | Hungarian | Indonesian | Italian | Japanese | Latvian | Lithuanian | Macedonian | Malay | Malayalam | Norwegian (Bokmål) | Norwegian (Nynorsk) | Persian | Polish | Portuguese | Romanian | Russian | Serbian | Slovak | Slovenian | Spanish | Swedish | Turkish | Ukrainian | Urdu

Warning.gif

This Feature Is Prohibited

If you attempt to use this on SHellium you will be banned.


Contents

Overview


Compiling a kernel is often one of the worst fears a system administrator has. Why? It is a very time consuming process, requires a lot of knowledge about your system, and one thing wrong can prevent the system from booting. (which can pose a problem if you are working remotely without physical / kvm access

Gathering Information on the System


Our first step assumes you already have a pre-built system, and that you want to recompile the kernel under different settings. First, run the following command:

lspci

This gathers information about your hardware. Write this down.

Next, grab CPU information.

cat /proc/cpuinfo

Write this information down too.

Getting Kernel Source


The nice thing about the linux kernel is that it is open source. This means you can modify it to your liking (although this is not recommended if you are a beginner). You can even release it and sell it! There are many sources which contain the source code to the kernel. (pun not intended)

The easiest way to get started is to grab the kernel sources from your favorite package manager. Try using YaST, yum, rpm, or emerge to get the source code.

If you want to, you can also get the source code from one of the many developers around. These builds are usually "bleeding edge", which means a lot of un-tested code. (meaning, if it breaks...you are out of luck) If you are feeling adventurous, go for it. Otherwise, stay far, far away.

The latest sourcecode is always available at http://kernel.org - this contains stable and unstable kernel sources dating back to the originals from the 90's. The source code usually contains checksum files as well, be sure to verify these using md5 or sha (depending).

Extract 'n' Patch


Create a directory:

mkdir src cd src

If the sources are in bzip format, issue the following command:

tar xfvj /path/to/linux/kernel

If the sources are in GZIP format, issue the following command:

tar xfvz /path/to/linux/kernel

Now, apply any patches you'd like using the patch -pl command. These are also available from http://kernel.org - some are very important, so please be sure to check.

Configuration


Overview


First, let me warn you. The configuration process is EXTREMELY LONG AND TEDIOUS, and I recommend to do it in one sitting to prevent errors. Make yourself a cup of coffee, as some configurations depending on your hardware can take up to three hours. Most 2.4.x kernels and on have graphical ncurses interfaces, so you are not looking at boring text files. Help is also always available.

Modules


Each option usually has three choices. Compile directly into the kernel, compile as a module, or completely disable. When modules began early on, many people kept to compiling drivers directly into the kernel to prevent speed decreases. Now, both options are fine and you will find little speed differences.

Starting


Enter the kernel source directory and run:

make mrproper - This will clean out all the junk currently in the kernel source.

Now the command we have all been waiting for...:

make menuconfig - This will either present you with a blue-looking graphical text terminal configuration window if you are on a terminal, (ncurses based) or the better looking xwindow based configuration screen if you are in a GUI environment. Both do the same things, one just looks more pretty. (Running the graphical version requires you to type make xconfig instead in most cases)

If you are looking for an even greater adventure, run make config for a series of questions (VERY LONG) to configure your kernel.

Configuring your Kernel


This step requires all the knowledge we received from the two commands early on. Be sure to compile into the kernel all the drivers you need for each set of hardware you have. You may find some are enabled by default, but this is not usually the case. Compiling drivers you do not need is not recommended as this makes the kernel huge and inefficient. Sadly, we can not give you very many pointers on what to enable and what to not...as each hardware situation and operating system pose kernel configuration changes. Here are some examples, however:
Code Maturity Level

This option allows configuration of alpha-quality software or obsoleted drivers. It is best to disable this option if the kernel is intended for a production system. If you require an unstable feature in the kernel, then enable this option but beware that it is not very well tested code.

General Setup

This contains options for sysctl, a kernel feature which allows run-time configuration changes. Any other general configuration options are also kept here.

Loadable Module Support

YOU WANT TO ENABLE MODULE SUPPORT! If you will need other kernel modules you will also need to enable "Set Version Information on All Module Symbols".

Processor Type and Features

This is the most important configuration choice. In the introduction section we determined our processor by looking at the output of /proc/cpuinfo and now use that information here to select the appropriate processor. Included in this menu are features such as Symmetric Multi-processing Support for computers with multiple CPUs and High Memory Support for machines with more than 1GB of RAM.

Power Management Options

Found here are options for ACPI and CPU Frequency Scaling which can dramatically improve laptop power usage. Stay far away from experimental modules, especially in this section, there have been known problems with new kernels.

Bus Options ( PCI, PCMCIA, EISA, MCA, ISA)

Here are options for all system bus devices. On most new machines the ISA and MCA support can often be disabled.

Executable File Formats

This section contains all the file formats available to the kernel. There are many interesting options here as well, do look through and check it out.

Device Drivers

All the device-driver configuration options that were previously scattered throughout the 2.4.x menus are now neatly organized under this option. Check your hardware to find out what to enable here.

File Systems

Found here are options for filesystems which are supported by the kernel, such as EXT3 and ReiserFS. ReiserFS is recommended for filesystems with many small files. It is highly recommended to build support for the root filesystems directly into the kernel rather than as a module for the best results.

Security Options

Interesting options here include support for NSA Security Enhanced Linux and other features to increase security.



Crypto Options



In this section, I highly recommend enabling the crypto modules you will need. Most, if not all, are very important. Stay away from experimental ones, however.



Building the Kernel


Run:

make clean

Now start what we have all been waiting for, the build.

make bzImage

This process can take anywhere from ten minutes to three hours depending on your machine and the size of the kernel. Be prepared to wait, so go read a book and have a sandwich.

Build the Modules


Now it is time to build the modules. A shorter process.

make modules

If you were working as a non-root user, be sure to switch to root using su now.

make modules_install

Initrd


If you have built your main boot drivers as modules (e.g., SCSI host adapter, filesystem, RAID drivers) then you will need to create an initial RAMdisk image to avoid boot problems.

mkinitrd /boot/initrd-2.x.x.img 2.x.x (replace x's as appropriate)

Final Kernel Installation


cp arch/i386/boot/bzImage /boot/bzImage-KERNEL-VERSION (Note, arch can be different) cp System.map /boot/System.map-KERNEL_VERSION (As above, replace KERNEL_VERSION) ln -s /boot/System.map-KERNEL_VERSION /boot/System.map (As above, replace KERNEL_VERSION)

Now edit your GRUB/LiLO config to reference the new kernel, initrd (ramdisk), and partition location. See the manpages for those programs for details.

Great, we are done. Congratulations!

Personal tools
Namespaces

Variants
Actions
Navigation
Indexes
SHellium Sites
Toolbox