Jump to content
xisto Community
Sign in to follow this  
qwijibow

A General Guide To Re-compiling Your Kernel

Recommended Posts

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.

:) securety. do you know what a root kit is ? (http://forums.xisto.com/no_longer_exists/) 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 https://www.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

# Tulip family network device support#CONFIG_NET_TULIP=yCONFIG_DE2104X=mCONFIG_TULIP=m# CONFIG_TULIP_MWI is not set# CONFIG_TULIP_MMIO is not set# CONFIG_TULIP_NAPI is not setCONFIG_DE4X5=mCONFIG_WINBOND_840=mCONFIG_DM9102=m# CONFIG_PCMCIA_XIRCOM is not set# CONFIG_PCMCIA_XIRTULIP is not setCONFIG_HP100=mCONFIG_NET_PCI=yCONFIG_PCNET32=mCONFIG_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
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
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
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.

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

run the following command
make bzImage &&make modules &&make modules_install

bzImage is name of the kernel file.

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

copy the kernel to the boot directory

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...

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

/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 :) !)

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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:

make xconfig
(You must have X server access)

Then you simply do
make clean && make install

Afterwards, issue the
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

Share this post


Link to post
Share on other sites

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:

make xconfig
(You must have X server access)

Then you simply do
make clean && make install

Afterwards, issue the
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 ;) . I'll try it out tomorrow ... my openSuse installation might need some optimalisation because it's not running stable atm ^_^

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.