Saturday, 15 June 2013

How to Compile Linux Kernel from Source

Linux kernel is the important part of all Linux family of operating systems including Ubuntu, CentOS, and Fedora.

In this tutorial, we’ll explain how to compile Linux kernel from source.

1.Download Kernel source from kernel.org

 # wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.3.tar.xz
 

2. Untar the kernel source 

 # tar -xvJf linux-3.9.3.tar.xz
 

3. Configure kernel

 # cd linux-3.9.3

 # make menuconfig

 
We will use the default config provided by the kernel. So select “Save” and save the config in the file name “.config”
 

4. Compile the kernel 

   # make

 5. Compile Kernel modules 

  # make modules 

6. Install kernel modules

  # make modules_install

7. Install new kernel

  # make install

 8. Boot with new kernel

 #  reboot

Pipe

Pipes may be considered as open files that have no corresponding image in filesystems.

Pipes are created by pipe() system call  by a process , pipe() system call returns a pair of file descriptor .  Descriptor can be passed to decedents through  fork() system call. Process can read from pipe using read() system call and can write using write() system call.

POSIX defines only half-duplex (even pipe() returns 2 descriptor each process must close one before using other)  pipes .
Other Unix system such as System V 4 implement full-duplex pipes.

example : ls | more 
Internally what is  happening ?

1.Invokes the pipe() system call , say  return vale is file descriptor 3 (read channel) and 4(write channel)
2.Invokes fork() system call twice.
3.Invokes the close() system call .
 
The first child process executes ls and perform following operations
1. Invokes dup2(4,1) to copy file descriptor 4 to 1 .
2.Invokes close() system call to release file descriptors 3 and 4.
3.Invokes the execve() system call to execute the ls program  ,the program writes output to the file that has descriptor 1 (standard output) . i.e. it writes into the pipe.

The second child process executes more program and perform following operations
1.Invokes dup2(3,0) to copy file descriptor 3 to 0. (now file descriptor 0 is read channel )
2..Invokes close() system call to release file descriptors 3 and 4.
3.Invokes the execve() system call to execute the more program. The program reads its input from file with descriptor 0(by default) i.e from pipe (now)


If two or more process read or write to same pipe they must explicitly synchronize their access by using file locking or IPC semaphores