Skip to content

Compiling Linux kernel and running it using QEMU

September 22, 2012

As a part of my final year project i had to compile and test the linux kernel. This post is how i did it.

Kernel Compilation is a task whose difficulty varies according to the way you want to mould the kernel. If a simple kernel with a default setting is required then the steps are simple. But if the kernel has to be customized in a perticulat way then compilation can be a head ache.OK, lets get into bussiness


The nesseary tools required for compiling the kernel are

  1. gcc
  2. GNU make

They can be installed using apt-get in ubuntu. To test the compiled kernel we need QEMU.It can be downloaded using the command

$ sudo apt-get install qemu-system-i386

1.Downloading the linux kernel

First step of getting the kernel compiled is to get the kernel itself.It can be downloaded from I am using the long term stable kernel version 2.6.32 which was the kernel of ubuntu 10.04.

Lets begin by creating a working directory.

$mkdir linux

$cd linux

The kernel can be downloaded using wget


2.Extracting the kernel

The downloaded kernel is in compressed state, it is extracted using the tar command and cd in to the kernel directory

$tar xjf linux-

$cd linux-

3.Configuring the Kernel

The next step is to configure the kernel. To configure the kernel , the .config file is needed to be generated. A simple method to generate the .config file is to copy the configure file of the working Linux operating system.. For Ubuntu, it will be in the /boot/ directory. Copy this file to ~/linux/linux- An another method is to use make to generate a default config file using the command

$make defconfig

After generating the .config file, it has to be configured according to the setting we need on the compiled kernel. To make kernel with no windows, without any GUI, we can use menuconfig. Run the following command and a blue screen will appear. Select the settings you need on the kernel and unmark the things which are not required.Then save the config file

$make menuconfig

4.Make the kernel

The next is to make the kernel, it will take several minutes to complete. Use the following commands

$make all

$make modules

when it is finised , a file bzImage will be created in linux- if you are using the i386 architecure. This file is the binary image of the compiled kernel and it is used to run the kernel.

5.Create the initial file system

Even though the file sytems will be compiled alone the kernel, an initial file sytem has to be created which will be present in the RAM to run the kernel. To make this inital ram filesystem, mkinitrd is used. In ubuntu mkinitramfs is used instead of that

$cd ~/linux/linux-

$mkinitramfs -o initrd.img-

6.Run the kernel in QEMU

QEMU which stands for ‘Quick EMUlater’ is an excellent emulator. It can emulate different processer architecture with high speed on the PC itself. To run the kerenl use the following command,-kernel denotes the kernel image which is going to execute, -initrd reprresents the initial ram filesystem and -m shows how much memory in RAM is allocated for running qemu.

$qemu-system-i386 -kernel bzImage -initrd initrd.img- -m 512M

Tada.. you gets your running kernel


From → Linux

  1. You are amazing! post in your blog are very helpfull and i will read your news more times. Cheers for this info. Your blog and info are very important. Thanks again for your time for us 🙂

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

%d bloggers like this: