Kernel Compilation

Should have put this looooooooong before, but better late then never, so this one’s for all you BE people

Don’t mind the wordings, this is just a dump of my notes and outputs.

Step 1: Get kernel stable source code from kernel.org.we will get an archive  name something like linux-x.y.z.tar.bz2. here x indicates version no, y indicates whether kernel is stable or not and  z indicates kernel release number.if y is even then kernel is stable  otherwise unstable.we can download using command

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2

Step 2: untar a kernel archive in /usr/src(not necessarily) using

#tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src then go to directory where u have untarred the file cd /usr/src

Step 3: Check whether you have gcc or not: You can check it by following shell command which gcc if gcc is not installed,u can get it using command sudo apt-get install gcc

Step 4: Now you can start kernel configuring by typing any one of the command:

make menuconfig – Text based color menus,  radiolists & dialogs.  This option also useful on remote server if you wanna compile kernel  remotely.

make xconfig – X windows (Qt) based configuration tool,  works best under KDE desktop make gconfig – X windows (Gtk) based configuration tool,  works best under Gnome Dekstop.

For example make menuconfig command launches following screen:make menuconfig

You have to select different options as per your need.  Each configuration option has HELP button associated with it  so select help button to get help. finally select save an alternate configuration as .config file and exit.

Step 5: ~Modules Start compiling to create a compressed kernel image,

enter: make

Start compiling to kernel modules: make modules

Install kernel modules: make modules_install

Step 6 : ~Install kernel So far we have compiled kernel and installed kernel modules.  It is time to install kernel itself. make install

Step 7: Create an initrd image After this you will have to create initrd image of kernel. This can be done as follows : first goto /boot directory cd /boot create initrd image:

mkinitrd -o initrd.img-2.6.38.2 2.6.38.2

Many linux distros does not support this naturally,like Debian Wheezy does not suppport mkinitrd tools and so we have to use initramfs tools.

You can simply type following commands for this case: update-initramfs -k 2.6.38.2 -c and then update grub update-grub

Step 8:

This step includes actually modifying grub. This can be done by actually modifying  file grub.conf or using command update-grub

Step 9: reboot

Reboot from your new kernel.U can find out ur kernel version using: uname -a #Mine gave this sward@sward:~/module/hello_dev

$ uname -a Linux sward 2.6.38.2 #5 SMP Thu Apr 14 00:19:30 IST 2011 i686 GNU/Linux

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