Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,808,174 Members 36,641 Now Online
XDA Developers Android and Mobile Development Forum

HOWTO: Compile your own kernel from source (WIP)

Tip us?
(Last edited by adrynalyne; 4th November 2011 at 06:48 PM.)
adrynalyne's Avatar
Recognized Developer - OP
Thanks Meter 5,671
Posts: 9,620
Join Date: Dec 2008
Angry HOWTO: Compile your own kernel from source (WIP)

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:

[chaos@oblivion ~]$

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/
If you like what I do, buy me a brew!
The Following 58 Users Say Thank You to adrynalyne For This Useful Post: [ Click to Expand ]
Thanks Meter 6
Posts: 61
Join Date: Jan 2011
Location: Jenison
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
Senior Member
Thanks Meter 7
Posts: 397
Join Date: Feb 2010
Location: Aurora, CO
Nice Adrynalyne

Sent from my Thunderbolt using XDA Premium App
(Last edited by jaskru; 18th April 2011 at 04:23 AM.)
jaskru's Avatar
Senior Member
Thanks Meter 11
Posts: 135
Join Date: May 2010
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.
Thanks Meter 5
Posts: 48
Join Date: Jul 2010
Thanks a lot, i was wondering about this too.

Sent from my ADR6400L using Tapatalk
Jaxidian's Avatar
Senior Member
Thanks Meter 218
Posts: 713
Join Date: Sep 2010
Location: Indianapolis
I'm really glad you've posted this. Time to play for those of us who are lazy (or busy)!
Senior Member
Thanks Meter 56
Posts: 526
Join Date: Feb 2010
awesome. I love the android community's open-ness. Not only do you post your source, but you tell people how to use it...
happimeal's Avatar
Senior Member
Thanks Meter 19
Posts: 239
Join Date: Mar 2011
Location: Lathrop
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!!!
Device : HTC Thunderbolt
Rom : BAMF Sense 3.0 RC4
The Following User Says Thank You to happimeal For This Useful Post: [ Click to Expand ]
LexusBrian400's Avatar
Senior Member
Thanks Meter 143
Posts: 1,128
Join Date: Mar 2010
Wow. Thank you for taking the time to write this up. Some of us really do appreciate it!
Beesley on IRC

Follow me on Twitter - TheRealBeesley
Cadillac Johnson
Senior Member
Thanks Meter 25
Posts: 163
Join Date: Mar 2011
You sir, are a gentleman and a scholar.

You really are amazing at what you do. Sometimes I wonder when you sleep..

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes