Thursday 7 April 2016

Linux Kernel configuration and build

Linux Kernel configuration and build  


In Last chapter we have got overview of Architecture of Linux kernel and basic subsystems of Linux kernel. Now question arise from where to Download the kernel and how to build a Linux Kernel. After Downloading the Linux Kernel we need to build Linux Kernel, If we want to install Linux kernel in any hardware . Before installing Linux Kernel in any hardware and booting,we need to do some kernel configuration according to that device. We will discuss various way of  kernel configuration in this tutorial.

Download Linux Kernel


Linux kernel is open source and maintained by Linux kernel community . Every member of this community keep on working for enhancement of Kernel. This community maintain kernel repository on https://www.kernel.org/ . Every contributor of Linux kernel updates there changes on this mainline kernel so that other can get the updated kernel. We can get Latest kernel from this site anytime without paying any charge for it.
Download kernel from:

https://www.kernel.org
From Kernel.org we get tar file of Linux kernel. So after downloading Linux kernel  first job we need to do is to uncompress the Kernel by following command 
tar -xvf kernel_name.tar.xz 

Linux kernel Configuration

Kernel which we get from Kernel.org is generic kernel which we can build and install on different hardware platform . But before building Linux kernel we need to customize or configure the Linux kernel or we can say we need to do some platform specific changes to port our linux kernel on our hardware platform.
For configuring the kernel go into root directory of Kernel uncompressed folder and use one of the following way of Kernel Configuration.
Linux kernel provides us various way of configuring the Linux Kernel. Following are  some method to configure the Linux kernel
1) make config
2) make menuconfig
3) make defconfig 
1) make config
make config is a character based questions answers session method in which kernel start asking character based question like whether to enable a particular setting or not. We have to answer according to our requirement.[caption id="attachment_31" align="alignnone" width="1336"] make config[/caption]
make config
2) make menuconfig Linux provides a graphical view of configuring kernel , menuconfig. when we run above command we get a GUI on which we can see multiple kernel settings.For having this GUI we should have ncurses library installed in our system . If we haven't installed in our system we might come across following error
make_menuconfig
How to fix ncurses Error:download and install following library to fix this issue
  1. $ sudo apt-get update
  2. $ sudo apt-get install libncurses5-dev
After doing above step make menu config will run successfully and below screen appear.
menuconfig_1
3) make defconfig
When we download kernel form kernel.org , kernel comes with default configuration which is set by kernel maintainer. To create this default configuration give below command
$ make defconfig

How to Build a Linux Kernel

 As now we have done the basic setting required for building Linux kernel. Now final step is to build the Linux kernel. Below are the steps to build Linux kernel
1) Go to root directory of uncompressed kernel.
2) Give Make command
$ make
If our PC has multi core then we can use below command to improve the speed of kernel build .make -j4 here specify number of cores available present plus 1. by using this command we are forcing to use all the available cores for building the Kernel.



You Can also watch our Linux Device Drivers Video Tutorials for Better understanding

No comments:

Post a Comment