You are on page 1of 4

How to compile the Linux kernel

Download the source code for desire kernel version.


Go to https://www.kernel.org/ Select the appropriate version and download. Use the directory /usr/src/ untar the source files in the /usr/src/ directory
cd /usr/src/ tar -xvjf linux-3.9.3.tar.gz

Change directory to kernel we want to compile


cd linux-3.9.3

Or
cd /usr/src/linux-3.9.3

Install the gcc compiler


This may be installed already in Ubuntu but if not we can install with this command.
sudo apt-get gcc

Configure the kernel


Linux kernel has many configuration options depending on the processor and other hardware. menuconfig is one of the tool for configuring the kernel, we need to install libncurses package to work with menucofig.
sudo apt-get install libncurses5-dev

*sudo is for super user access


make menuconfig

This command will open a menu for configuration of kernel options. We can navigate around to see different options and to edit a part use space-bar for enable and disabling the driver/module. Save the configuration file as .config. Since make command use .config file to build the kernel. We can load the already configured file files form the source code directory and then save as .config. We can also load the configuration file for which current system's running kernel was built form /boot/ directory. Copy and rename configuration file with the following command.
cp source-file destination-directory/[new-Name-optional] cp /boot/config-3.x.y.etc /usr/src/linux-3.9.3/.config

Build the kernel


make command will build the kernel if gcc is already installed.
sudo make

This command will start compiling the kernel and will take some time depend on the configuration and hardware you are using for compiling.

Install the New Kernel


Not tested yet

Boot Linux to the new Kernel


Not tested yet

How to cross compile the Linux kernel for ARM


Download the source code for desire kernel version.
We can download source code form http://www.friendlyarm.net/ for friendlyARM smart210 (mini210v2). We also have the source code in the CDs supplied with the code. Make a directory where you like lets choose home directory. You can use one of the commands to go to home directory.
cd cd ~/ cd /home/user-name/

Make a new directory with name of friendlyARM in home directory. Copy and untar the source files in the ~/friendlyARM/ directory.
Mkdir ~/friendlyARM/ cd ~/friendlyARM/ tar -xvjf linux-3.9.3.tar.gz

Change directory to kernel source which we want to compile.


cd linux-3.9.3

Or
cd ~/friendlyARM/linux-3.9.3

Install the gcc compiler


For compiling the kernel for arm platform the arm-linux-gcc compiler is also needed. We can download this form friendlyARM or the get it from the CD which have be shipped with the kit. Then we need to untar the package in suitable directory. Lets use the /usr/local/arm We may need to make a new directory if arm is not already existed.
mkdir /usr/local/arm

untar the arm-linux-gcc packge for the CD to the /usr/local/arm/. After untar browse the bin directory. In our case make it something like this /usr/local/arm/4_5_1/bin. Original directory structure was different we change for simplicity. /usr/local/arm/opt/frindlyARM/arm/4.5.1/bin to /usr/local/arm/4_5_1/bin Note: 4.5.1 was changed to 4_5_1 because sometimes . does not work correctly in terminal.

Now we need to export this this directory to $PATH so whenever we need this command arm-linux-gcc system can find the command. For this go to home directory and open the .bashrc file.
cd gedit .bashrc

Or
gedit ~/.bashrc

A text editor will open the file, Now scroll to the end of the file and append with following text.
export PATH=$PATH:/usr/local/arm/4_5_1/bin

Save and close the file. Exit and re-launch the terminal so that above command can take effect. Compiler for arm-linux has been installed.

Configure the kernel


Linux kernel has many configuration options depending on the processor and other hardware. menuconfig is one of the tool for configuring the kernel, we need to install libncurses package to work with menucofig.
sudo apt-get install libncurses5-dev *sudo is for super user access make menuconfig

This command will open a menu for configuration of kernel options. We can navigate around to see different options and to edit a part use space-bar for enable and disabling the driver/module. Save the configuration file as .config. Since make command use .config file to build the kernel. We can load the already configured file files form the source code directory and then save as .config. There are different configuration files are available for different systems use one which is suitable for your system.
mini210_android_defconfig mini210_linux_defconfig mini210-tvp5150_android_defconfig mini210-tvp5150_linux_defconfig mini210_ubuntu_defconfig

e.g.
cp mini210_linux_defconfig .config

Build the kernel


make command will build the kernel if gcc is already installed.

sudo make zImage

This command will start compiling the kernel and will take some time depend on the configuration and hardware you are using for compiling.

Install the New Kernel Boot Linux to the new Kernel

You might also like