This article assumes little or no prior experience with compiling the Linux kernel and a system with no preexisting kernel sources. It assumes a basic proficiency in navigating and manipulating the Linux file system at the command line, including comfort with the vi text editor. It assumes knowledge of the system's specific hardware configuration. It assumes all basic requirements for compiling the kernel are met prior to beginning the process. Once you have downloaded and unpacked the kernel source, it is highly recommended that you read the README file located at the root of /usr/src/linux-2.6.x. It contains more detailed information about this process, and may save you some trouble. A system with an x86 (most non-64-bit Intel and AMD processors) architecture will be assumed.
Procedure
To compile the Linux 2.6.x kernel you first need to obtain the kernel source code. At this writing, the current kernel source is approximate 43 Megabytes in Bzip2 format. For the purpose of this article we will use Bzip2 (*.tar.bz2) format, which yields a slightly smaller compressed file than gzip (*.tar.gz). With the exception of arguments to the tar command (tar -zxvf for *.tar.gz files), the steps are the same if you choose to use the gzip format.
Current Kernel sources can be obtained from the Linux Kernel Repository; you can go straight to the 2.6 kernel sources at ftp://ftp.kernel.org/pub/linux/kernel/v2.6. Make sure you download the most recent FULL source code. If the file name includes the word 'patch', this is the wrong file. File names for the full source code packages begin with 'linux'. Presenty the most current release is linux-2.6.21.1.tar.bz2 (this changes frequently, so pay close attention when making your selection - the home page at kernel.org will always tell you what the most recent release is).
Once you have downloaded the kernel source code, you'll want to move it to its default location, which is /usr/src on most systems. Since you're writing to an area that is owned by root (for which most user accounts don't have write permission), you'll need to execute the command with root privileges. Invoke a command prompt and issue the following command:
user@linux:~>sudo mv /source/code/location/linux* /usr/src
You will be prompted to enter your root password before the command will be executed. Once the file has been moved, you should change your current working directory to /usr/src:
user@linux:~>cd /usr/src
Now you need to unpack the source code using Linux's standard command line decompression utility:
user@linux:/usr/src>tar -jxvf linux*
A list of files will be displayed to standard output (your monitor) as they are inflated. Uncompressing the file will create a new directory, linux-2.6.x (where x = the revision number), where the actual source code is contained. Once the sources are unpacked, change to this directory:
user@linux:~>cd /usr/src/linux*
NOTE:
It is highly recommended that you read the README file located at the root of /usr/src/linux-2.6.x. It contains more detailed information about this process, and may save you some trouble.
Since we're starting from scratch, we'll need to build a configuration file, which will tell the system what kinds of hardware support we want to include in the kernel. This step is the most tedious and will take the longest. There are several different ways to accomplish this, some of which function purely at the command line. Savvy readers can seek out this information through an online search. Because we still like doing some things in a graphical environment, we'll use the command:
user@linux:~>make xconfig
A window will appear on your KDE or Gnome desktop with the title "qconf". A list of major kernel features will appear in the left hand column. Selecting one of these will show specific options in the upper right hand pane of the qconf window.
Because there are so many options and so many hardware configurations out there, I will not attempt to cover them all here. I will assume that you know enough about your system's hardware configuration to select the proper options for basic hardware support. I will also assume that you know enough not to monkey with things that you don't understand, bearing in mind that an improper kernel configuration can result in faulty system performance or inability to boot the system.
There are two ways to include certain kinds of hardware and functionality support. You can choose to compile support directly into the kernel, in which case you want to use the check mark in the box next to the option in your qconf window. You can also choose to compile certain options as modules. These are represented with a dot in the corresponding checkbox. Each method has its advantages and disadvantages.
The more options you choose to compile directly into the kernel, the larger your kernel will be, which in turn means slower system response time. The upside to compiling options directly into the kernel is that you don't have to worry about loading certain support manually. It is generally best to compile all support for your basic hardware configuration (video, mouse, keyboard, etc.) and for anything you use frequently directly into the kernel.
You can also compile certain options as modules. Modules are handy if you don't need to use a particular type of hardware device or kind of functionality all the time. Modules can be loaded (and unloaded) at the command line, and support for the hardware or feature in question is activated without having to reboot the system. For example, if you're amateur radio operator and you want support for packet radio, but only use it once in a while, then you would probably want to compile support for those options as modules.
Once you are satisfied with your selections, you need to write them to a configuration (*.config) file. Select File -> Save As in your qconf window and choose a file name for the file. Make sure it is being saved in /usr/src/linux-2.6.x, as this is where the following commands will expect to find it by default:
user@linux:/usr/src/linux-2.6.x>make
Depending on the speed of the system's processor, the amount of RAM, and the number of options being included, this may take a while. If you have chosen to compile any portions of the kernel as modules, then you also need to:
user@linux:/usr/src/linux-2.6.x>make modules_install
This, too, could take a while, depending of the number of modules that need to be built. Once both make and make modules_install have completed, you will have a compressed kernel image waiting at /usr/src/linux-2.6.x/arch/i386/boot/bzImage. This needs to be relocated to the /boot directory with a new name. You will need root privileges in order to write to /boot:
user@linux:/usr/src/linux-2.6.x>sudo mv arch/i386/boot/bzImage /boot/vmlinuz-2.6.x
You also need to copy and rename the system map file, which was created in /usr/src/linux-2.6.x:
user@linux:/usr/src/linux-2.6.x>sudo mv ./System.map /boot/System.map-2.6.x
Next, you need to add an option for the new kernel to your boot menu so you can select it when you start the system:
user@linux:/usr/src/linux-2.6.x>cd /boot/grub
Let's back up this file, just in case:
user@linux:/boot/grub>cp menu.lst menu.lst.backup
Now we can edit the file using vi (I'll assume you know your way around vi, if you don't you can use the text editor of your choice, and yes, you can do this from inside KDE or Gnome, but only as root):
user@linux:/boot/grub>vi menu.lst
It is important to retain the conventions used for other entries when editing this file. This includes tabs and spaces for ease of reading the file. The menu.lst file looks something like this (especially for SuSE or openSuSE users; users of other distributions won't see anything about YaST2 here):
# Modified by YaST2. Last modification on Wed Feb 28 09:49:00 PST 2007
default 0
timeout 8
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate
###Don't change this comment - YaST2 identifier: Original name: linux###
title openSUSE 10.2
root (hd0,1)
kernel /boot/vmlinuz root=/dev/hda2
initrd /boot/initrd
To add your new kernel to the list, you'll want to add something like this:
###New Kernel###
title My Distribution - latest kernel
root (hd0,1)
kernel /boot/vmlinuz-2.6.x root=/dev/hda2
initrd /boot/initrd-2.6.x
Save your changes. Now you need to create an initial ram disk (initrd) image for booting the new kernel. I have found it is best to do this from within the directory where it will reside, which is /boot. You'll need to run the mkinitrd command with root privleges:
user@linux:/boot/grub>cd ..
user@linux:/boot>sudo mkinitrd -k vmlinuz-2.6.x -M System.map-2.6.x
It is extremely important that you match the kernel image (vmlinuz-2.6.x) to the corresponding System.map (System.map-2.6.x). Failing to do so will cause problems when it comes time to boot the system.
Check to make sure that the necessary files are present in /boot:
user@linux:/boot>ll (that's two lowercase Ls)
If you see the following files, you're ready to reboot the system and try out your new kernel:
vmlinuz-2.6.x
System.map-2.6.x
mkinitrd-2.6.x
Enjoy!
Published by TM
Am I supposed to say something here? View profile
- Two Free Software Programs for Converting Media FilesConverting video files becomes very difficult with many computer users because they do not know about file type. I will introduce you two free software to help you to convert video files as well as to cut or join them.
Most Useful Free Software for a PCn today's day in age, computers are used for just about everything. With that in mind, there is software for just about everything you can think of. Sounds good, right? Not when...
- Why I Love Open Source Software
- Open Source (R)Evolution
- Two Movements with Different Views: The Free Software Foundation and the Open Sour...
- Get Free Software Now! Here Are the Sites
- Free Software Downloads for the Cheap Techie
- Free Software for Writers
- The Philosophy of Open Source
- Download the latest kernel sources from the Linux Kernel Repository at kernel.org.
- Relocate the compressed source package to /usr/src, then tar -jxvf linux*.
- Use 'make xconfig' to access kernel options in a user-friendly graphical interface.




