How to compile & recompile linux kernel in Ubuntu (generic way)

This is just a brief description, so read at your own risk.

I have tested & used it to compile & recompile (11th time till now) linux kernel. So it should be working. Please install a fresh install of Ubuntu.

I have assumed that you are working in Ubuntu 10.10 and using kernel version 2.6.37.3 . If you are using any other kernel version just replace 2.6.37.3 with your version.

You need some applications to compile the linux source code. You can install the required applications by the following code:

sudo apt-get update
sudo apt-get install build-essential initramfs-tools

If you have downloaded a compressed source like .tar.bz2, extract it first. You can extract it anywhere, you don’t need to put the source code in any specific folder.

To compile linux kernel for the first time, open a terminal & go to the source directory in the terminal using “cd”. The source directory should contain some folders like “arch”, “block”, “crypto”, etc. Now type the following commands:

mkdir ../linux-build
yes ''|make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build config
make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build
sudo make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build modules_install install
cd /boot
sudo mkinitramfs -o initrd.img-2.6.37.3 2.6.37.3
sudo update-grub

This will take a lot of time. This steps are required for the first time only.

Recompilation:

If you want to recompile & install it, you need to run the following commands in terminal from the source directory:

sudo rm /boot/*2.6.37.3*
make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build
sudo make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build modules_install install
cd /boot
sudo mkinitramfs -o initrd.img-2.6.37.3 2.6.37.3
sudo update-grub

This recompilation part should take a lot less time than the previous. After each compilation and recompilation, you must restart Ubuntu to see the changes.

If you are editing the same system call function again and again, then you can do the following (it will reduce the compile time a lot, changes in 3rd line only, no modules_install step):

sudo rm /boot/*2.6.37.3*
make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build
sudo make --jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build install
cd /boot
sudo mkinitramfs -o initrd.img-2.6.37.3 2.6.37.3
sudo update-grub

It will reduce the compile time to 5 min or less.

-Enzam

P.S. : To add a system call, follow here.

Advertisements

11 responses to “How to compile & recompile linux kernel in Ubuntu (generic way)

  1. Pingback: How to add a system call in linux kernel (Ubuntu OS) | Enzam's Blog

  2. Pingback: How to add a system call in linux kernel (Ubuntu OS) | Enzam's Life

  3. I’ve been browsing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me.
    In my view, if all web owners and bloggers made good content as you did, the internet
    will be much more useful than ever before.

  4. Pingback: how to compile linux kernel modules in ubuntu | PDF Finder

  5. For compiling first time i stuck at the third step
    make –jobs=`getconf _NPROCESSORS_ONLN` O=../linux-build
    it was getting some error
    “make[2]: *** No rule to make target ‘kernal/mysystemcalls.os’ , needed by ‘kernal/built- in.o’ . stop.
    make[1]:***[kernal] Error 2
    make: *** [sub-make] Error 2

  6. These tips furthermore labored to get a good way to notice that many people online have the similar fervor similar to acquire to recognize large amount additional with this in mind problem.

  7. Howdy! This really is my personal 1st trip to your site! Were a staff regarding volunteers as well as beginning a whole new effort in a local community inside same specific niche market. Your site supplied us helpful data to work in. You might have carried out some sort of excellent work!

Want to share your views? Please do 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