Remove All Ads from XDA

HOWTO: Compile your own kernel from source (WIP)

10,950 posts
Thanks Meter: 6,568
By adrynalyne, Inactive Recognized Developer on 18th April 2011, 04:06 AM
Post Reply Email Thread
Updated. You can find an easier to use and more up to date version here:

Hey folks,

Figured I would throw this out there for those who may want to know just what goes into compiling a kernel, and possibly, doing it themselves. This is a WIP, and is more about how to compile, than how to make changes to source or customize your own kernel.


Linux. For this case, we will assume Ubuntu 10.10, 64 bit. This can be done with 32 bit as well, but you will need a different cross compiler.
Download | Ubuntu

dsixda's kitchen. So that we can easily split and repack kernels.

Source. You can use mine. Its fairly heavily tweaked, and compiles without any modifcations.

A cross compiler toolchain. Because I use 64 bit linux, I use a 64 bit cross compiler.
(Credit adwinp from XDA)


First, we install Ubuntu. I won't be going through that, however. So, assuming we have Ubuntu already installed, and working, we are ready to dive right in.

First, we need a tool Ubuntu does not install by default. This is called git. From a terminal:

Getting Source Code
sudo apt-get install git

Once git is installed, we can grab our source. Using a terminal:

[[email protected] ~]$

mkdir android
cd android
mkdir kernels
cd kernels
git clone git://
Depending on your connection, this could take a while.

This will create a kernel_htc-mecha directory under your /home/username/android/kernels folder.

Grabbing Toolchain
Now we will grab the toolchain. Download it, decompress it, and just leave it in the 4.4.4 directory. Move it to your android directory.

Grabbing and setting up the kitchen
Download the kitchen from the link given above, and decompress it. Rename it to kitchen. Move it to your android directory. Then from a terminal:

cd ~/android/kitchen
chmod 755 menu
This installs the kitchen and starts it up. Now the first thing we need to do is setup a working directory. Take a rom, any rom, and copy it to the ogiinal_update folder inside the kitchen. You can then setup your working folder.

Inside the working folder, delete boot.img. Grab, one of say, my kernels, and extract it. Take boot.img from the extracted contents and copy to the kitchen.

To split the initramfs (ramdisk) from the kernel, simply choose 0 from the menu, then 20. Hitting w will extract the kernel to a BOOT-EXTRACTED directory inside the kitchen (not working folder). Inside that folder, you will find the ramdisk and a zImage. The zImage is the kernel. We will stop there for now.

Compiling the kernel
First, we move to the kernel directory.

cd ~/android/kernels/kernel_htc-mecha
To compile the kernel, first we must have a configuration file ready. To do this:

make mecha-lte_defconfig
It will configure the system for compiling.

Now to compile the kernel:


make -j5 ARCH=arm CROSS_COMPILE=/home/username/android/4.4.4/bin/arm-none-eabi-

Where username is your, well, username and the number after j (thats a J) is the number of cpus +1.

Depending on the speed of your system. a zImage should be created within 3-30 minutes.

Packing the kernel

The zImage will be located under ~/android/kernels/kernel_htc-mecha/arch/arm/boot directory.

We will copy that zImage into the BOOT-EXTRACTED directory of the kitchen. Then, back at our menu for the kitchen, we hit 'b' to build the kernel. Within seconds, there is a new boot.img inside our Working folder. Now, remember my kernel package you downloaded? Well, time to kang the installer! The directory you unzipped contains a META-INF and system directory. You need both of those. Copy the boot.img in with those two folders.

So, our directory layout currently looks like so:

We need one more file, the wifi driver, from our compiled source.

Under ~/android/kernels/kernel_htc-mecha/drivers/net/wireless/bcm4329_204 you will find a file named bcm4329.ko. Copy this into system/lib of your new kernels installer directory.

Zip these three folders and give it a name. Now its ready to install.

A couple of things of note:

You almost always have to match the wifi driver with the kernel.

make clean mrproper will clean all the precompiled and temp fikes out of your source. This is recommended when making major source changes. Don't forget to remake your configuration after running it though.


There may be some files not found errors. Please be careful with these commands.

If the files not found are and/or, take a look below.

sudo ln -s /usr/lib/ /usr/lib/
sudo ln -s /usr/lib/ /usr/lib/
The Following 59 Users Say Thank You to adrynalyne For This Useful Post: [ View ] Gift adrynalyne Ad-Free
18th April 2011, 04:10 AM |#2  
Flag Jenison
Thanks Meter: 6
Very nice write up, I've been looking into this for a while so its nice someone put it all together in one thread.

Sent from my NookColor using XDA Premium App
18th April 2011, 04:14 AM |#3  
Senior Member
Flag Aurora, CO
Thanks Meter: 7
Nice Adrynalyne

Sent from my Thunderbolt using XDA Premium App
18th April 2011, 04:19 AM |#4  
jaskru's Avatar
Senior Member
Thanks Meter: 14
I love learning new things... Thanks for sharing knowledge!

For those of us that play in a Virtual Box, any notes about issues that may come up? I used to dual boot but decided that a vb is more time efficient for me.
18th April 2011, 04:21 AM |#5  
Thanks Meter: 5
Thanks a lot, i was wondering about this too.

Sent from my ADR6400L using Tapatalk
18th April 2011, 04:27 AM |#6  
Jaxidian's Avatar
Senior Member
Flag Indianapolis
Thanks Meter: 276
I'm really glad you've posted this. Time to play for those of us who are lazy (or busy)!
18th April 2011, 04:37 AM |#7  
Senior Member
Thanks Meter: 76
awesome. I love the android community's open-ness. Not only do you post your source, but you tell people how to use it...
18th April 2011, 05:00 AM |#8  
happimeal's Avatar
Senior Member
Flag Manteca
Thanks Meter: 30
Thank you so much for spending the time to write this, i have been googleing this and your write up is the best ive found.

I know this is a work in progress, but some ideas for future revisions, at least things that I have been wondering,

The files tweaked for overclocking, undervolting, and maybe some explanations on what goes into this.

Important files and maybe files we should not touch, (if there are any).

Just things I have wondered.

Thank you again!!!
The Following User Says Thank You to happimeal For This Useful Post: [ View ] Gift happimeal Ad-Free
18th April 2011, 05:18 AM |#9  
LexusBrian400's Avatar
Senior Member
Thanks Meter: 198
Wow. Thank you for taking the time to write this up. Some of us really do appreciate it!
18th April 2011, 05:43 AM |#10  
Senior Member
Thanks Meter: 25
You sir, are a gentleman and a scholar.

You really are amazing at what you do. Sometimes I wonder when you sleep..
18th April 2011, 06:25 AM |#11  
Chickasha, OK
Thanks Meter: 10
Uggg, I am running Ubuntu 10.10 64bit.

I have followed this step by step but I am getting the following error:

/home/scott/android/4.4.4/bin/../libexec/gcc/arm-none-eabi/4.4.4/cc1: error while loading shared libraries: cannot open shared object file: No such file or directory
make[2]: *** [scripts/mod/empty.o] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2
make: INTERNAL: Exiting with 3 jobserver tokens available; should be 2!

What package am I missing? I apt-get installed libcloog-ppl0.

Any help is appreciated.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes