Re-compile the kernel guide

Source: Internet
Author: User
Article Title: re-compile the kernel guide. 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.
Abstract: An important feature of Linux is its open 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 technologies. The Linux kernel is the most direct representative of these features.
An important feature of Linux is its open 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 technologies. The Linux kernel is the most direct representative of these features.
  
Why do we need to upgrade the kernel?
  
As its name literally means, the Linux kernel undertakes the most core task of the Linux operating system and is the arbitration of other programs and hardware in the running process: it needs to manage the memory of all processes to ensure that they can get the same time slot of the processor. It also provides interfaces between programs and hardware.
  
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.
  
Generally, the kernel version serial number is represented by three numbers, for example, 2.2.14. the higher the version number, the stronger the function. The version number is divided into two series: one is the product series, named after an even number, such as 1.2.x, 2.0.x, and 2.2.x. the version number is stable and has been thoroughly tested; the other is the development and testing series, which is named after an odd number for testing the latest functions. it is not recommended for beginners and production.
  
Later in this article, we will introduce the steps, concepts, precautions, and more documents used for Kernel upgrade from the kernel 2.0.34 to 2.2.14, respectively, the italics in the text are directly input commands.
  
Kernel configuration and compilation
  
Linux currently supports the following CPU types: x86, arm, DEC Alpha, SUN iSCSI, M68000, MIPS, and PowerPC. the above types already include CPU models used by most users. During installation and configuration, Linux automatically identifies these models.
  
The first command to be run is: # cd/usr/src/linux; make mrproper. Make sure that there are no correct. o files and file dependencies in the source code directory.
  
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 (text-based most traditional configuration interface)
  
# Make menuconfig (text menu-based configuration interface)
  
# Make xconfig (graphical window mode-based configuration interface)
  
# Make oldconfig (if you only want to modify some small points based on the original kernel configuration, it will save a lot of trouble)
  
During configuration, the default values can be used for most options. only a small part of options need to be selected based on the user's needs. For example, if you want the kernel to support a file system with DOS partitions, you need to select FAT or dossystem for the file system. if the system is equipped with a Nic or PCMCIA card, select the type of the corresponding card in the network configuration.
  
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.
  
Compile some functional code that is far away from the other parts of the core and is not frequently used into a loadable module. This helps reduce the length of the kernel and reduce the memory consumed by the kernel, this feature simplifies the impact on the kernel when the corresponding environment changes. Many functions can be processed in this way, such as Nic support and file system support such as FAT.
  
After the kernel is configured, the dependency and integrity of the kernel source code file need to be checked and compiled. at this time, ensure that the gcc version used by the system is above the gcc-2.7.2:
  
# Make dep (ensure that key files are in the correct location)
  
# Make clean (make sure all related files are in the latest version)
  
# Make zImage (compile the compressed kernel)
  
When the kernel supports many peripherals and functions, the kernel may become very large. in this case, you can compile the large kernel:
  
# Make bzImage
  
The compilation time is related to factors such as hardware conditions and kernel configuration of the machine. taking the player 300 in 64 MB memory as an example, it takes about 20 minutes to compile the kernel at a time. The obtained kernel is located in the/usr/src/linux/arch/i386/boot directory. assume that your CPU is x86.
  
If you select a loadable module, compile the selected module after compiling the kernel:
  
# Make module)
  
# Make module-install (transfer the compiled module to the standard system location)
  
The standard Directory of the module in the system is located in/lib/modules/x. y. z, followed by x. y. z is the version number. for security reasons, it is best to back up/lib/modules before running # make modules-install. A module is usually a file with the. o extension. use the command # lsmod to list the modules in the current kernel.
  
Software Download and unpacking
  
Select a relatively fast and authoritative site to download the latest kernel source code package. for example, if conditions permit, you can download the latest kernel source code package from the following site:
  
Ftp://sunsite.unc.edu/pub/linux/kernel
  
Linux users in China can download from the following sites:
  
Http://studio.openunix.org
  
Http://www.clinuxworld.com
  
.
  
The core code of the Linux system is stored in the directory/usr/src/linux. In fact, this directory is a link pointing to the current core version directory, for example, if the current version is 2.0.34, the actual directory of the core should be:/usr/src/linux-2.0.34. The directory in the newly downloaded kernel is linux. in this way, uninstalling the package directly under/usr/src will overwrite the original kernel directory. Therefore, it is safe to delete the link linux first, then unpackage, rename, and re-link.
  
Before unpacking, make sure that there is no linux directory under the/usr/src directory, or you do not want to keep this directory.
  
In addition, with the enhancement of Linux kernel functions and support for more peripherals, the file package increases. The size of the latest stable version 2.2.14 kernel package is about 14 MB, however, in actual decompression and compilation processes, the free space of the partition in the/usr/src directory must be greater than 60 MB.
  
Enable new kernel
  
Copy the compiled new kernel to the system directory/boot, for example
  
# Cp/usr/src/linux/arch/i386/boot/zImage/boot/zImage-2.2.14
  
Then, edit the system boot configuration file/etc/lilo. replace the existing option with the new kernel option and give it a label. remember to keep the original kernel and related options at this time, in this way, you do not have to worry about the failure of the upgrade and the machine cannot start. at least you can use the old kernel to boot your computer. Save and edit and exit. remember to run the command # lilo to update the system boot image so that the modification to lilo. conf will take effect.
  
After the machine is restarted, press the "Tab" key at the LILO prompt, and the new kernel option is displayed.
  
For Linux versions after Chinese version in China, several major versions are carried out in the kernel, such as Xteam Linux on the surfing platform and Bluepoint Linux on the blue site, therefore, if you use these release versions to upgrade the kernel according to the above steps, it will lead to failure of localization, unstable system operation, and other consequences. You need to wait for the manufacturer to release a new kernel package, download it from the download site specified by the manufacturer, and upgrade it according to the instructions in the package.
  
  
  
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.