The general steps to build linux kernel is:

1. Preparation

2. Kernel configuration

3. Make and install kernel image and modules

Here I use linux-3.4.28 on Ubuntu 12.04 LTS to make a demo.

The cmd to check kernel rev is:

$ uname --kernel-release

Preparation

1. Download kernel source from: www.kernel.org.

Linux kernel used odd minor version numbers to denote development releases and even minor version numbers to denote stable releases.

For example, Linux 2.3 is a development family, and Linux 2.4 is the stable release family that Linux 2.3 matures into.

2. Unzip the package.

$ tar -jxvf linux-3.4.28.tar.bz2

3. Install basic build environment.

$ sudo apt-get install build-essential libncurses5-dev

Build-essential generally includes the gcc/g++ compilers, libraries and some other utils.


4. Use a root authority and begin following steps.

The 5th step in preparation and make/install operation will modify content of /usr, so use the root authority.

$ su root

Root's password is required. If it's not set, you should do this before su root.

$ sudo passwd root

Below cmd those are started with # have an authority as root. 

5. Conventional doings.

  a. Move linux source code to a certain location.

# mv linux-3.4.28 /usr/src/

  b. Make a symbolic link for linux source.

# cd /usr/src
# ln
-s linux-3.4.28 linux

This step seems needless, why we do this?

Assume you write an automation to build kernel of 2.6, and 3.2 after one year, then 3.4 again, you have to change the automation script and check semantic error carefully.

After making a soft link, you can simply change the link to other kernel release folder. It's much easier.

What we do here is exactly abstract what changes.

  c. Make symbolic links for other requisite source folders.

# cd /usr/include/
# rm
-rf asm-generic linux scsi # ln -s /usr/src/linux/include/asm-generic asm-generic # ln -s /usr/src/linux/include/linux linux # ln -s /usr/src/linux/include/scsi scsi

Kernel configuration

Configure what function you want to build into your kernel. And generate .config at this folder for makefile.

Hidden files are started with a '.' in Linux.

Enter the directory of /usr/src/linux.

Clean previous configuration, unnecessary object files and dependancy first.

# make mrproper

Then there're several ways to configure kernel. Just use one of them and get .config.

a. xconfig

# make xconfig

If unable to find QT.

$ sudo apt-get install libqt3-mt-dev

b. character menu

# make menuconfig

If you have installed libncurses5-dev, there should be no error.

c. gtk+

# make gconfig

If unable to find gtk+

$ sudo apt-get install libglade2-dev

d. traditional

(not recommended)

# make config

e. use old config and generate .config

# make oldconfig

Make and install kernel image and modules

1. Clean previous object files.

# make clean

2. Read .config and accordingly build a dependance tree.

# make dep

3. Make kernel image.

# make bzImage

-------------------------------------------------

Below steps are optional unless you choose Yes

for  Enable loadable module support

or the option CONFIG_MODULES=y.

4. Make modules.

# make modules

5. Install modules.

# make modules_install

6. Locate modules.

# depmod -a

-------------------------------------------------

7. Install kernel.

If you use GRUB to manage your boot. Just

# make install

If you use LILO or something else, here's a reference. But I've not tried it by meself.

Useful link

Detail steps in Chinese:

http://wenku.baidu.com/view/e5ddb3020740be1e650e9ad8.html

Downgrade kernel:

(There're some more geek shows here)

http://forum.ubuntu.org.cn/viewtopic.php?p=2514710

 

 posted on 2013-02-05 18:30  turtle_fly  阅读(857)  评论(0编辑  收藏  举报