LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-18-2007, 08:32 PM   #1
sausagejohnson
Member
 
Registered: Mar 2004
Location: Canberra Area, Australia
Distribution: Kubuntu
Posts: 242

Rep: Reputation: 30
Thumbs up Kernel Compilation Notes and Tips



Kernel Compilation Notes and Tips
=================================

Having compiled a few kernels now over the years I still wouldn't call myself an expert but I have managed to jot a couple of tips along the way that I would have loved to have known when I started out. Although it is one thing to follow a kernel compile guide, it is another to know what is going on behind the scenes so that decisions can be made on your own. So I hope the following is of use to some people.



.config files
-------------

This file lives in the root of your kernel source folder, but not when you have first downloaded a fresh kernel. This file is generated only after exiting one of the configuration programs like:
make menuconfig

So when you hear about the .config file, thats how it gets there. Have a look in the /boot folder and you will see some pre-built .config files in there that your distribution has created for you and these can serve as a good base when creating your own customised kernel. An example might be: config-2.6.11-1.1369_FC4

One of the most frustrating things when starting to do your own kernel compile is to start off with a blank slate in the menuconfig program and not really know what things to include and what things not to include. Perhaps your system is working ok, but all you wanted to compile in as an extra was NTFS support?

Say you started off without an existing .config file in your kernel source folder and then ran the 'make menuconfig' command. You would then select the NTFS module, quit and continue the compilation process as per normal instructions. But if all went well and you rebooted, chances are your system will fail. Why?

Well it is because you started with a blank canvas. There was no .config file there to start with. By making one completely from scratch, you will have missed low level drivers that are very important for the system but which you may not know about. This is why it is very handy to locate the stardard .config file that came with your distro and use it as a base and only make your alterations to that. Remember from before that these are usually found in the /boot folder, put there by your distribution.

So how do we do that? Well there are two ways.

a) After running 'make menuconfig' you can use the "Load Alternate Configuration" option to load a config file from boot by typing in something like: /boot/config-2.6.11-1.1369_FC4.

The menuconfig program will populate all it's choices with the options held in the config-2.6.11-1.1369_FC4 file. When exiting the program, your changes will not be saved back to the original /boot/config-2.6.11-1.1369_FC4 file. Instead the .config file is created for the first time in your kernel source folder.

b) The second way is to copy the config from the boot folder to your kernel source folder with something like: cp /boot/config-2.6.11-1.1369_FC4 /usr/src/kernel/.config

Then when you execute 'make menuconfig', the program will load and autopopulate it's choices due to the presence of the .config file.

This is one of those things I wish I understood before. Once you do, you can make some good decisions about perhaps archiving .config file for later use or having a few to choose from etc.

Oh, and its a good idea to copy your latest .config to the /boot folder just to keep it safe for future changes, say: cp /usr/src/linux/.config /boot/mykernel-feb2007.config



Adding modules later
--------------------

So you managed to get a kernel + modules all nicely working and all boots fine. But hang about, you forgot to include the scsi_mod.ko module. Ah nuts. Do you really have to go through all those steps over again in the kernel README or your favourite guide again. Nah you don't have to.

If you still have your kernel source folder sitting around and it contains your last .config file, then you should be ok.

Even if you don't have your kernel source folder anymore, just unpack it again and set it up as per the kernel README, and run 'make mrproper'. Then copy in the last .config you saved to /boot back into your kernel source folder with something like cp /boot/mykernel-feb2007.config /usr/src/linux/.config.

So once you have your source folder with your last .config nicely in place, just run 'make menuconfig' again.

The program will load and populate your old choices. Go enable the scsi module or whatever module it was you wanted to change.

Once you quit the program, just run:
make modules
make modules_install

See, because the kernel itself has not been changed, only modules, it is ok to just run the module compile. All the modules are created again and installed into the /lib/modules/2.6.whatever/ folder all over again including your forgotten module.

The last thing to do is just to let the init ramdisk know whats going on for boot time. Locate the current initrd file for your current kernel in the /boot folder and either backup or delete it. For example, if you are on kernel version 2.6.19 (use uname -r to find out), then your initrd might be called something like: initrd-2.6.19.img.

Create a new file in boot with: mkinitrd /boot/initrd-2.6.19.img 2.6.19

Then reboot.

Ok, that's it. Do this whenever you want to make a quick change to your modules.



Conclusion
----------

These tips have helped me enormously when treading through kernel compilation information and getting it right. For any errors in this document, please post changes. Thanks.

Feb 2007
Wayne Johnson
waynejohnson.net
 
Old 02-19-2007, 01:47 PM   #2
Lenard
Senior Member
 
Registered: Dec 2005
Location: Indiana
Distribution: RHEL/CentOS/SL 5 i386 and x86_64 pata for IDE in use
Posts: 4,790

Rep: Reputation: 58
Nice, but if you really want tips get and keep handy "The Linux Kernel in a NutShell", it is freely available here;

ftp://ftp.kernel.org/pub/linux/kerne...kn_pdf.tar.bz2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My installation notes & tips (long) Ed-MtnBiker Fedora 5 05-03-2006 11:36 AM
Tips on compiling a kernel. dr_zayus69 Linux - General 4 06-01-2005 07:47 PM
kernel compile tips wanted Nightfrost Linux - General 2 11-03-2004 06:34 AM
Kernel upgrade tips? syxxpac023 Linux - General 2 10-31-2001 03:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 05:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration