Linux is a Operating System kernel and user space applications will create different distributions like CentOS, Ubuntu, Mint, Kali around this kernel. Kernel can be downloaded freely and used without any license fee. In this tutorial we will learn how to download Linux Kernel from kernel.org and compiling with GCC . An the last step installing or upgrading the kernel.
Linux是一个操作系统内核,用户空间应用程序将围绕该内核创建不同的发行版,如CentOS,Ubuntu,Mint和Kali。 内核可以免费下载和使用,无需任何许可费用。 在本教程中,我们将学习如何从kernel.org下载Linux Kernel以及如何使用GCC进行编译。 安装或升级内核的最后一步。
下载内核源代码 (Download Kernel Source Code)
Kernel source code is originally maintained in the kernel.org . But there are a lot of mirrors which serve to download the kernel source code. In this step we will download kernel source code by using wget
command like below. Current stable version of the Linux Kernel is 4.17.6
.
内核源代码最初在kernel.org中维护。 但是有很多镜像可以用来下载内核源代码。 在这一步中,我们将使用如下的wget
命令下载内核源代码。 Linux内核的当前稳定版本是4.17.6
。
$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.6.tar.xz
安装GCC和其他要求(Install GCC and Other Requirements)
GCC is most popular compiler for C and C++ source codes in Linux environment. We will use GCC in order to compile and create binaries for Linux Kernel . We will install gcc
with the following command for different distributions.
GCC是Linux环境中最流行的C和C ++源代码编译器。 我们将使用GCC来为Linux内核编译和创建二进制文件。 我们将使用以下命令为不同的发行版安装gcc
。
Ubunt,Debian,Mint,Kali: (Ubunt, Debian, Mint, Kali:)
$ sudo apt-get install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
CentOS,Fedora: (CentOS, Fedora:)
$ sudo yum install git fakeroot build-essential ncurses-dev xz-utils libssl-dev bc flex libelf-dev bison
提取内核源代码(Extract Kernel Source Code)
Kernel source code has a lot of text type data which may take a lot of disk space and bandwith. So Linux Kernel code is distributed in compressed formats like xz
, tar.gz
etc. We download Kernel Source code as xz
so we need to extract source code with the tar
command like below.
内核源代码包含大量文本类型数据,这可能会占用大量磁盘空间和带宽。 因此Linux内核代码以xz
, tar.gz
等压缩格式分发。我们将内核源代码下载为xz
因此我们需要使用tar
命令提取源代码,如下所示。
$ tar xvf linux-4.17.6.tar.xz
创建编译配置 (Create Compile Configuration)
We will create a configuration which will used to compile required modules and kernel features.
我们将创建一个配置,该配置将用于编译所需的模块和内核功能。
$ make menuconfig
用GCC编译Linux内核源代码并制作(Compile Linux Kernel Source Code with GCC and Make)
We will use make
command wich will run compile process according to the configuration we have created with the make menuconfig
command.
我们将使用make
命令,它将根据我们使用make menuconfig
命令创建的配置运行编译过程。
$ make
更快地编译Linux内核(Compile Linux Kernel Faster)
By default make command will make compile with a single thread . But as modern CPU’s have multiple cores which gives ability to use multiple threads we can run parallel compile with -j
option of the make
command. In this case we specify 4 threads
默认情况下,make命令将使用单个线程进行编译。 但是由于现代CPU具有多个内核,这些内核可以使用多个线程,因此我们可以使用make
命令的-j
选项运行并行编译。 在这种情况下,我们指定4个线程
$ make -j 4