Introduction

Introduction

In 1991, a Finnish student named Linus Benedict Torvalds made the kernel of a now popular operating system. He released Linux version 0.01 on September 1991, and on February 1992, he licensed the kernel under the GPL license. The GNU General Public License (GPL) allows people to use, own, modify, and distribute the source code legally and free of charge. This permits the kernel to become very popular because anyone may download it for free. Now that anyone can make their own kernel, it may be helpful to know how to obtain, edit, configure, compile, and install the Linux kernel.
在1991年一个名为Linux Benedict Torvalds 的芬兰学生制作了如今最受欢迎的操作系统的内核。他在1991年发布了linux 0.01版本并且在1992年二月他为内核授权了GPL许可。GNU 通用公共许可允许人们合法的免费的使用,占有修改并且发布源代码。这项许可使得内核变得非常受欢迎因为所有人可以免费的下载他。现在每个人都可以制作他们自己的内核,这对如何获取,编辑,配置,编译,并且安装Linux kernel非常有帮助。

A kernel is the core of an operating system. The operating system is all of the programs that manages the hardware and allows users to run applications on a computer. The kernel controls the hardware and applications. Applications do not communicate with the hardware directly, instead they go to the kernel. In summary, software runs on the kernel and the kernel operates the hardware. Without a kernel, a computer is a useless object.
内核是一个操作系统的核心。操作系统是管理硬件的所有程序集合并且允许用户在电脑上运行应用。内核控制着硬件以及应用。应用不能直接与硬件进行通讯,但是可以与内核进行通讯。总而言之,软件的运行在内核上面内核控制着硬件。没有内核,电脑就会变得无用。

There are many reasons for a user to want to make their own kernel. Many users may want to make a kernel that only contains the code needed to run on their system. For instance, my kernel contains drivers for FireWire devices, but my computer lacks these ports. When the system boots up, time and RAM space is wasted on drivers for devices that my system does not have installed. If I wanted to streamline my kernel, I could make my own kernel that does not have FireWire drivers. As for another reason, a user may own a device with a special piece of hardware, but the kernel that came with their latest version of Ubuntu lacks the needed driver. This user could download the latest kernel (which is a few versions ahead of Ubuntu’s Linux kernels) and make their own kernel that has the needed driver. However, these are two of the most common reasons for users wanting to make their own Linux kernels.
一个用户有很多原因想要制作他自己的内核。许多用户想要制作他们操作系统需要的代码的内核,例如,我的内核包含防火墙设备驱动,但是我的计算机缺少这部分的设备。当计算机启动的时候时间以及内存被浪费在驱动我的系统不需要安装的设备上面。如果想要精简我的内核。我可以制作不包含防火墙驱动的内核。对于其他的原因,一个用户有一个特殊的硬件设备,但是来自Ununtu的最新版本的内核缺乏该设备的驱动。该用户可以下载最新的内核(在Ununtu Linux kernel 前面的几个版本)然后制作需要该驱动的内核。然而,这是用户构架内核的两个最常见的原因。

Before we download a kernel, we should discuss some important definitions and facts. The Linux kernel is a monolithic kernel. This means that the whole operating system is on the RAM reserved as kernel space. To clarify, the kernel is put on the RAM. The space used by the kernel is reserved for the kernel. Only the kernel may use the reserved kernel space. The kernel owns that space on the RAM until the system is shutdown. In contrast to kernel space, there is user space. User space is the space on the RAM that the user’s programs own. Applications like web browsers, video games, word processors, media players, the wallpaper, themes, etc. are all on the user space of the RAM. When an application is closed, any program may use the newly freed space. With kernel space, once the RAM space is taken, nothing else can have that space.
在下载内核之前,我们需要讨论几个重要的定义与事实。linux 内核是一个整体。这就意味着整个操作系统作为内核空间被保留在内存中。需要澄清的是内核被推入内存中,被内核使用的一部分空间是为内核保留的。只有内核才能使用被保留的内核空间。内核独占该部分空间直到关机。相对于内核空间的是用户空间,用户空间是用户程序独占的一部分内存空间。像浏览器,视频游戏,文字处理器,声音播放器,壁纸,主题等等之类的应用程序都在内存中的用户空间里面。当程序关闭,任何程序都可以使用新地空闲的空间。一旦在内存空间中开辟了内核空间,其他程序都不能再使用该空间。

The Linux kernel is also a preemptive multitasking kernel. This means that the kernel will pause some tasks to ensure that every application gets a chance to use the CPU. For instance, if an application is running but is waiting for some data, the kernel will put that application on hold and allow another program to use the newly freed CPU resources until the data arrives. Otherwise, the system would be wasting resources for tasks that are waiting for data or another program to execute. The kernel will force programs to wait for the CPU or stop using the CPU. Applications cannot unpause or use the CPU without the kernel allowing them to do so.
Linux 内核是抢占式多任务内核。这意味着内核会暂停一些任务确保所有的应用程序有使用cpu的机会。例如,如果一个程序正在运行但是需要等待一个数据,内核就会暂停处理该程序并允许其他程序使用新的空闲的cpu资源直到数据到来。不然的话系统会因为一些等待数据的任务或者其他需要执行的程序浪费资源。内核强迫应用程序等待CPU或者停止使用CPU,应用程序不能在没有kernel允许的情况下脱离中断或者使用CPU的资源。

The Linux kernel makes devices appear as files in the folder /dev. USB ports, for instance, are located in /dev/bus/usb. The hard-drive partitions are seen in /dev/disk/by-label. It is because of this feature that many people say “On Linux, everything is a file.”. If a user wanted to access data on their memory card, for example, they cannot access the data through these device files.
Linux内核可以使设备在文件夹/dev 中呈现为文件。例如 USB接口,位于/dev/bus/usb.硬盘驱动分区位于/dev/disk/by-lable。因为这个特点许多人称“Linux 一切皆文件”。例如如果用户想要接触在内存卡中的数据不能直接访问设备文件。

The Linux kernel is portable. Portability is one of the best features that makes Linux popular. Portability is the ability for the kernel to work on a wide variety of processors and systems. Some of the processor types that the kernel supports include Alpha, AMD, ARM, C6X, Intel, x86, Microblaze, MIPS, PowerPC, SPARC, UltraSPARC, etc. This is not a complete list.
Linux kernel 是便携的,便携性是使Linux受欢迎的一个很重要的原因。便携性使得内核可以工作在不同的处理器和系统上面。内核支持的一些处理器类型包括Alpha, AMD, C6X Intel, X86, Microblaze, MIPS, PowerPC, SPARC, UltraSPARC, etc. 这并不是完整的列表。

In the boot folder (/boot), users will see a “vmlinux” or a “vmlinuz” file. Both are compiled Linux kernels. The one that ends in a “z” is compressed. The “vm” stands for virtual memory. On systems with SPARC processors, users will see a zImage file instead. A small number of users may find a bzImage file; this is also a compressed Linux kernel. No matter which one a user owns, they are all bootable files that should not be changed unless the user knows what they are doing. Otherwise, their system can be made unbootable - the system will not turn on.
在启动文件夹(/boot)中,用户将会看到”vmlinux“或者“vmlinuz”的文件。他们都是编译后的Linux内核。以 “z”结尾的是压缩文件,“vm”代表虚拟内存。在有着SPARC处理器的系统中,用户会看到一个zimage文件。一小部分的用户会找到一个bzimage文件; 这些也是压缩过的Linux 内核。无论用户有哪一个,他们的所有启动文件都不能被改变除非用户知道他们的作用。否则操作系统会变得不可启动,操作系统将不会被打开。

Source code is the coding of the program. With source code, programmers can make changes to the kernel and see how the kernel works.
源代码是程序的编码。根据源码程序员可以改变内核并且了解内核是如何工作的。

Downloading the Kernel:

Now, that we understand more about the kernel, it is time to download the source code. Go to kernel.org and click the large download button. Once the download is finished, uncompress the downloaded file.
现在,我们了解了内核的很多内容,是时候下载源码,前往kernel.org 点击大大的下载按钮,一旦下载完成解压下载的文件。

For this article, I am using the source code for Linux kernel 3.9.4. All of the instructions in this article series are the same (or nearly the same) for all versions of the kernel.
这篇文章我使用的源代码是Linue kernel 3.9.4 。该系列文章的所有教程对于所有版本的内核都是相似的。