Reproduced in this blog Spirit Leap Cloud: the original link.
1. Write in front
The Linux operating system consists of four parts: (1) Kernel: The kernel is the core of an operating system. It is responsible for providing the operating environment for all other programs and services, allocating various hardware and software resources, managing the system's processes, memory, device drivers, files and network systems, and determining the performance and stability of the system. In the operating system, the kernel acts like a human brain. (2) Shell:shell is the user interface of the system, which provides an interface for users to interact with the kernel. (3) file system: is the organization method that files are stored on storage devices such as disks. Linux systems can support a variety of currently popular file systems such as EXT2, EXT3, FAT, FAT32, VFAT, and ISO9660. (4) Applications: For example: Text editor (vi, VIM, gedit, etc.), programming language, X Window (graphical interface), Office suite, Internet Tools, database, etc. among them, An important feature of Linux is the openness of its source code, and anyone can get any version of the Linux kernel source on https://www.kernel.org/. in the case of Windows operating systems, this is often a problem: After the system has been running for a period of time, it is becoming more and more slow, the system disk is getting more and more data, and the remaining capacity is becoming less. However, because Windows systems are not open source, we have no way of knowing the nature of the problem. In the Linux operating system, the use of the Linux kernel open source features, from the kernel source layer to locate the above problems, so that the Linux system can be customized, optimized to meet the functional and performance requirements. Next, take the linux-3.10.1 version of the kernel as an example, detailed description of how to get the Linux kernel source code, how to compile, install a Linux kernel of its own.
2. Compiling the installation environment
| Operating system |
Ubuntu 12.04 64-bit |
| Existing Linux kernel versions |
linux-3.2.0 |
| Kernel version to be compiled |
linux-3.10.1 |
Note: In the following description, all operations involved in the server Ubuntu 12.04 operating system environment are logged in and executed as root.
3. Get the Linux-3.10.1 kernel
Obtain the Linux-3.10.1 source code in the URL https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.1.tar.bz2 via the wget file Download tool and save it to the system/ home/work/kernel/directory (can also be saved to a different directory, but note that all the following operations please in this directory), and decompression. first install the wget and compile the kernel depends on the package: #apt-get install wget gcc libncurese5-dev get linux3-1.10 Source command line operation is as follows: (1) Switch to/ home/directory #cd/home/ (2) Create work directory and switch to work directory #mkdir work && CD work/ (3) Create the kernel directory and switch to the kernel directory #mkdir kernel && cd kernel/ (4) Obtain linux-3.10.1 kernel source package linux-3.10.1.tar.bz2 through wget #wget https://www.kernel.org/pub/linux/kernel/v3.x/ LINUX-3.10.1.TAR.BZ2 (5) Extract source package linux-3.10.1.tar.bz2 #tar –jxvf linux-3.10.1.tar.bz2–c/home/work/kernel/ (6) After decompression, in the current directory to get the linux-3.10.1 folder, as shown:
Note: If the Ubuntu 12.04 operating system is unable to get linux-3.10.1.tar.bz2 through wget for some reason (for example, no extranet), you can first pass through the https://www.kernel.org/pub/in the Windows system LINUX/KERNEL/V3.X/LINUX-3.10.1.TAR.BZ2 Download the source package and copy it to the/home/work/kernel/directory in the Ubuntu 12.04 system. 4. Compile and install the Linux-3.10.1 kernel
First switch to the linux-3.10.1 folder: #cd linux-3.10.1 configuration kernel: (1) Keep the source clean #make mrproper Note: This operation clears the kernel feature profile that was configured during the historical compilation process, so it is only done before the kernel is compiled for the first time, and in other cases, if you need to clear the residual data from the previous compilation process, simply use the following command: #make clean This command removes only intermediate and target files produced by the compilation process, and does not delete the historical configuration. (2) Setting the kernel function option #make Menuconfig executes the above command to display the graphical interface of the functional configuration in the character interface, such as:
According to the function prompts to configure the required features, this experiment with the default configuration, the keyboard by the left and right key to select the save configuration, to get the new kernel configuration file, such as:
Use the left and right buttons on the keyboard to confirm the configuration by using the ENTER key on the keyboard. (3) Compile kernel and module purge staged cache: #make clean compile kernel: #make bzimage or: #make bzimage–j4 Note: Where-j4 represents the number of simultaneous tasks compiled. If there are 4 CPU cores in the operating system, you can speed up the compilation by-j4. This compilation process is long, please wait patiently. Compile kernel module: # Make Modules (4) Install kernel module and kernel #make modules_install #make install here , The linux-3.10.1 kernel has been compiled and will then describe how to modify the default boot entry for the Ubuntu 12.04 operating system so that the system restarts and enters the newly compiled linux-3.10.1 kernel.
5. Configure boot-up entry
(1) Update the list of startup items, such as: #update-grub2
From there, you can see a list of all the kernels in the system and know that the newly compiled linux-3.10.1 is located in the first position in the list. (2) Modify the default boot menu configuration file/etc/default/grub #vim/etc/default/grub
, the value of Gtub_default determines when the system starts from the core list of kernel cores. If gtub_default=0, it means booting from the first kernel. Because the newly compiled linux-3.10.1 kernel is in the first position, the value of Gtub_default is modified to 0.
After saving, restart the system to view the latest boot menu, such as:
The system is started by default from the newly compiled "Ubuntu, with Linux 3.10.1" kernel. Note: If you want to boot from an older kernel, you can select an older kernel by selecting "Previous Linux Versions" from the previous version of the kernel list. (3) After viewing the newly compiled kernel into the system, use the following command to view the kernel version in the current system, such as: #uname-a
If you can see "Linux Ubuntu 3.10.1", it means that linux-3.10.1 's kernel has been compiled and installed successfully.
Linux kernel compilation