Download and start the Linux kernel source code

Source: Internet
Author: User

Kernel version

To compile the latest kernel, you must first download its source code. Before downloading the source code of the kernel, you need to know what you are looking. First, you have to ask your own question: Do you need a stable or test version of the kernel?

The second digit of a stable version kernel usually uses an even number. For example, 2.0.38, 2.2.15, 2.2.18, and 2.4.1 are considered "stable" kernels (because they contain 0, 2, 2, and 4, respectively ). If you want to try the test kernel, you usually need to find the kernel with the highest number and an odd number in the second digit of the version number. For example, 2.3.99 and 2.1.38 are both beta kernels (because they contain 3 and 1 ).

Kernel version history

The 2.2 series kernel is considered a newer and stable kernel. If "newer" and "stable" are what you want, the third digit of a version number is the highest 2.2 kernel (2.2.16 is the latest version ).

When the 2.2 series kernel is still under development, the 2.3 series has started. This series is a beta version of new and advanced features that will be integrated into the 2.4 stable series. The 2.3 series has reached 2.3.99 and its development has stopped. The developer has started 2.4.0. If you prefer to use the latest technology, you may want to use the latest 2.4 series kernel that you can find.

2.4 kernel warning information

Once a real 2.4 series kernel comes out (like 2.4.0), don't assume that the kernel is ready for use on a mission-critical system like a server. even though 2.4 is supposed to be a stable series, early 2.4 kernels are likely to be not quite up to snuff. as is often the case in the computer industry, the first version of anything can have fairly sizable bugs. while this may not be a problem if you're testing the kernel on your home workstation, it is a risk you may want to avoid when you machine provides valuable services to others.

Download Kernel

If you only want to compile a new version of the kernel that you have installed (for example, SMP support), you do not need to download any code-skip this part to continue the next screen.

You canHttp://www.kernel.org/pub/linux/kernelFind the kernel code. When you enter, you will find that the source code of the kernel is organized into multiple directories by kernel version (v2.2, v2.3, and so on. In each directory, you will find files labeled "linux-x.y.z.tar.gz" and "linux-x.y.z.tar.bz2 ". These are the source code of the Linux kernel. You will also see the document with "patch-x.y.z.gz" and "patch-x.y.z.bz2. These are patch packages used to update the complete kernel source code. If you want to compile a new kernel version, you need to download one of these "Linux" files.

Kernel unpacking

If you have downloaded a new kernel from kernel.org, it is time to unpack it.

First, CD/usr/src. If there is a "Linux" directory, change it to "Linux. Old" ("Mv Linux. Old" with root permission ).

Now, you can unlock the new kernel package. Still in the/usr/src directory, enter TAR xzvf/path/to/My/kernel-x.y.z.tar.gz or CAT/path/to/My/kernel-x.y.z.tar.bz2 | Bzip2-d | tar xvf -, the downloaded source code is compressed using gzip or Bzip2. After entering this command, the downloaded kernel source code will be released to a new "Linux" directory. Note-the full set of kernel source code usually occupies more than 50 MB space on the hard disk!

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

Linux kernel source code can be obtained in many ways. Generally, in the installed Linux system, the/usr/src/Linux directory contains the kernel source code. In addition, you can also download files from the Internet. After decompression, files are generally stored in the Linux directory. The kernel source code has many versions. The latest version is 2.2.14.
Many people have a fear of reading the Linux kernel. Of course, there are indeed a lot of difficulties to read such large and complex system code as the Linux kernel, but it is not as difficult as you think. Difficulties can be overcome with perseverance. Methods and tools are required for everything. The correct method can guide the work, and good tools can get twice the result with half the effort. The same is true for Linux kernel source code. Next, I will introduce my experience in reading the kernel source code. Finally, I will introduce a reading tool on the Windows platform.
If you want to read the source code smoothly, it is best to have a certain understanding of the source code knowledge in advance. For the Linux kernel source code, the basic requirements are: (1) Basic knowledge of the operating system; (2) familiar with the C language, it is best to have the Assembly language knowledge and gnu c's knowledge of Standard C extensions. In addition, you should know the overall distribution of the Linux kernel source code before reading. We know that modern operating systems generally consist of process management, memory management, file systems, drivers, and networks. You can see from the Linux kernel source code that each directory roughly corresponds to these aspects. The composition of the Linux kernel source code is as follows (assuming it is relative to the Linux directory ):
The arch subdirectory contains the core Code related to the hardware architecture supported by the core source code. For example, the X86 platform is i386.
The include directory contains most of the core include files. In addition, each supported architecture has a subdirectory.
Init this directory contains the core startup code.
Mm this directory contains all the memory management code. The Memory Management Code related to the specific hardware architecture is located in the arch/*/mm directory. For example, arch/i386/MM/fault. c corresponds to x86. All device drivers in the drivers system are located in this directory. It is further divided into several types of device drivers, each of which also has corresponding sub-directories, such as the driver of the Sound Card corresponds to drivers/sound.
IPC this directory contains the core inter-process communication code.
Modules this directory contains the modules that can be dynamically loaded.
File System code supported by FS Linux. Different file systems have different subdirectories. For example, ext2 file systems correspond to ext2 sub-directories.
The main core code of kernel. At the same time, the Code related to the processor structure is stored in the arch/*/kernel directory.
Net core network code. Each subdirectory corresponds to one aspect of the network.
LIB This directory contains the core library code. The library Code related to the processor structure is stored in the arch/*/lib/directory.
Scripts this directory contains the script file used to configure the core.
Documentation this directory is a reference for some documents.
After understanding the structure of the source code, you can start to read it. There are vertical and horizontal points for reading methods or sequences. The vertical direction is to follow the execution sequence of the program; the horizontal direction is to implement the module. This is not absolute, but often combined. For Linux source code, the startup code can follow the Linux Startup sequence step by step. The general process is as follows (taking the X86 platform as an example ):
. /Larch/i386/boot/bootsect. S -->. /larch/i386/boot/setup. S -->. /larch/i386/kernel/head. S -->. /init/main. start_kernel () in C (). For parts such as memory management, you can read and analyze them separately. My experience is: it is best to read the startup code in sequence and then read the topics, such as process and memory management. Each function should be implemented step by step. In fact, this is a repetitive process, and it is impossible to read it once.
As the saying goes: "to do good deeds, you must first sharpen your tools ". Reading complex programs like Linux core code is daunting. It is like a snowball that gets bigger and bigger. Reading a part of the core often uses several other related documents, and you will soon forget what you did. Therefore, it is impossible to have a good tool. Most of the fans are familiar with the window platform and are still commonly used in windows, so here I will introduce a tool software for Windows: Source insight. This is a free 30-day software that can be downloaded from www.sourcedyn.com. Installation is very simple. Just like other installation methods, double-click the Installation File Name and follow the prompts. After the installation is complete, you can start the program. This software is very simple to use and is a good tool for reading the source code. A brief introduction to its usage is as follows: first select new under the project menu, create a project, enter the project name, and then ask you to add the source code to be read (you can add the entire directory, the software analyzes the source code you add. After the analysis, you can read it. If you want to see the definition of a variable in the open reading file, first calibrate the light in the variable, and then click the corresponding option on the toolbar. The definition of the variable is displayed. You can also define and implement functions. Other functions are not mentioned here. If you are interested, you can install a source insight, which greatly improves the efficiency of reading the source code. How about it? Try it!
Luomei 201400, room 103, No. 19, Jiefang 1 village, Fengxian County, Shanghai)

Reference prompt:
Content Page: Linux kernel source code reading and tool introduction-Electronic Information Science and Technology paper
Prepared by: 66wen

Address: http://hi.baidu.com/try__again/blog/item/f218dba8b925aeb8ca130c19.html

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.