A General Guide To Re-compiling Your Kernel

free web hosting
Free Web Hosting > Computers & Tech > How-To's and Tutorials > OS > Linux

A General Guide To Re-compiling Your Kernel

qwijibow
This is a very general guide for those wanting to re-compile there 2.6 linux kernel for the first time.

-----------------------------------
1st... Why would you want to re-compile your kernel ?
------------------------------------
a) its a right of passage, if you are comfortable re-compiling a kernel, then you are well on your way to becoming an experianced linux user.

cool.gif securety. do you know what a root kit is ? (www.rootkit.com) root kits need to load themselves into your kernel as drivers. you can stop them by hard compiling all the drivers your computer needs into your kernel, then dissableing driver module loading. (also there are things like SELinux (securety Enhanced), but that goes beyond the scope of this tutorial.

c) Performance. Most Operating sytems are optimised to run well on all the latest Pentium and Athlon chips.
you can change this to optimise the kernel highly for your Processor

d) You need to upgrade your kernel, but dnt want to wait for your distro to release a new one.

e) your curiouse about how it all works.

--------------------------------------
great... so whats a kernel ???
-------------------------------------
the kernel is the heart of the operating system, it controls all your hardware.
drivers for the kernel can either be compiled into the kernel, or as seperate modules which can b loaded or unloaded.

for example.... my on board nework card will always be in my computer, so i compile it hard into the kernel.

however, i may consoder getting a new sound card in the future, so i compile the sound card drivers as modules, which an be unloaded, and replaced when i update my hardware.

for more info, see kernel.org

-------------------------------------
Okay, lets start... download a plain vanilla kernel
------------------------------------
(assuming you have already installed a compiler)

step one, you need a kernel source code package.
go to http://kernel.org and click the "F" link of the latest 2.6 kernel version.
at the time of writing this this is 2.6.10 (F gets full source code, other links give patches)

Patches tweak source code for things like support, securety or performance, but again is beyond the scope of this tutorial.

extract the doanloaded kernel to somwhere like /usr/src/linux-<version>/

---------------------------------------
Getting a base configureation
---------------------------------------
We are going to use a kernel configureation that we know works ( the one you are using right now)
so that we dont need to configure all areas.

have a look in the /proc/ folder for a file named config or config.gz
is a file named config exists, copy it to your /usr/src/linux-<version> folder with the command "cat /proc/config > /usr/src/linux-<version>/.config"

if the file is named config.gz then use "gzcat" instead of cat. (and dot miss the dot '.' in the /.config)

if neither exist in /proc then have a look fir a file named Config in your /boot filder (you may need to mount /boot first)

cave a look inside it, it should hav a format similar to this

CODE

# Tulip family network device support
#
CONFIG_NET_TULIP=y
CONFIG_DE2104X=m
CONFIG_TULIP=m
# CONFIG_TULIP_MWI is not set
# CONFIG_TULIP_MMIO is not set
# CONFIG_TULIP_NAPI is not set
CONFIG_DE4X5=m
CONFIG_WINBOND_840=m
CONFIG_DM9102=m
# CONFIG_PCMCIA_XIRCOM is not set
# CONFIG_PCMCIA_XIRTULIP is not set
CONFIG_HP100=m
CONFIG_NET_PCI=y
CONFIG_PCNET32=m
CONFIG_AMD8111_ETH=m
# CONFIG_AMD8111E_NAPI is not set


copy it to the kernel directory and rename it to .config

----------------------------------
configureing !!!!!
-----------------------------------
cd into the kernel directory, and run the command
CODE
make oldconfig


this will adapt the config file from a different kernel vwersion to match the current version.
if you aer asked any questions, answer with the default by simply hitting return.

now run the command
CODE

make menuconfig


You can navigate this menu with the direction keys, the return key to enter a menu, and the space key to change the highlited value.

[ ] means no, or do not compile
[ M ] means compile as a module (which can b loaded or unloaded at any time)
[ * ] means hard compiled into the kernel

if you dont usderstand somthing, you can read the help on any section.
not all items can be compiled as moduls, but most can.

Have a look round, read, experiment.

one thing tomake sure of, is that under FileSystems section, the support for your file system is selected as * not M (ths is vatal to booting, unless you build an initrd-image, which is beyond the scope of this tutorial.)

Now have a look at ProcessorType --->> Porcessor Family.
this is probably defailted to i486 or i686.

if you dont know what processor you have, run this command in a different window
CODE
cat /proc/cpuinfo


You can greatly improve compile time by removing support for devices toy dont have.
these are mainly in the Device Drivers section.

if you dont need or use firewire, dissabl that... dont use your parrallell port ? dissable that.
do you have a gigabit ethernet connection ?? no ? dissable.

You are free to tweak and change as much or as little as you want.
you may want to systematically read every help section and decide wether or not to change it.
you might want to play it safe and only alter the processor optimisation.

do as little or as much as you feel comfortable with.

when you have finished, ecit out all the way, and answer yes to saving.

-----------------------------
compiling
-----------------------------

you ONLY need to backup IF the kernel vrsion you are compiling is the same as the kernel version you are currently using.

CODE

cp -r /lib/modules/<version> /lib/modules/<version>-backup


run the following command
CODE

make bzImage &&
make modules &&
make modules_install


bzImage is name of the kernel file.

---------------------------
Installing.
---------------------------

copy the kernel to the boot directory

CODE

cp /usr/src/linux-<version>/arch/boot/i386/bzImage /boot/myNewKernel.bz


----------------------------
Edit grub.conf or lilo.conf
----------------------------

Open /boot/grub/menu.lst with a text editor
find the section that looks like so...

CODE
title Gentoo Linux
       root(hd0,0)
       kernel /boot/kernel-2.6.9-gentoo-r14 root=/dev/hda1 vga=791 apic
       initrd /boot/initrd-2.6.9-gentoo-r14


and add anouther copy of it,
if there is an initrd line (like there is here) remove it.
and edit the kernel line so that th path given is to /boot/myNewKenrel.bz
also edit the title line to somthing like "myTestKernel"
and if you are using fedora or redhat (maybe others) you will need to fix the root= option.
dont leave anything on the root option like LABEL=/ that redhat puts there, reploace it with your REAL root device...

if you dont know your real root device, open up /etc/fstab and look for the line which has a plain '/' as the second option... like this

CODE
/dev/hda1               /               reiserfs        noatime                 0 0


do the same with /etc/lilo.conf if you are using lilo.
After editing lilo's config file, you ill need to re-oinstall lilo with the command "lilo"

make sure the Timeout=# value in grub or lilo gives you enough time to select your kernel.

------------
End
-------------

A well compiled and configured kernel will be slightly faster, less bloated, and slightly faster booting.

when grub first starts, the first thing it has to do is de-compress the kernel, a smaller kernel will e-compress a little faster.

Also, all the text that apreas on screen before the init scripts take over (the lines that end in [ OK ])
is ouput from the kernel's built in drivers amungst other things.
removing built in drivers that you dont need will incrace the speed of this phase of booting too.

Dont Expect miricles...
you have done extremely well if your first kerneleven boots.

you rpobably will not notiice and performace increaces, maybe benchmark programs will display improvment.

for lightning fast system, you would also need to re-compile the whole system (see lInuxFromScratch or Gentoo at DistroWatch.com

ALSO, dont be surprised it you fail the first time... Almost everyone fails the first time (think of Neo making that first jump in the Matrix wink.gif !)

If anyone wants to add more advanced info to this thread i would be greatfull.
especially for things like SELinux / Boot-Splash / Patching

 

 

 


Reply

rockershive
good day qwijibow:

I'm a newbie on Linux, I just want to get step-by-step instructions to see or try to edit the source code of Linux -I'm using SUSE 10.1 distro...
Maybe you can post it here...thanks in advance.

Reply

xboxrulz
compiling a new Linux kernel has become easier in recent years than before. Of course, there are some digging required before you should EVER attempt at recompiling your kernel.

First, you must extract your tarball, then you just repeat some of the steps including inserting this command:
CODE
make xconfig
(You must have X server access)

Then you simply do
CODE
make clean && make install


Afterwards, issue the
CODE
mkinitrd
command.

There shouldn't be any further tinkering for openSUSE.

This is how I did it in openSUSE 10.2. Of course you need root access to do all this! Remember, by using any tutorials here, it is at YOUR OWN SOLE RISK! We cannot be held accountable for faults here.

xboxrulz

Reply

wutske
QUOTE(xboxrulz @ Jan 4 2008, 07:26 PM) *
compiling a new Linux kernel has become easier in recent years than before. Of course, there are some digging required before you should EVER attempt at recompiling your kernel.

First, you must extract your tarball, then you just repeat some of the steps including inserting this command:
CODE
make xconfig
(You must have X server access)

Then you simply do
CODE
make clean && make install


Afterwards, issue the
CODE
mkinitrd
command.

There shouldn't be any further tinkering for openSUSE.

This is how I did it in openSUSE 10.2. Of course you need root access to do all this! Remember, by using any tutorials here, it is at YOUR OWN SOLE RISK! We cannot be held accountable for faults here.

xboxrulz


Thank you very much for providing the info for openSuse tongue.gif . I'll try it out tomorrow ... my openSuse installation might need some optimalisation because it's not running stable atm huh.gif

 

 

 


Reply

xboxrulz
goodluck wutske smile.gif. I'm not sure if anything changed for 10.3, but I highly doubt it.

Post your success here if you want smile.gif

xboxrulz

Reply


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

Similar Topics

Keywords : Compiling Kernel


    Looking for general, guide, compiling, kernel






*SIMILAR VIDEOS*
Searching Video's for general, guide, compiling, kernel
advertisement




A General Guide To Re-compiling Your Kernel