Linux Kernel entry, package Church (1)

Source: Internet
Author: User

BKJIA: Linux has become a buzzword in recent years. None of the students and IT professionals who boast computer proficiency have installed one or two Linux operating systems on their computers, and have consciously caught up with fashion. However, in Ubuntu or SUSE forums, there are often such conversations:

"What have you learned after studying Linux for so long ?"

"Oh, I am familiar with Linux installation, upgrade, and desktop beautification! You see, this is the latest Ubuntu version. The desktop is very beautiful !"

"……"

There is a famous saying in the Linux community: if you do not know what to do when you enter your operating system, you 'd better turn off your computer and there must be more important things waiting for you to do. To be honest, if you are not familiar with Linux commands, you cannot really learn Linux. On the other hand, Linux kernel is the most interesting part of the Linux operating system, although it is not available to users. Especially for developers, Linux kernel development is definitely the best place to hone. BKJIA editors have always believed that IT technology is widely used in foreign countries, and they have little access to UNIX-like systems and play with kernel development.

The following is an entry-level article written by Linux kernel developer Robert Love, known as the "package Church". We recommend that you do not miss out on students, Linux fans, developers, and system administrators who are interested in Linux kernel development. Of course, although the title is package-oriented, you may need certain Linux commands and C language basics.

The following is the body content:

Linux Kernel has always been regarded as the most difficult part to learn about Linux. I believe you have read many articles about the kernel, but ask yourself, how much have you mastered? This article will introduce from scratch what is regarded as a deep Linux kernel, which involves the download, compilation, installation, and kernel development of the kernel source code.

How to obtain the Linux kernel source code

To download the Linux kernel, you must go to the official website. The website provides two types of file downloads: one is the complete Linux kernel, and the other is the incremental kernel patch. They are all tar archive packages. Unless you need to use the old Linux kernel for special reasons, you should always upgrade to the latest version.

Use Git

Linux Kernel development team led by Linus started using Git version control system to manage Linux kernel a few years ago. For details, refer to: What is Git ?), The Git project is also created by Linus. Unlike traditional CVS, Git is distributed. Therefore, many developers may feel unfamiliar with its usage and workflow, however, I strongly recommend that you use Git to download and manage the Linux kernel source code.

You can use the following Git command to obtain the latest "push" version of the Linus kernel code tree:

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git

Run the following command to synchronize the latest status of your code tree with the Linus code tree:

$ git pull

Install kernel source code

The kernel package is in GNU zipgzip) and bzip2 format. The name of the file in the 'struct' format. y. z is the specific version of the kernel source code. After downloading it to the source code package, it is easy to extract and decompress it. If you download the bzip2 package, run:

$ tar xvjf linux-x.y.z.tar.bz2

If you download a gzip package, run:

$ tar xvzf linux-x.y.z.tar.gz

No matter which command is executed, the source code will be decompressed and extracted to the linux-x.y.z directory, if you use Git to download and manage the kernel source code, you do not need to download the tar package, you only need to run the git clone command to automatically download and decompress it.

The kernel source code is usually installed in/usr/src/linux, but it is best not to use this source code tree during development, because the kernel version compiled for your C library is usually linked here.

Application Patches

Linux Kernel developers will make their modifications into patches to share with others, and the patches are incremental. Incremental patching is an effective way to move from one kernel tree to another, you can upgrade the kernel without downloading the complete kernel package. This not only saves bandwidth, but also saves kernel upgrade time. Before applying the patch, go to the directory of the kernel source code tree and run:

$ patch –p1 < ../patch-x.y.z

Note that the patch package also has a clear version number. The version number here must be the same as the version number of the Linux kernel source code. When the kernel and patch version number are inconsistent, force application of the patch will cause unexpected consequences.

Kernel source code Tree Introduction

The kernel source code tree is divided into many directories, which contain many subdirectories. The top-level directories of the source code tree and their descriptions are listed in the table below.

Directory Description
Arch Source code of a specific architecture
Block Block I/O layer
Crypto Encryption API
Documentation Kernel source code documentation
Drivers Device Driver
Firmware Use the device firmware required by a driver
Fs VFS and independent File System
Include Kernel header
Init Kernel startup and initialization
Ipc Inter-process communication
Kernel Core subsystems, such as schedulers
Lib Assistant routine
Mm Memory Management Subsystem and VM
Net Network subsystem
Samples Sample Code
Scripts Script used to generate the kernel
Security Linux Security Module
Sound Sound Subsystem
Usr Early user space code called initramfs)
Tools Tools used for Linux development
Virt Virtualization infrastructure

There are still many files in the root directory of the source code tree. COPYING is the kernel license description file (gnu gpl v2), and CREDITS is the list of developers involved in the Linux kernel, MAINTAINERS lists individuals who maintain subsystems and drivers. Makefile is the basis of kernel Makefile.


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.