How to compile the Linux kernel

libre software, mswl, mswl-cases, mswl-devtools

Hi at all!!!

Well we follow with the post related about Case studies!!!

Now with a little how-to for how we compile the Linux kernel in our machines, yeah the big question for all people who likes GNU/Linux… 😉

In our M.Sc. in Libre Software we had a lesson about this topic, and like we could see this task is more easily than at begginig seems.

Well first of all we must to download the sources of the Linux kernel that we like.
In the kernel web site we can find all Linux kernel, we have donwload any use the Full Source link.

Once we have our tar.bz2 kernel, we must create a folder without spaces, so in example, in our home folder we do:

> mkdir our_kernel_dir

inside in the oir new kernel folder we decompress the file with the kernel source code that previously we have donwnload.

> tar jvxf your_linux_kernel.tar.bz2

Before to do something, we must to install the utilities for compile our kernel if we haven’t.

> apt-get install build-essential kernel-package

once, we have to go inside our new linux folder (your_linux_kernel folder).
Here we must put:

> make menuconfig

Whit this instruction we configure the functionality of our new kernel, we can move around all options an select and deselect the ones that we like.
Once we have finished, we exit and save our configuration.

If we work under safe, we can begin from a kernel that runs in our system, for this, we have to do:

> cd /boot/kernels/

In this folder we get all of our kernels that runs in our system, we choose one and doing:

> cp kernel_choose ~/our_kernel_dir

then, if we chose this configuration, in the menuconfig window (make menuconfig) we must scroll
down and select the “Load an alternate configuration file” option, then we put our config file,
and the configration will be load for use this.

Once we have make our config and save the configuration, we can a file in our .config folder the file configuration.

Then we put in our terminal the next instruction which will compile our kernel using the
configuration specified previously:

> make bzImage && make modules && make modules_install

After this, we’ll have a file image in the folder images, and we’ll to copy in the boot kernel folder:

> cp arch/x86/boot/bzImage /boot/kernel-X-y-z.img

Now we must create our kernel .deb package (for Debian and Debian based distros like Ubuntu) for install later:

> make-kpkg –initrd –append-to-version=.XXXX kernel_image kernel_header

And for finish we need to install this using the dpkg command:

> dpkg -i kernel-X-y-z.deb

Could be neccesary that we can configure grub (or lilo) for use this kernel, but using this
way mentioned in class not would be neccesary.


M.Sc. Case studies Linux Kernel slides

And that’s all, see u my friends!!!!!


One thought on “How to compile the Linux kernel

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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