Chapter 1

Basics

Overview




  • What is Linux Kernel ?
  • Why I need to learn about Kernel ?
  • Linux Kernel development process
  • Basic Linux Kernel internals

What is kernel anyway?



Kernel is responsible for communicating 
with hardware


Kernel Provide a unique interface for
 software to use hardware 


Kernel is responsible to handle network
 communications


Kernel schedule processes to use CPU time


Kernel shares resources between processes




Very Basic Schema of an operating system


Why softwares needs

 kernel?


  • Without a kernel each software should implement its own interface to use hardware
  • With lots of interfaces around there will be huge number of software bugs around.
  • There is no warranty for each interface performance 

Why do i need to know about

 Kernel?



  • You can improve your system performance
  • You can install some device drivers by yourself *
  • It's good to know about your Linux box
  • If you are a developer or want to be one you have to know how your operating system operate.

Why Linux Kernel ?


  • It's totally free ( under GPL v2)
  • Monolithic with support for loadable modules
  • True multi-tasking
  • Support for hardware and filesystem
  • Multi-arch
  • Robust community 
  • People watching, So no backdoor
  • Configurable
  • ........




that's Enough, let's begin



First Step

Build a custom kernel

Requirements for build


1. Linux kernel source code. Get it from www.kernel.org
$ wget  https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.x.y.tar.xz 

2. A bootloader. You definitely have one already.

3.ncurses library and build tools          (on a debian box)
# apt-get install libncurses5 build-essential 

Lets Do it


Extract the source code.
$ tar Jxvf linux-3.x.y.tar.xz  
Create a build directoy
$ mkdir build 
Configure the kernel  ( It's the hard part )
$ cd linux-3.x.y && make O=../build menuconfig 
build the kernel
$ make O=../build -j 4 

Installation

Install new kernel image
# make O=../build modules_install install 

update your bootloader configuration to load new image.
# update-grub2 
* In case of a grub2 bootloader on a debian compatible box


Reboot & Enjoy new kernel

Initial Ram disk



Installer script probably created it for you.



Manual creation of initrd:

# cd /boot/ && mkinitramfs -v -o ./initrd-3.x.y 3.x.y 



Understanding

Start up Process




BIOS -> Bootloader -> Kernel

Bios



BIOS performs hardware-platform specific
 startup tasks



BIOS loads and executes the partition boot code
 from the designated boot device
(Phase 1 of a Linux bootloader)

Bootloader

Phase 1 loads phase 2 (the bulk of the boot loader code).

Some bootloaders use a phase called "Phase 1.5"
Without is some lard modern disks may not be 
fully available.

Decompress OS into memory and load it.

Prepare hardware and memory before calling
  'start_kernel()'

Kernel



'start_kernel()' perform OS setup
( Interrupts, Memory management, Drivers, etc )


Kernel spawns idle process, scheduler and init process


init process setup and load the user space world




Wait until next chapter To learn about startup process in nutshell 



End of Chapter 1


References: 

  • https://www.kernel.org/doc/
  • Linux Kernel Development (3rd Edition) ISBN: 978-0672329463
  • Linux kernel documentation (documents directory in source tree)

Contact me


Website :     www.lxsameer.com

IRC:     irc://irc.freenode.net/#5hit

Email:       lxsameer@gnu.org

twitter:          @lxsameer
Made with Slides.com