Compiling Linux Kernel, Step by Step

Home / Compiling Linux Kernel, Step by Step

Compiling Linux Kernel, Step by Step

November 24, 2015 | Article | 4 Comments

— This is old article I wrote on my old Nest —

Recently I was doing some linux kernel compilation for a course homework. I did it manually. Someone said it’s so complicated so I will share my guide for linux kernel compilation. Here I use the most recent kernel version as October 9th, 2012. The version is 3.6.1. All operations are performed on Ubuntu distribution.

Check for your current linux kernel version. You can do it by typing this on your terminal.

uname -r


cat /proc/version

Now download the latest kernel at website. In this tutorial we would use kernel version 3.6.1.


The reason I used linux-3.6.1.tar.xz instead of linux-3.6.1.tar.gz or linux-3.6.1.tar.bz2 is simply because of download size.We will following a convention or common practice of kernel building so we will use /usr/src directory. Make sure you move the source to /usr/src/ directory. Do that using root access.

Now extract the source code.

tar -Jxf linux-3.6.1.tar.xz
cd linux-3.6.1

In linux-3.6.1 folder there would be some files and folders. Some of them used as special purpose as:

arch – describe all architecture support by kernel
crypto – contain cryptographic implementation like AES, DES
drivers – all drivers modules (ID, SCSI, Ethernet device, Wireless)
fs – all filesystem implementation (ext4, FAT, NTFS)
net – all network protocol implementation (IPv4, IPv6, tcp, 802.11)

Now let’s configure our kernel source. The kernel compilation need a configuration file that contain lots of variable to help to understand what modules we need to compile. Specific kernel variable can be found at

We can take the old configuration as our basis for creating configuration file.

cp /boot/config- .config

Note that I use kernel so I copy the configuration file. It can be different in your system so match the version number with your current kernel version.

It’s a wise way to see what we can do by invoking make. A little help could give us hint.

make help

Now, to configure the config file, invoke

make menuconfig

After deciding what configuration you choose, It’s time for compilation. We will using generic way of compilation. It is the standard way provided by kernel and not platform oriented.

To compile the kernel and its modules we can invoke:


The process could be 1 to 4 hours depending on your system performance. For old machine like mine, it could be around 4 hours to do so. In this step the compiled kernel is stored in binary form as arc/x86/boot/bzImage file. Based on kernel headers it will compile the kernel modules (device driver, filesystem, network, etc) and generate .ko files which are kernel objects. These modules also called Loadable Kernel Modules (LKM).

Next, we will install kernel modules. to do so we can invoke.

make modules_install

This step will copy all kernel modules (*.ko) to /lib/modules/<version>/kernel/ folder.

Next we will install the kernel itself. We did that by invoking.

make install

This step copy the arch/x86/boot/bzImage to /boot folder and copy the .config to /boot/config-<latest version> and generate file.

Next we need to create initramfs file. What is iniramfs? You can find out here.

update-initramfs -c -k <version>

Here <version> can be 3.6.1 for this case.

Next we have to update the boot loader. I’m using GRUB so we have to invoke:


This command automatically probe the kernels in /boot folder and add the entries in configuration file, grub.cfg

Restart the system and look at your bootloader entry. choose the new kernel in bootloader. Now open terminal and invoke.

uname -r

The kernel version should be 3.6.1 now.


About Author

about author


A man who is obsessed to low level technology.

  1. Guide to FreeBSD Kernel Compilation - Xathrya.ID

    […] previous articles, we have discuss about how to compile kernel in Linux. So far we also have discuss about how to add our own system call. But how about other […]

  2. Install Kernel on Ubuntu - Xathrya.ID

    […] Unlike compiling kernel by yourself, Ubuntu provide you with precompiled kernel. It means, they compile the kernel for you. It might good for anyone who want to install new kernel effortlessly. However, the drawback for this precompiled kernel is the kernel is optimized for general machine. It want to address all the hardware and machine condition resulting in bigger size. Yes it can run on any machine, but might not be optimized. If you want to optimized the kernel for your machine in specific way, you might want to consider compiling kernel from source. […]

  3. Linux Kernel Packaging - Xathrya.ID

    […] target machine and install it. The package you use is built by someone else. So if you know how to build Linux kernel from source, how can you make a package from […]

  4. Add New System Call to Linux 3.6.1 - Xathrya.ID

    […] Please note that the overall kernel structure in linux prior to 3.2 is different to the newer one so adding syscall in 3.6.1 would has different technique than technique discussed earlier. But by the way, the step for adding system call is similiar to previous article (step by step compile kernel 3.6.1) […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Social Share Buttons and Icons powered by Ultimatelysocial