Compiling the Linux kernel

Posted on enero 3, 2011

0


Well now, for the people that always have been wanting to know, I’m going to explain how to compile and customize a kernel using Ubuntu linux.

First in order to do not break the one we use, we could use another one from kernel.org which is the place where are located the changes that the linux kernel had had.

Once we have downloaded it, for example I just got the linux-2.6.36.2, we untar it using the “tar -xvwf” command and then we enter into the uncompressed file directory.

$ tar -xvwf linux-2.6.36.2.tar.bz2
$ cd linux-2.6.36.2.tar.bz2

Then we are going to configure our kernel, but before doing this we have to install the following things:

$ sudo apt-get install build-essential kernel-package

In my case here I also needed to install the libncurses5-dev package, cause I got the following error

So we also do the $ sudo apt-get install libncurses5-dev

Once we have this we are ready to configure the kernel, so to do that once we are inside the linux-2.6.36.2 uncompressed file we type

$ make menuconfig

Here we configure the modules we want our kernel to include, or any configuration we want. So we will see a list of modules, and we’ll be able to configure them pressing space bar to select if we want them not to be in the kernel, to be part as a module, or to be always part of the kernel. For example below I am in the networking support modules and I configured that I wanted the Bluetooth to be part of the kernel as a module (M), but the amateur radio support is built-in part of the kernel (*)

then we compile it with

$ make bzImage && make modules && make modules_install

and after this we got our .img of the kernel which we we’ll have to move to the /boot directory. Finally we will have to create the initrd file, which is the one that preload the block device modules, to do this we used the command

$ mkinitramfs -o ./initrd.img-2.6.25.4

Also if we are in a debian or ubuntu environment we could use this command instead of the ones above to directly compile and make a .deb package to install it.

$ make-kpkg -initrd -append-to-version=.XXXX kernel_image

Tagged: ,
Posted in: Uncategorized