Kernel development is the dream of every engineer, who touches linux…But it is not a bread and butter thing, it needs more and more time, resources, patience to achieve what we needed. Here I share some steps which I followed for the first time when I worked with kernel.. This blog is dedicated to all beginners who has thirst in kernel of linux… Kindly post me your replies, to improve this blog….

As for my knowledge I feel following steps are needed to get a new kernel and to start working with that..

*)    download the new kernel
**)    configure the kernel
***)    build the kernel and finally
****)    install the kernel

1)    Downloading new kernel

Before doing anything, make sure with these tools

First,
In terms of downloading new kernel, if you want to clone it from git repository, you’ll want to:

$ sudo apt-get install git

you can figure out whats going on….

Second,

When we want to configure new kernel depending upon our need(there are so many ways to do that) for semi GUI based configuration, we need:

$ sudo apt-get install libncurses5-dev

Third,
By any chance if you don’t have your gcc with your system, try to get it asap:

$ sudo apt-get install gcc

Inorder to get more info, please read respective man pages…

Fourth,

Let us get overview of our system, before installing the new kernel, this will help us to compare changes happened, due to new kernel after installation..

A)    Checking inside /boot directory for

        *)    vmlinuz-*        ->    compressed linux kernel
        **)    initrd.img-*        ->    initial ramdisk of kernel
        ***)    config-*        ->    configuration file of respective kernel

    for detailed explanation of all the three spend more time with manual pages, and surf internet

B)    /lib/modules will hold set of loadable kernel modules for each kernel we have in our system, in my case I got these

$ ls -l /lib/modules/

total 8

drwxr-xr-x 3 root root 4096 Feb 25  2012 2.6.32-5-686
drwxr-xr-x 3 root root 4096 Feb 25  2012 2.6.39-bpo.2-686-pae

from my output, you may understand that I have two kernels inside my system, before installing the newer kernel(3.7.8)..

just on digging inside of one,

$ ls -l /lib/modules/2.6.32-5-686/

total 2552
lrwxrwxrwx  1 root root     35 Dec  7  2011 build -> /usr/src/linux-headers-2.6.32-5-686
drwxr-xr-x 10 root root   4096 Dec  7  2011 kernel
-rw-r–r–  1 root root 603672 Nov 14  2011 modules.alias
-rw-r–r–  1 root root 583488 Nov 14  2011 modules.alias.bin
-rw-r–r–  1 root root 299640 Nov 14  2011 modules.dep
-rw-r–r–  1 root root 421232 Nov 14  2011 modules.dep.bin
-rw-r–r–  1 root root     52 Nov 14  2011 modules.devname
-rw-r–r–  1 root root  99256 Nov  3  2011 modules.order
-rw-r–r–  1 root root    131 Nov 14  2011 modules.softdep
-rw-r–r–  1 root root 237855 Nov 14  2011 modules.symbols
-rw-r–r–  1 root root 307874 Nov 14  2011 modules.symbols.bin
lrwxrwxrwx  1 root root     38 Dec  7  2011 source -> /usr/src/linux-headers-2.6.32-5-common

this is what I got…

C) And finally, to get some interesting fact about our system, browse /proc library

to find version of my running kernel,

 $ cat /proc/version 


Linux version 2.6.39-bpo.2-686-pae (Debian 2.6.39-3~bpo60+1) (norbert@tretkowski.de) (gcc version 4.4.5 (Debian 4.4.5-8) ) #1 SMP Thu Aug 4 11:02:22 UTC 2011

to find my processor information

$ cat /proc/cpuinfo

processor    : 0
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Pentium(R) Dual-Core CPU       T4500  @ 2.30GHz
stepping    : 10
cpu MHz        : 1200.000
cache size    : 1024 KB
physical id    : 0
siblings    : 2
core id        : 0
cpu cores    : 2
apicid        : 0
initial apicid    : 0
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 13
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm xsave lahf_lm dts
bogomips    : 4588.08
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

processor    : 1
vendor_id    : GenuineIntel
cpu family    : 6
model        : 23
model name    : Pentium(R) Dual-Core CPU       T4500  @ 2.30GHz
stepping    : 10
cpu MHz        : 1200.000
cache size    : 1024 KB
physical id    : 0
siblings    : 2
core id        : 1
cpu cores    : 2
apicid        : 1
initial apicid    : 1
fdiv_bug    : no
hlt_bug        : no
f00f_bug    : no
coma_bug    : no
fpu        : yes
fpu_exception    : yes
cpuid level    : 13
wp        : yes
flags        : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl est tm2 ssse3 cx16 xtpr pdcm xsave lahf_lm dts
bogomips    : 4588.44
clflush size    : 64
cache_alignment    : 64
address sizes    : 36 bits physical, 48 bits virtual
power management:

As like this you can get much more….

For your information, on using ‘cat’ command for all(version, cpuinfo) of them, you may thing as they(version, cpuinfo) are all files, but the fact is they(version, cpuinfo) are not files,come on lets check it out

$ ls -l /proc/version

-r–r–r– 1 root root 0 Feb 18 14:11 /proc/version

$ ls -l /proc/cpuinfo

-r–r–r– 1 root root 0 Feb 18 14:11 /proc/cpuinfo

$ ls -l /proc/mtrr

-rw-r–r– 1 root root 0 Feb 18 13:29 /proc/mtrr

since the content of each is ‘0’, they don’t have any content, as a normal file has. What they represents are windows between the user space and kernel space…

Oh..! I forgot to say this command

$ uname -a

Linux boss 2.6.39-bpo.2-686-pae #1 SMP Thu Aug 4 11:02:22 UTC 2011 i686 GNU/Linux

as per your guess, these command shows the detail of running kernel in my system…

and to find currently loaded modules in my kernel, do this

$ lsmod 

->    currently loaded kernel modules
Remember all these commands, we will be using them for comparison after installation of our new kernel…

Atlast, to get a newer kernel, click here, and download also its repective patches…

 $ tar xvjf linux-3.7.8.tar.bz2

Here I had not discussed about git cloning(to get new kernel)…

2)    Configuring the newer kernel…

I saved the newer stable kernel of version 3.7.8 at the desktop, for safety purpose

Keep the source tree of kernel at Desktop and do all steps as follow…..

Proceed further by changing directory to the kernel tree, just as like this

$ cd linux-3.7.8/

A)    Cleaning the source directory

$ make distclean

this is mandatory for cleaning, the source tree, even though we downloaded the newer..

B)    manual configuration of new kernel,

This command will throw us a semi – GUI page for configuration purpose..

$ make menuconfig

Please spend some time with configuration window, at last while exit don’t save anything…

I hope those who are all reading this blog may be beginners… We are not in the state, to do this ourselves, hence kindly don’t try to configure the kernel as per

your wish now, this will lead to drastic damage….After sometime we may be in a state that we will develop a kernel by ourselves…….:-)

Short cut method to configure a kernel is to just copy the configuration file of running kernel, obviously you will not get any extra feature. But for a beginner

this is mandatory to get practiced.

I know my running kernel,

$ uname -a

Linux boss 2.6.39-bpo.2-686-pae #1 SMP Thu Aug 4 11:02:22 UTC 2011 i686 GNU/Linux

I am looking to copy its configuration file with newly created configuration file for newer kernel..Just type as follows

$ cp /boot/config-2.6.39-bpo.2-686-pae .config

explanation for this command is not necessary.. to anyone…

But it is obvious that inorder to get much more newer features only, we are migrating from old to new kernel, due to previous step it will result that newer kernel

too will have only the old features, to get activate the newer features I need to run

$ make oldconfig

but it becomes tedious process, since we may need to config each and every new feature by hitting ENTER, I don’t know exact number of newer features…

I suggest two ways to achieve this,

a)    just keep your finger, on ENTER key, as long as process completes,

but I got a very beautiful method due to my searching,

b)    

$ yes '' | make oldconfig

And after this gets over, I can see my newer config file using

$ cat .config

And now its time to give our favorite name to our newer kernel,

this can be done by,

a)    open a file named ‘Makefile’ from linux source(which I placed at desktop)directory
b)    you can see few lines at beginning of it,

    VERSION = 3
    PATCHLEVEL = 3
    SUBLEVEL = 0
    EXTRAVERSION = jackandjill        <–    I gave this name…

    you are allowed to give your favorite names at EXTRAVERSION, other options not suited for editing……

3)    Building kernel

It is quite simple…

just,

$ make

it will take much more time, to build everything, don’t disturb terminal during this…

or else in order to speed up the process use this

$ make -j4

        ->    4 represents my cpu is dual core, generally you can choose this number as double of your cpu core..

4)    Installation

This involves following steps,

a)    copy the build generated files inside /boot directory,
b)    populate modules, but creating a new directory for kernel inside /lib/modules
c)    updating bootloader(GRUB), to find the newer kernel, during boot process

just enter,

$ sudo make modules_install

and

$ sudo make install

sh /home/elcot/Desktop/linux-3.7.8/arch/x86/boot/install.sh 3.7.8-pimpi3 arch/x86/boot/bzImage \
System.map “/boot”

then,

$ sudo update-initramfs -c -k 3.7.8-jackandjill

finally,

updating the bootloader,

$ sudo update-grub

Everything finished, then its time for reboot….

One more question, how will you select the newer kernel, while system gets boot up…?

Answer is just push the SHIFT key down, while booting, you will get a screen that prompt us to select the kernel….Select your hand rolled kernel…

after reboot, you just confirm your kernel by

$ uname -a

Linux boss 3.7.8-jackandjill #1 SMP Mon Feb 18 16:15:26 IST 2013 i686 GNU/Linux

so I have three kernels inside my system, you may see this by

$ ls -l /lib/modules/

total 12
drwxr-xr-x 3 root root 4096 Feb 25  2012 2.6.32-5-686
drwxr-xr-x 3 root root 4096 Feb 25  2012 2.6.39-bpo.2-686-pae
drwxr-xr-x 3 root root 4096 Feb 18 17:16 3.7.8-jackandjill

$ exit

If things works fine, then no issues..

If it throws any errors please take a note of it in a paper, and report / get help from experts using mailing list….

Eventhough, if your hand rolled kernel makes trouble, you can boot up with your old kernel, system will boot…!!!

But all these steps are done by me on my system, with taking risks….I suggest you to be cautious while doing all these steps…I may not guarantee, if anything

goes wrong….!!!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s