Compile a kernel using UbuntuLinux

Source: Internet
Author: User
Compile a kernel using the UbuntuLinux method-general Linux technology-Linux programming and kernel information. The following is a detailed description. Each Linux release has its own dedicated tool to build a custom kernel. this article describes how to compile the kernel on the Ubuntu platform, and how to obtain the latest and unmodified kernel source code from www.kernel.org (also called vanilla kernel) to build a custom kernel, in this way, you can use your own kernel instead of the kernel of the release version, and also introduce how to patch the kernel to facilitate the addition of new features.

I have tested the following work on Ubuntu 6.10 Server ("Edgy Eft") and Ubuntu 6.06 Desktop ("Dapper Drake.

The first thing I want to talk about is that the way to build a custom kernel in the article is not the only one. There are many other ways, but this is just a method I used. I cannot guarantee that no problems will occur after use.

1. Preparations

We recommend that you use the root user to perform all the following steps. If you have not created a root login password, run the following command:
Sudo passwd root

Then, log in as root:
Su

If you want to replace the root user with a general user, remember to input sudo before all the commands in this article. For example, when I run
Apt-get update

You need to run the following command to replace it.
Sudo apt-get update

1.1/bin/sh ("Edgy Eft") on Ubuntu 6.10 ")
In Ubuntu 6.10,/bin/sh is a character link to/bin/dash by default. when you compile the software source code,/bin/dash may still be faulty. at least I have encountered some problems. so I linked/bin/sh to/bin/bash.

If you use Ubuntu 6.10, you can run:
Rm-f/bin/sh
Ln-s/bin/bash/bin/sh

2 install necessary software packages (prepare for Kernel compilation)

First, we upgrade the software (Package) Library:
Apt-get update

Then we install all required software packages:
Apt-get install kernel-package libncurses5-dev fakeroot wget bzip2

3. Download the kernel source code

Next, download the required kernel to the/usr/src directory (go to www.kernel.org to download the required kernel version, for example. linux-2.6.18.1tar.bz2 (you can download all the 2.6 kernel: http://www.kernel.org/pub/linux/kernel/v2.6/ from here ). then download to the/usr/src directory:
Cd/usr/src
Wget http://www.kernel.org/pub/linux/... ux-2.6.18.1.tar.bz2

Decompress the kernel source code and create a linux character link pointing to the kernel source code directory:
Tar xjf linux-2.6.18.1.tar.bz2
Ln-s linux-2.6.18.1 linux
Cd/usr/src/linux

4. patch the kernel source code (optional)

Sometimes your default kernel does not support new devices. You need to install a new driver. or you need to use virtual technologies or other advanced technologies, which are not supported by these existing kernels. in this case, you need to patch the kernel source code (of course the patch has been released ..)

Now, let us assume that you have downloaded the patch (in the following example, we call patch.bz2) to/usr/src. Run the following command to directly patch the kernel source code (your user must be in the/usr/src/linux directory ):
Bzip2-dc/usr/src/patch.bz2 | patch-p1 -- dry-run
Bzip2-dc/usr/src/patch.bz2 | patch-p1

The first command is used for testing and has no impact on the kernel. If no error is displayed, you can run the second command to patch the kernel. If the first command is incorrect, proceed with this operation!

You can also install patches through kernel prepatches. for example, if you need a feature that is only available in 2.6.19-rc4, the official complete kernel version is not yet released, and the patch-2.6.19-rc4.biz2 has been released. you can call this patch to the kernel source code of 2.6.18, but do not set it to 2.6.18.1 or 2.6.18.2. this rule is noted in the following web page: http://kernel.org/patchtypes/pre.html

Prepatches is equivalent to the test release in linux; they are located in the archive test directory, and we can patch the previous full release (version number in three parts) using patch (1) tool (for example, 2.6.12-rc4 prepatch can only patch 2.6.11 kernel source code, rather than 2.6.11.10 .)

So if you want to compile 2.6.19-rc4 kernel, you must download 2.6.18 (http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2) in Step 3.1 to replace 2.6.18.1 kernel source code!

The following describes how to patch 2.6.18 with 2.6.19-rc4:
Cd/usr/src
Wget http://www.kernel.org/pub/linux/... atch-2.6.19-rc4.bz2
Cd/usr/src/linux
Bzip2-dc/usr/src/patch-2.6.19-rc4.bz2 | patch-p1 -- dry-run
Bzip2-dc/usr/src/patch-2.6.19-rc4.bz2 | patch-p1

5. Configure the kernel

It is a good idea to use the current working Kernel configuration file as the basis for the new Kernel configuration file. Therefore, we copy the existing configuration file to/usr/src/linux:
Cp/boot/config-'uname-R'./. config

Then run
Make menuconfig

Then we can see the Configuration menu of the kernel. Move the green cursor to the line Load an Alternate Configuration File and select the. config File (including the Configuration of the current working kernel) as the Configuration File:



(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // linux.chinaitlab.com/UploadFiles_7565/200612/20061201103900359.png'); ">


(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // linux.chinaitlab.com/UploadFiles_7565/200612/20061201103900618.png'); ">



Then, go to the kernel configuration menu and select the desired function. After completing the configuration, select Exit and answer the following question (Do you wish to save your new kernel configuration? Do you want to save the new Kernel configuration ?), Select Yes:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.