Sunday, February 27, 2011

Difference between Microkernel and Monolithic kernel.

This post explains the two main kernel architectures of operating systems: the monolithic kernel and the micro kernel. Starting with an introduction about the term ”kernel” itself and its meaning for operating systems as a whole, it continues with a comparison of benefits and disadvantages of both architectures.

Kernel: kernel is the indispensable and therefore most important part of an operating system. Roughly, an operating system itself consists of two parts: the kernel space (privileged mode) and the user space (unprivileged mode). Without that, protection between the processes would be impossible.
There are two different concepts of kernels:
·         monolithic kernel.
·         μ-kernel (micro kernel).

Monolithic kernel: The older approach is the monolithic kernel, of which Unix, MS-DOS and the early Mac OS are typical represents of. It runs every basic system service like process and memory management, interrupt handling and I/O communication, file system, etc. in kernel space see Figure 1 (click here for Anatomy of Linux Kernel). It is constructed in a layered fashion, built up from the fundamental process management up to the interfaces to the rest of the operating system (libraries and on top of them the applications). The inclusion of all basic services in kernel space has three big drawbacks.
·         The kernel size increase.
·         Lack of extensibility.
·         The bad maintainability. 


Figure 1: Monolithic Kernel base Operating System.
Bug-fixing or the addition of new features means a recompilation of the whole kernel. This is time and resource consuming because the compilation of a new kernel can take several hours and a lot of memory. Every time someone adds a new feature or fixes a bug, it means recompilation of the whole
 kernel. (click here: “ How to Compile Kernel Source”)

To overcome these limitations of extensibility and maintain-ability, the idea of μ-kernels appeared at the end of the 1980’s. 

Microkernel: The concept (Figure 2) was to reduce the kernel to basic process communication and I/O control, and let the other system services reside in user space in form of normal processes (as so called servers). There is a server for managing memory issues, one server does process management, another one manages drivers, and so on. Because the servers do not run in kernel space anymore, so called ”con-text switches” are needed, to allow user processes to enter privileged mode (and to exit again). That way, the μ-kernel is not a block of system services anymore, but represents just several basic abstractions and primitives to control the communication between the processes and between a process and the underlying hardware. Because communication is not done in a direct way anymore, a message system is introduced, which allows independent communication and favors extensibility.


Figure 2: MicroKernel base Operating System.

Currently, there are two different generations of μ-kernels. The first generation was a more or less a stripped-down monolithic kernel. Because of performance drawbacks concerning process communication, several system services like device drivers, communication stacks, etc. found their way back into kernel space. This resulted in an even bigger kernel than before, which was slower than its monolithic counterpart. 

            Research in the field of μ-kernels prove, that it is not the best solution to create a hybrid kernel 1 , but a pure micro kernel, which has to be very small in size. So small, that it fits into the processor’s first level cache as a whole. Second generation μ-kernels like the L4 are highly optimized, not just referring to the processor family, but also to the processor itself 2 , which results in a very good I/O performance.

In a simple way we can say like this :

Monolithic Kernel (Macro Kernel): Kernel Image = (Kernel Core+Kernel Services). When system boots up entire services  are loaded and resides in memory.
Example: Windows and Unix.

Micro kernel : Kernel Image = Kernel Core. Services are build in to special modules which can be loaded and unloaded as per need.

We have another type of kernel integration technique called
Modular, this is derived from best of micro and monolithic kernel) In
Modular kernel integration:  Kernel Image = (Kernel core + IPC service modules +Memory  module +Process Management module). All other modules are loadable kernel modules.
Example: Linux kernel

Stay tuned for more information :-)



Saturday, February 26, 2011

Hyperlink Open in new window or tab

In response to a blogger request, here is the HTML for a hyperlink that opens in new window and tag (that is, visitor will not lose your site):

<a href="target URL" target="_blank">anchor text</a>

or

<a href="target URL" target="new">anchor text</a>

NOTE:
1. target="....." has been deprecated and is not XHTML compliant and will give errors when you try to validate your website with
http://validator.w3.org/

This is because the people drafting the new standard feels that this should not be forced upon visitors but left to visitors to make a link open in the same or new window or tab (you can make a hyperlink open new window or new tab by right-clicking on a link and choosing either). But how many surfers know how to do that?

target="...." is still effective in many current browsers. Don't know about the future.

2. anchor text is the text that will be displayed by the browser. For example this is the HTML to the father of this blog which will soon be converted to custom domain:

<a href="URL" target="new">Linux Kernel Programming</a>


for the above code the browser will display it as below, and usage of target="new" will open the link either in new window or tab, check this by clicking below link.

Linux Kernel Programming

Anchor text is important from the SEO (Search Engine Optimization) point of view.

3. Many webmaster feels that forcing visitors clicking on links in your site to open new windows or tabs is a wrong strategy and may discourage repeat visits, but this subject is controversial. Do your own research.

How to add Scrolling text-marquee-html code for Blogger.

Hai..! I am explaining how to add Scrolling text(also called as marquee)to your blog sidebars,blog posts,etc...!

This is Another way to attract the visitors is adding some decoration to the site like scrolling text,etc.But,don't decorate it too much,particularly if your site contains too much text as it irritates and spoils the concentration of the reader.You can add scroll bars to tell your visitors what will be your next updates,popular posts,advertisements,etc.

So, this is how it goes to add the scrolling text in your blog...! lets see :

Type 1:

Here is the code to add a simple scrolling text from right to left side


The output will be like:
This is a code to simple scrolling text



Type 2:

If you want some more attraction,then try these,

Add a background color to the text,

If you want some more attraction,then try these,

Add a background color to the text,

This is a code to simple scrolling text

You can choose your background colour by replacing the hexadecimal code(#99ccff).
Click here to see the codes of the different colors.

Here are some mode attributes to learn:



direction="left"

direction="right"

direction="up"

direction="down"


Type 3:

The above attributes tells the text which direction to scroll.
Use the code below:


Here is are some examples:
To scroll Right :

This is a code to simple scrolling text

To Scroll Up :

This is a code to simple scrolling text

To Scroll Down:

This is a code to simple scrolling text


Type 4:

More Attribute:

  • You can add this attribute to alternate the text
  • You can also set the speed of the text with this simple attribute:
the html code for this:
Output for above code:

the html code for this:

This is a code to simple scrolling text

Type 5:

Here this code is to stop the text scrolling when the cursor is on text.
(place the mouse over the text to test it)

Changing the text colour:
Here is the code to change the text colour:(Add it before the marquee tag)



Here is the code to do this

Output:

This is a code to simple scrolling text

Note : If the snow effect is ON in the blog this above OutPut is not the one expected.

How to Add Google Analytics to Your Blogger Blog

Google Analytics is one of the best tools that you can use to track information about the way visitors come to your blog. Here is the procedure....!


Sign into Google Analytics with your Google Account.
Once you have signed in you will be taken to a page that asks you to “Click on the Sign Up button to get started.”
   
                   signup
Click on the ‘Signup’ button to be taken to the ‘Signup’ page.

                   signuppage

Next: Enter the URL of the site you wish to track, and assign a name as it should appear in your Google Analytics reports.

                    privateinfo

Once you have done this and clicked on continue, you will be taken to a page that asks for your First name, last name, home phone and Country. Fill out the details and click continue.

Next you will be taken to the Terms of Service Page. Put a check mark in the “Yes, I agree to the above terms and conditions” box and click on the button that says “create new account.”
Once you have created your account you will be taken to the tracking instructions page.

Copy the HTML ‘snippet’ of Code.
  • Sign into Blogger
  • Click on the Layout Tab
  • Click on Edit HTML
Put a check mark in the box next to ‘Expand Widget Template’.
It’s always a good idea to back up your template before you make any changes.
Click on Download Full Template to back up your template and save a copy onto your computer.

                 pastecode
  • Scroll down through the template code and paste the tracking code just before the body tag. <body>
  • Click on Save Template at the bottom of the screen.
Once you have added the tracking code to your ‘Blogger Template’ go back to Google Analtics and click on continue.

That’s it. You have successfully installed Google Analtics on your Blogger Blog. Google Analtics should be now gathering data about your blog visits.
Please note that Google Analytics generally updates your reports every 24 hours. You may want to check back the next day to familiarize yourself with the different reports.


How to Add a Falling Snow Effect To Blogger.

Step1: Login to your blogger Dashboard and go to Desing --> Page Elements.

Step2: Click on 'Add a Gadget' on the sidebar.

Step3: Select 'HTML/Javascript' and add the one of code given below


<script src=”http://snow-effect.googlecode.com/files/snow.js” type=”text/javascript”>
 
/***********************************************
* Snow Effect without images-by Kurt Grigg at http://www.btinternet.com/~kurt.grigg/javascript
 
* Script featured & available at Dynamic Drive at http://www.dynamicdrive.com/
 
* Please keep this notice intact

***********************************************/
 
</script>


Step4: Now Click On Save 'JavaScript' You are done.

How To Add Snow Effect On The Blogger Mouse Cursor Area.

Hi! guys...! here is the cool simple snow effect to your blog mouse cursor area. I found it interesting hen i as google-ing and many snow effects gadget use images to this. but this gadget do not use images to this. so this is very fast. i've tested this effect on internet explorer, mozzilla firefox & many other web browsers. this simple non-image based widget works just fine....!  
I hope you enjoy using this very cool snow effect gadget. please add your comments, installation trouble or opinions below comment box.


Hey don't think that this would add a widget in your blog, here we just use an approach of using widget. 



Step1: Login to your blogger Dashboard and go to Desing --> Page Elements.

Step2: Click on 'Add a Gadget' on the sidebar.

Step3:Select 'HTML/Javascript' and add the one of code given below



Code: 

<script type='text/javascript'>
// <![CDATA[
var colour="black";
var sparkles=100;

var x=ox=400;
var y=oy=300;
var swide=800;
var shigh=600;
var sleft=sdown=0;
var tiny=new Array();
var star=new Array();
var starv=new Array();
var starx=new Array();
var stary=new Array();
var tinyx=new Array();
var tinyy=new Array();
var tinyv=new Array();
window.onload=function() { if (document.getElementById) {
var i, rats, rlef, rdow;
for (var i=0; i<sparkles; i++) {
var rats=createDiv(3, 3);
rats.style.visibility="hidden";
document.body.appendChild(tiny[i]=rats);
starv[i]=0;
tinyv[i]=0;
var rats=createDiv(5, 5);
rats.style.backgroundColor="transparent";
rats.style.visibility="hidden";
var rlef=createDiv(1, 5);
var rdow=createDiv(5, 1);
rats.appendChild(rlef);
rats.appendChild(rdow);
rlef.style.top="3px";
rlef.style.left="0px";
rdow.style.top="0px";
rdow.style.left="3px";
document.body.appendChild(star[i]=rats);
}
set_width();
sparkle();
}}
function sparkle() {
var c;
if (x!=ox || y!=oy) {
ox=x;
oy=y;
for (c=0; c<sparkles; c++) if (!starv[c]) {
star[c].style.left=(starx[c]=x)+"px";

star[c].style.top=(stary[c]=y)+"px";
star[c].style.clip="rect(0px, 5px, 5px, 0px)";
star[c].style.visibility="visible";
starv[c]=50;
break;
}
}
for (c=0; c<sparkles; c++) {
if (starv[c]) update_star(c);
if (tinyv[c]) update_tiny(c);
}
setTimeout("sparkle()", 40);
}
function update_star(i) {
if (--starv[i]==25) star[i].style.clip="rect(1px, 4px, 4px, 1px)";
if (starv[i]) {
stary[i]+=1+Math.random()*3;
if (stary[i]<shigh+sdown) {
star[i].style.top=stary[i]+"px";
starx[i]+=(i%5-2)/5;
star[i].style.left=starx[i]+"px";
}
else {
star[i].style.visibility="hidden";
starv[i]=0;
return;
}

}
else {
tinyv[i]=50;
tiny[i].style.top=(tinyy[i]=stary[i])+"px";
tiny[i].style.left=(tinyx[i]=starx[i])+"px";
tiny[i].style.width="2px";
tiny[i].style.height="2px";
star[i].style.visibility="hidden";
tiny[i].style.visibility="visible"
}
}
function update_tiny(i) {
if (--tinyv[i]==25) {
tiny[i].style.width="1px";
tiny[i].style.height="1px";
}
if (tinyv[i]) {
tinyy[i]+=1+Math.random()*3;
if (tinyy[i]<shigh+sdown) {
tiny[i].style.top=tinyy[i]+"px";
tinyx[i]+=(i%5-2)/5;
tiny[i].style.left=tinyx[i]+"px";
}
else {


tiny[i].style.visibility="hidden";
tinyv[i]=0;
return;
}
}
else tiny[i].style.visibility="hidden";
}
document.onmousemove=mouse;
function mouse(e) {
set_scroll();
y=(e)?e.pageY:event.y+sdown;
x=(e)?e.pageX:event.x+sleft;
}
function set_scroll() {
if (typeof(self.pageYOffset)=="number") {
sdown=self.pageYOffset;
sleft=self.pageXOffset;
}
else if (document.body.scrollTop || document.body.scrollLeft) {
sdown=document.body.scrollTop;
sleft=document.body.scrollLeft;
}
else if (document.documentElement && (document.documentElement.scrollTop || document.documentElement.scrollLeft)) {
sleft=document.documentElement.scrollLeft;
sdown=document.documentElement.scrollTop;
}
else {
sdown=0;
sleft=0;
}
}
window.onresize=set_width;
function set_width() {
if (typeof(self.innerWidth)=="number") {
swide=self.innerWidth;
shigh=self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientWidth) {
swide=document.documentElement.clientWidth;
shigh=document.documentElement.clientHeight;
}
else if (document.body.clientWidth) {
swide=document.body.clientWidth;
shigh=document.body.clientHeight;
}
}
function createDiv(height, width) {
var div=document.createElement("div");
div.style.position="absolute";
div.style.height=height+"px";
div.style.width=width+"px";
div.style.overflow="hidden";
div.style.backgroundColor=colour;
return (div);
}
// ]]>
</script>


Step 4: Now Click On Save 'JavaScript' You are done....!

Friday, February 25, 2011

How to add Favicon to Blogger Blog

Favicon is a small icon(image) displayed at the beginning of the address bar of the browser.It is also called Favourite Icon,Pageicon and urlicon.

The main advantage of creating and using favicon is ,it makes it easy to find your blog or site when someone favourited or bookmarked your site/blog among several other sites. Here in the below image arrow point to favicon.

 
Most of the people use 16*16 pixel favicon(you can also use 32*32 pixel favicon) with ".ico" format.But,you can also use gif,png(image formats) as well.

Step1: First you need to generate the favicon, that is ".ioc" file by using a favicon generator tool, it is simple in 3 steps.

Step2: The generated favicon should be hosted by some servers, there are many servers available for free hosting. below i have provided link for a generator and hosting site.

Step3: The generated HTML code has to be pasted in blog templet to display your personal favicon.


Step4: Now,go to your blogger dashboard>layout>Edit html [look at the below screenshots]

and look for this code(it is at the top the template)

<title><data:blog.pagetitle/></title>

<b:skin><![CDATA[/* 


Step5: Add the HTML code generated (that is link that looks like below) between the above two lines.


Step6: Save the templet....! thats it, you are Done.




Related Posts:



Tuesday, February 22, 2011

What are Possible Task States ?

All informations about one process is stored in struct task_struct. It includes the status, flags, priority, and many more information about one task. The task_struct of the currently running process is always available through the macro current.
 
Possible task statuses are:

TASK_RUNNING

(R) The process is able to run and contributes to the system load. The scheduler decides which processes really receive CPU time.

TASK_UNINTERRUPTIBLE 
(D) The process waits for some event. It will not be considered by the scheduler. The process cannot do anything while it is waiting (it cannot even be killed). This is usually used by device drivers while the process is waiting for some hardware to respond. Such a process contributes to the system load even though it will not receive CPU time; some other part of the system is considered to be working on behalf of the process.

TASK_INTERRUPTIBLE
(S) The process waits for some event as in TASK_UNINTERUPTIBLE but it can be woken up by a signal. This should be used when the action can be interrupted without side effects. A process in this state is considered asleep and does not contribute to the system load.
 
TASK_STOPPED
(T) The process is stopped by a signal (Ctrl-Z)
 
TASK_ZOMBIE
(Z) The process has exited but there are still some data structures around that could not yet be freed. The zombie will usually be freed when the parent calls wait4() to get the exit status.


Monday, February 21, 2011

What is Linux Driver Model ?

The Linux Device model is built around the concept of busses, devices and drivers. All devices in the system are connected to a bus of some kind. The bus does not have to be a real one; busses primarily exist to gather similar devices together and coordinate initialization, shutdown and power management.

When a device in the system is found to match a driver, they are bound together. The specifics about how to match devices and drivers are bus-specific. The PCI bus, for example, compares the PCI Device ID of each device against a table of supported PCI IDs provided by the driver. The platform bus, on the other hand, simply compares the name of each device against the name of each driver; if they are the same, the device matches the driver.

Binding a device to a driver involves calling the driver’s probe() function passing a pointer to the device as a parameter. From this point on, it’s the responsibility of the driver to get the device properly initialized and register it with any appropriate subsystems.

Devices that can be hot-plugged must be un-bound from the driver when they are
removed from the system. This involves calling the driver’s remove() function passing a pointer to the device as a parameter. This also happens if the driver is a dynamically loadable module and the module is unloaded. All device driver callbacks, including probe() and remove(), must follow the return
value.


How "container_of" macro works, & an Example

Here iam giving a small code snippet that gives and idea about working of "container_of", this posed me little difficulty in understanding, after google-ing i got some examples and after working on that i wrote a simple C application that depicts its working. here i have defined two macros "offsetof" and "container_of" which i have extracted from "kernel.h" header. 
       Please interpret this code and try some trick to understand "container_of".

container_of macro is defined in linux/kernel.h

syntax: container_of( pointer, container_type, container_field );

This macro takes a pointer to a filed name container_field, within a structure of type container_type, and returns a pointer to the containing structure .

simply this is a convenience macro that may be used to obtain a pointer to a structure from a pointer to some other structure contained with in it.


Code :

#include <stdio.h>
#include <stdlib.h>

#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define container_of(ptr, type, member) ({            \
 const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 (type *)( (char *)__mptr - offsetof(type,member) );})

struct test1 {
 int a;
};

struct test2 {
 int b;
 struct test1 z;
 int c;
};

int main()
{
 /* existing structure */
 struct test2 *obj;
 obj = malloc(sizeof(struct test2));
 if(obj == NULL){
       printf("Error: Memory not allocated...!\n");
 }
 obj->z.a = 51;
 obj->b = 43;
 obj->c = 53;
 
 /* pointer to existing entry */    
 struct test1 *obj1 = &obj->z;

 struct test2 *obj2 = container_of(obj1, struct test2, z);

 printf("obj2->b = %d\n", obj2->b);

 return EXIT_SUCCESS;
}

Note: Copying the code directly into your source.c file will also copies the invisible characters and finally you will left out with stray errors, i recommend you to type the code and that even becomes a practice.

for more information check out this : http://www.kroah.com/log/linux/container_of.html

Saturday, February 19, 2011

How To Add “Select all” Html Box to Your Blogger Post

Hai...! your blogs usually consists code that you would like to share, in this post I am giving on of the ways in doing it in a simple manner by adding a piece of code. 









You first add below code to your blogger post.

<form name="MyTextBoxForm"> <input name="button" onclick="javascript:this.form.MyTextBox.focus();this.form.MyTextBox.select();" type="button" value="Select All" /><br /> <textarea cols="80" name="MyTextBox" rows="12" wrap="off">Your Contents Here</textarea></form>

Note: Replace Your Contents Here with your text or tutorial codes,

Example:


"Hey click this button so that code in the below window gets selected and "Ctrl+c" and "Ctrl+v" in your blog temp-let.





Now you are done.

Have a good time.

Related Posts:

Friday, February 18, 2011

How to Make Blog Refresh Automatically

Here I am showing how to make a blog refresh automatically after a given time out, i felt this necessary when the widget I used in the blog need a periodic refresh.


1.Login to your blogger dashboard--> desing- -> Edit HTML

2.Scroll down to where you see tag .

3.Copy below code and paste it just after the tag.



<meta HTTP-EQUIV='refresh' content='20;URL=http://google.com'/>


Note: Replace http://linuxkernel51.blogspot.com with your blog or website URL.

20 is the time period between 2 page refresh.Change it as your choice.

4.Now save your template

You Are Done.


Related Posts:

Removing or Hiding NavBar in Blog

When browsing Blogger powered weblogs hosted on blogspot.com domain or custom domain, there is always a NavBar (Navigation Bar or Banner) that appears on top of the blog. The Blogger NavBar contains Search Blog text-box, Flag Blog to notify Blogger about objectionable contents on the blog, Next Blog link to visit another blog randomly, plus links to create blog or sign in to Blogger.
      No many visitors nor bloggers themselves may find it useful though. It’s possible to hide and remove the NavBar with a little CSS hack. The trick will not interfere or mess up with the custom layouts that webmaster has designed, and pretty safe and easy to implement. In fact, if you’re publishing the blogger Blog to own custom domain with FTP or SFTP, it’s possible to turn off NavBar.

____________________________________________________________________

1. Sign in to Blogger.
2. On the Blogger Dashboard, click on the Layout link of the blog that you want to disable its NavBar. You can also click Customize on NavBar while visiting your blog.







3. Under the Layout tab, click on Edit HTML tab to view the template’s HTML code.








4. Search for the following line of code:

]]>

Before the line, add in the following line of code:

#navbar { display: none; }

or:

#navbar-iframe { display: none !important; }

5. Click on SAVE TEMPLATE to make the change effective.

Sunday, February 6, 2011

Exporting System Call Table in 2.6.x Kernel

System call table was exported till 2.4 kernels, because of security reasons and preventing kernel crash from malicious applications system call table is no more exported. Here is the patch to export system call table.
                Hey...! patch is not something strange programming concept :), its just to edit few source files in kernel to export system call table. 

+ symbol implies the line of code to be added.
 - symbol implies the line of code to be removed.

Here is the patch....! (I am implementing for i386 architecture, as most of desktops are with this architecture)

1) open the file: /src/linux-2.6.32.21/arch/i386/kernel/entry.s

-.section .rodata,"a"
+.section .data,"aw"
 #include "syscall_table.S"

 syscall_table_size=(.-sys_call_table)
2) open the file: /src/linux-2.6.32.21/kernel/kallsyms.c
 
__initcall(kallsyms_init);

 EXPORT_SYMBOL(__print_symbol);
+
+extern void *sys_call_table;
+EXPORT_SYMBOL(sys_call_table);
 
After modifications save changes to above files and rebuild the kernel so that System Call Table is exported in the next boot.

Read Me: I have ever read somewhere on the Internet, implementing a new system call is not the right way to control a module. The right way is to use ioctl() instead. More importantly, it is a silly thing to expose `sys_call_table' for modules to fiddle with it. For experimentation its not big deal.....! have fun exporting sys_call_table.





 




Tuesday, February 1, 2011

How to Invoke System Call in Application


System call can be invoked in application in two different ways. Here to depict this I am writing a C application test.c for both the ways.

Using inline assembly code:
Int this method, you have to know the id of the system call which you would like to invoke. Here in Exercise1, we have added a system call with id: 337, and now I am trying to invoke it in this below example.
  • First move the id of system call to the accumulator register (eax).
  • Raise an interrupt, for context switch to kernel mode. Here int 0x80 raises a Trap interrupt.
  • Now, move the return value into the accumulator.

test.c
_______________________________________________________________________
#include<stdio.h>
int main(){
printf(“Entered main function…!\n”);

/*here starts system call*/
__asm__(“movl $337, %eax”);
__asm__(“int $0x80”);
__asm__(“movl %eax, -4(%ebp)”);

printf(“System call invoked, to see type command: dmesg at your terminal\n”);
printf(“Exiting main….!\n);

return 0;
}
_______________________________________________________________________


Using syscall:
In this we have to include sys/syscall.h header and the code is as follows. mycall is the name of the system call to be invoked, and it is the one we have added in Exercise1.
synatx for syscall :
int syscall(int number, ...);Click here for complete description.
test.c 
_______________________________________________________________________
#include<stdio.h>
#inclide<sys/syscall.h>
int main(){
printf(“Entered main function…!\n”);

/*here starts system call*/
syscall(“SYS_mycall”);

printf(“System call invoked, to see type command: dmesg at your terminal\n”);
printf(“Exiting main….!\n);

return 0;
}
_______________________________________________________________________

Compile and run it.

$ gcc test.c –o test
$ ./test
Entered main function…!
System call invoked, to see type command: dmesg at your terminal
$ dmesg | tail
New sys call invoked by ./test app


Please leave comment :-)                                                Queries are at free of cost

How To Build Linux Kernel

Here we compile kernel source to generate a new kernel image and this new image is used at the next boot of the system.
(Mainline kernel is called as vanilla kernel)
Note: I am assuming that you, as a root user in source directory, at /usr/lib/linux-2.6.32 (linux-2.6.32 name of the kernel source directory that we obtained after unzipping). It’s a convention to place the unzipped source directory at /usr/lib but it can be any where, but to build you have to be in the source directory.

Step1: Assign kernel version tag.
To do so open the Makefile in the source directory at the path /usr/lib/linux-2.6.32/Makefile and at the top of the file you will find the field EXTRAVERSION, edit as follows

$ Vim Makefile

Modify: EXTRAVERSION = .firstbuild
*save the above changes to file.

Step2: Choose kernel configuration.

To do so type that following command. This will generate a configuration file “.config”. Any file that starts with “.” is a hidden file, to list the hidden files use option 'a' with 'ls' command.
$ make menuconfig (this pumps kernel info onto console, wait until prompt returns)

Because the Linux source code is available, it follows that you can configure and custom tailor it before compiling. Indeed, it is possible to compile support into your kernel for only the specific features and drivers you want. Configuring the kernel is a required step before building it. Kernel provides multiple tools to facilitate configuration. The simplest tool is a text-based command-line utility.
$ make config

This utility goes through each option, one by one, and asks the user to interactively select yes, no, or (for tristates) module. Because this takes a long time, unless you are paid by the hour, you should use an ncurses-based graphical utility.
$ make menuconfig

To make very simple use oldconfig option.
$ make oldconfig
Ultimately they generate .config file.
Note: refer to man pages on make, type “make help” at your terminal.

Step3: Compile the source to create kernel image (raw) and modules.
$ make
This takes around 30 min on a normal desktop, to speed up, create threads if yours is a multicore machine. To build the kernel with multiple makes jobs, use
$ make -jn
Here, n is the number of jobs to spawn. Usual practice is to spawn one or two jobs per processor.

Step4: Install the modules on file system.
To do so type the following command.
$ make modules_install
This copies the modules into disk space and adds folder at /lib/modules/[name].
Here name will be 2.6.32.firstbuild

Step5:
As an example, on an x86 system using grub, you would copy arch/i386/boot/bzImage
to /boot, name it something like vmlinuz-version

$ cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.32.firstbuild

Step6:

The build process also creates the file System.map in the root of the kernel source tree. It contains a symbol lookup table, mapping kernel symbols to their start addresses. copy System.map to /boot, name it something like System.map-version

$cp System.map /boot/System.map-2.6.32.firstbuild

$mkinitramfs –o /boot/initrd.img-2.6.32.firstbuild  2.6.32.firstbuild
here 2.6.32.firstbuild is the name of folder that was automatically created at /lib/modules

Step7: Update Grub

$ update-grub

If you open the file grub.cfg at the path /boot/grub/grub.cfg the ###BEGIN/etc/grub.d/10_linux ### segment should look like this
$ gedit /boot/grub/grub.cfg

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Ubuntu, with Linux 2.6.32.firstbuild' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set f57b34e4-1bf6-4135-993f-3db8881340d0
linux /boot/vmlinuz-2.6.32.firstbuild root=UUID=f57b34e4-1bf6-4135-993f-3db8881340d0 ro quiet splash
initrd /boot/initrd.img-2.6.32.firstbuild
}

menuentry 'Ubuntu, with Linux 2.6.32.firstbuild (recovery mode)' --class ubuntu --class gnu-linux --class gnu --class os {
recordfail
insmod ext2
set root='(hd0,1)'
search --no-floppy --fs-uuid --set f57b34e4-1bf6-4135-993f-3db8881340d0
echo 'Loading Linux 2.6.32.firstbuild ...'
linux /boot/vmlinuz-2.6.32.firstbuild root=UUID=f57b34e4-1bf6-4135-993f-3db8881340d0 ro single
echo 'Loading initial ramdisk ...'
initrd /boot/initrd.img-2.6.32.firstbuild

}
Note1: In "/boot/grub/grub.cfg" you will find fields like "timeout = -1" Change it to "timeout = 10", so that even if your new image crashes you have chance to select the generic image in the next Restart.
 
Note2: If the ###BEGIN/etc/grub.d/10_linux ### segment doesn’t start with your new image then you manually cut and paste the above two blocks of code from this segment and paste it below ###BEGIN as very first line.
Restart your system.


Note3: Make sure that while executing Step4 all the modules are copied, if this process stops with few modules copied, like less than a count of 10, then its clear that build was not complete, this can be a reason that you were not as root user while building the kernel and even if the error still persists, chmod 777 kernel-source/* directory. and start all the above steps.


Note4: If you encounter kernel-panic after you restart with grub updated with new kernel configuration then above Note3 can be a solution or else the source is not downloaded completely.



The above process can be simple given as :


First you should be the root user and then go to source folder and then edit the Makefile “EXTRAVERSION” filed in source directory to “.firstbuild”, and execute these commands in sequence. Make sure that you are in root.
$ make oldconfig
$ make
$ make modules_install
$ cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.32.firstbuild
$ cp System.map /boot/System.map-2.6.32.firstbuild
$ mkinitramfs –o /boot/initrd.img-2.6.32.firstbuild 2.6.32.firstbuild
$ update-grub