Linux Kernel Compilation

Source: Internet
Author: User
Article title: Linux Kernel Compilation details. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Kernel introduction
?? Kernel is the core of an operating system. It manages system processes, memory, device drivers, files, and network systems, and determines system performance and stability.
?? An important feature of Linux is its open source code. all kernel source programs can be found in/usr/src/linux. most application software is designed to comply with GPL, you can obtain the source code. Any software engineer in the world can add code that he thinks is excellent. one obvious benefit of this is the fast fixing of Linux Vulnerabilities and the use of the latest software technology. The Linux kernel is the most direct representative of these features.
?? Imagine what the source program with the kernel means to you? First, we can understand how the system works. By reading the source code, we can understand the operating principle of the system, which is simply a fantasy in Windows. Secondly, we can tailor the system to suit our own situation, so we need to re-compile the kernel. What is the situation in Windows? I believe that many people have been inexplicably confused by the increasing size of Windows. Again, we can modify the kernel to meet our own needs. What does this mean? Yes, it is equivalent to developing an operating system on your own, but most of the work is done. all you have to do is add and implement the functions you need. In Windows, unless you are the core technical staff of Microsoft, you don't have to worry about it.
  
Kernel version number
  
?? Since the Linux source program is completely open, anyone who follows GPL can modify the kernel and publish it to others. The development of Linux uses the market model (bazaar, which corresponds to the cathedral-church model). to ensure that these disordered development processes can be carried out in an orderly manner, Linux uses a dual-tree system. One tree is a stable tree, and the other is a non-stable tree or a development tree ). Some new features and experimental improvements will be implemented in the development tree first. If the improvements made in the development tree can also be applied to the stability tree, the same improvements will be made in the stability tree after tests in the development tree. Once the development tree has been sufficiently developed, the development tree will become a new stable tree. The development number is reflected in the source program version number. the Source program version number is in the form of x. y. z: for a stable tree, y is an even number. for a development tree, y is bigger than the corresponding stable tree (therefore, it is an odd number ). So far, the maximum version of the stability tree is 2.2.16. The latest release of Redhat7.0 adopts the 2.2.16 kernel, and the latest version of the development tree is 2.3.99. Maybe you have found and many websites have a kernel like 2.4.0-test9-pre7, but this is not the official version. Kernel updates allow access to the http://www.kernel.org.
  
Why re-compile the kernel?
  
?? Linux, as a free software, is constantly updated with the support of many enthusiasts. The new kernel fixes bugs in the old kernel and adds many new features. If you want to use these new features or customize a more efficient and stable kernel based on your system, you need to recompile the kernel.
?? Generally, the updated kernel supports more hardware, provides better process management capabilities, and runs faster and more stably. It also fixes many vulnerabilities found in earlier versions, it is necessary for Linux users to regularly upgrade and update the system kernel.
?? In order to correctly set the Kernel Compilation configuration options and compile only the code of the functions required by the system, the following four considerations are generally taken:
?? L self-compiled kernels run faster (with less code)
?? L The system will have more memory (the kernel part will not be exchanged to the virtual memory)
?? L Compilation of unnecessary functions into the kernel may increase the vulnerability exploited by system attackers
?? L compiling a function into a module is slower than compiling it into the kernel.
  
Kernel Compilation mode
  
?? To support a certain part of functions, such as the network, you can compile the corresponding part into the kernel (build-in) or compile the part into a module ), dynamic Call. If it is compiled into the kernel, the corresponding functions can be automatically supported when the kernel is started. this advantage is convenient and fast, and the machine starts once, you can use this feature. The disadvantage is that it will make the kernel huge. Whether you need this feature or not, it will exist. this is the common practice of Windows, we recommend that you compile the frequently used parts directly into the kernel, such as the NIC. If it is compiled into a module, the corresponding. o file will be generated and can be dynamically loaded during use. the advantage is that the kernel will not be too large, but you have to call these modules by yourself.
Kernel Compilation details
  
Obtain and update the new kernel version
  
?? Linux kernel version released on the official website is http://www.kernel.org, China's major ftp can generally find some versions of the kernel. The new version of the kernel is released in two forms: one is the complete kernel version, and the other is the patch file, that is, the patch. Compared with linux-2.4.0-test8.tar.bz2, the website has a large number of cores, which can be downloaded and used by users with fast network speeds. The internal kernel is generally a .tar.gz(.tgz.pdf file, which is a. bz2 file. the two files are compressed using gzip or bzip2, and need to be decompressed during use. Patch files are relatively small, generally only dozens of K to hundreds of K, and rarely exceed 1 M. users with slow network speeds can use patch files to upgrade the kernel. However, the patch file is for a specific version. you need to find your own version to use it.
?? The root permission is required to compile the kernel. the following operations are assumed that you are the root user. Copy the kernel you want to upgrade to/usr/src/(the following uses linux-2.4.0test8.tar.gz of the kernel 2.4.0test8as an example). The command is
  
# Cp linux-2.4.0test8.tar.gz/usr/src
  
?? Let's take a look at the current/usr/src content and notice that there is a linux symbolic link that points to a directory similar to a linux-2.2.14 (corresponding to the kernel version you are using now. First, delete the link:
  
# Cd/usr/src
# Rm-f linux
  
?? Decompress the downloaded source code file. If you download the .tar.gz (. tgz) file, use the following command:
  
# Tar-xzvf linux-2.4.0test8.tar.gz
  
?? If you download the. bz2 file, for example, linux-2.4.0test8.tar.bz2, use the following command
  
# Bzip2-d linux-2.4.0test8.tar.bz2
# Tar-xvf linux.2.4.0.test8.tar
  
?? Now let's take a look at the content under/usr/src. now you will find that there is a directory named linux, which contains the source program of the kernel we need to upgrade. Do you still remember the link named linux? The reason for using that link is to prevent the source program of the original kernel version from being overwritten during Kernel upgrade. We also need to handle the same problem:
  
# Mv linux linux-2.4.0test8
# Ln-s linux-2.4.0test8 linux
  
?? In this way, we also have a symbolic link named linux, so you don't have to worry about overwriting it in the future (maybe you will feel that it is unnecessary to re-establish a linux symbolic link, but in fact this is essential, which will be introduced below ). If you also download the patch file, such as the patch-2.4.0test8, you can perform the patch operation (assuming that the patch-2.4.0test8 is already in the/usr/src Directory, otherwise, you need to copy the file to/usr/src first ):
  
# Patch-p0 <patch-2.4.0test8
  
?? Now we have upgraded the kernel source program to the latest version. let's start the Kernel Compilation journey.
  
Preparations
  
?? The first command to be run is:
  
# Cd/usr/src/linux; make mrproper
  
?? This command ensures that the source code directory does not contain the correct. o file and file dependencies. This step can be omitted because we use the downloaded full source program package for compilation. If you use these source programs to compile the kernel multiple times, you 'd better run this command first.
?? Make sure that the asm, linux, and scsi links in the/usr/include/directory point to the source code of the kernel to be upgraded. They chain The Real include sub-directories required by the real Computer Architecture (i386 for PCs) under the source code directory. For example, asm points to/usr/src/linux/include/asm-i386 and so on. If you do not have these links, you must create them manually. follow these steps:
  
# Cd/usr/include/
# Rm-r asm linux scsi
# Ln-s/usr/src/linux/include/asm-i386 asm
# Ln-s/usr/src/linux/include/linux
# Ln-s/usr/src/linux/include/scsi
  
?? This is an important part of configuration. Delete the asm, linux, and scsi links under/usr/include, and then create a new link pointing to the directory with the same name under the new kernel source code directory. These header file directories contain the important header files required to ensure that the kernel is correctly compiled on the system. Now you should understand why we have created a link named linux in the "redundant" directory of/usr/src?
Configuration
  
?? The following kernel configuration process is cumbersome, but the proper configuration is directly related to Linux running in the future. it is necessary to know some of the main and frequently used options.
?? You can use one of the following commands to configure the kernel based on your needs and hobbies:
  
# Make config (the most traditional text-based configuration interface is not recommended)
# Make menuconfig (text menu-based configuration interface, recommended for character terminals)
# Make xconfig (the configuration interface based on the graphic window mode is recommended in Xwindow)
# Make oldconfig (if you only want to modify some small points based on the original kernel configuration, it will save a lot of trouble)
  
?? Among the three commands, the make xconfig interface is the most friendly. if you can use Xwindow, we recommend that you use this command. The interface is as follows:
  
  
Figure xconfig_main.jpg
  
?? If you cannot use Xwindow, use make menuconfig. Although the interface is worse than the above one, it is always much better than make config. for the make menuconfig interface:
  
Figure menuconfig_main.jpg
  
?? When you select the corresponding configuration, there are three options, which represent the following meanings:
Y -- compile this function into the kernel
N -- do not compile this function into the kernel
M -- compile this function into a module that can be dynamically inserted into the kernel as needed
?? If you are using make xconfig, you can select the corresponding option with the mouse. If you are using make menuconfig, you need to use the space key to select. You will find that
Related Article

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.