NNP's Quick and Dirty Linux Kernel Compilation Guide
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
By NNP at 2006-03-09 09:52
NNP's Quick and Dirty Linux Kernel Compilation Guide
"Who am I? I am but the sum of my experiences..and today I am more than I was yesterday" - Terrabyte
Introduction
Welcome, I'm assuming that in coming here you've made the decision to have a go at compiling and using a new kernel so I won't go into the numerous reasons to make this decision. Compiling and setting up a kernel for the first time can be a daunting task even for users who are comfortable in everyday Linux use so I hope this guide will make the process a little easier and help get your new kernel up and running as fast as possible. Before I go on I must mention a few things, firstly if you are new to Linux or looking to get started then you are probably in the wrong place. I would recommend going to http://www.linuxiso.org and grabbing one of the distros from there which come with preconfigured kernel source's and nice graphical installers. They contain all you will need and there is a flavour for all users. Secondly, this guide is exactly what it claims to be, "Quick and dirty", (and not in _that_ way you perv :P ). I assume a level of competency with basic Linux commands and the environment. Also I wanted to keep this guide as short as possible so I won't be going into specific parts of the kernel or troubleshooting methods should something go wrong. If you need further assistance (although you shouldn't) check out the references section at the end of this document which explain the process in detail. Now, on with the show.....
Getting the kernel source
The kernel source can be downloaded from kernel.org. It is best to get one of the major releases (e.g 2.6.15) as opposed to one of the incremental increases between these (e.g. 2.6.15.6). By getting the major release you can patch to any of the incremental releases but you can also patch straight to the next major release (e.g. 2.6.16). This is more difficult if you get one of the incremental releases. Once you have the source move it into /usr/src. Also get the latest patch (at the time of writing this was 2.6.15.6) from kernel.org.
Unzip the kernel source and apply the patch as follows:
Step (iv) will show the exact same output as step (v) but it doesn't actually touch your kernel source tree. By using the dry-run option it will check to ensure that the kernel patch can be cleanly applied without screwing up your kernel source tree.
Configuring your new kernel
First you need to determine what type of hardware you have. This can be done using the command 'lspci'
You'll particularly need to know the IDE Chipset, Audio Controller, and the Ethernet Controller. You won't normally need to know your VGA Controller type when compiling the kernel. There are several methods of configuring the kernel with version 2.6
make config <--similar to 2.4. Most simplistic. Asks you about each option one at a time
make oldconfig <-- same as above but it uses your current .config file and only asks about new or changed options
make menuconfig <-- similar to menuconfig in 2.4.
make xconfig <-- QT based graphical system
make gconfig <-- Clone of xconfig except using GTK libraries.
We will be using make menuconfig. Its relatively simple to use and doesn't have many requirements. All you need are the ncurses dev files. In my opinion the QT and GTK installers just add unnecessary fluff. On debian a simple apt-get install libncurses5-dev should take care of that.
Now its really just a matter of going through the options an various menus and picking what suits your hardware and set up. If your unsure on anything you can highlight the option your unsure of and press ?. You can chose to compile things directly into the kernel (fill the box beside them with a * by pressing the space bar) or compile them as a module and insert them into the kernel as needed (by filling the box with an M). Certain things that are required to boot the kernel are best to be built in (such as IDE drivers etc) but for other non-critical stuff then its just as good, if not better, to build them as modules. At a later stage if you need to upgrade a driver thats compiled as a module you can just plug it out and insert the new one into the kernel but if its compiled in then a recompile of the kernel will be required.
NOTE: Support for your file system must be built into the kernel not as a module. Select the correct filesystem for the system you are currently running (e.g reiserfs, ext2, ext3 etc)
Building the new kernel
sudo make bzImage
Go make a cup of coffee or the beverage of your choice.
sudo make modules
Again, more drink (Starting to see a pattern? ;) )
sudo make modules_install
And more drink
If you wanted to minimise interruptions to your drinking time you could do
sudo make bzImage && make modules && make modules_install
You can also combine the make bzImage and make modules by typing 'make'. So the above command would become
make && make modules_install
The above commands can take quiet a while, as in close to an hour. If its a stock kernel from kernel.org (or elsewhere) it will be much faster than any of the distributions as it will have less to compile by default.
The modules will be copied into /lib/modules/KERNELVERSION
Installing the new kernel
Now its just a matter of copying the newly compiled kernel and System.map into /boot.
For me it looked like this
Now that the kernel is in place we just have to edit our boot loaders config file and add the new kernel.
If you are using the grub boot loader (and you probably are) this file is normally in /boot/grub and is called menu.lst. As I'm using Debian I can only guarantee it is there for my particular install. If you're using a different OS then check out its documentation for the correct location. Look at the other entries and copy their structure to add your new kernel to the list. You must be root. Ignore the initrd option as we haven't created one and they aren't normally necessary. For further info on editing your grub config file check out the GRUB manual.
If your boot loader is Lilo then you need to edit /etc/lilo.conf and then as root run /sbin/lilo to write the info to the MBR.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.