Compile the kernel in linux

Source: Internet
Author: User

Compile the kernel in linux. Now we will learn how to compile the kernel in Linux. Before compiling, you must know why to compile the kernel and what the kernel is like. The Linux operating system consists of four parts: utility set; shell; system program and Runtime Library; the role of the kernel -- it can provide a runtime environment for all other programs and services, allocating various hardware and software resources in the operating system, the kernel function is similar to the human brain. Since LInux is an open-source software with open source code, it provides convenience for us to customize the kernel. in Windows, we are often troubled by many problems, for example, after using our operating system for a period of time, we will find that the running speed is getting slower and the disk partition capacity of the operating system is growing. However, because windows is not open-source, we don't know why. However, in linux, all kernel code is open, so as long as we have enough capacity, we can customize this kernel to meet our own needs. This customization includes: our hardware features are strong, including many additional devices. However, the linux operating system used does not currently support these features and devices. Therefore, you can obtain these features through kernel compilation. In turn, if our hardware functions are weak, but we do not need many features and hardware support in linux, you can also remove these features through kernel customization and compilation to enhance our system performance. Or prevent some errors and vulnerabilities. In short, because the linux system provides us with customized kernel conditions (Open Source), we should be able to use these conditions to create an operating system suitable for our own needs. Now, we know why we need to compile the kernel. The following describes how to compile the kernel: 1. Before compiling, we need to know the hardware and software information of the current computer. The/proc directory stores the running value of the current memory. In fact, this folder is not the data in the hard disk, but the data in the memory, therefore, we can obtain the hardware environment information of the current system through the files in this directory. Such as cpu, memory, file system, pci device, version, and other information. As you can see, we can see cpuinfo meminfo pci filesystem partition version and other information through the less command. next, start to get the kernel source code package: the kernel source code package is obtained in two cases. The first is to obtain the kernel source code of the current system from the system installation disc, most of the kernel packages are in rpm format. The second type is the higher kernel code in www.kernel.org.pdf. The majority of the kernel packages is tar.gz. We will discuss the first method to obtain from the disc-the second disc needs to be mounted. We just saw this 37M package is the kernel source package if not installed, we use rpm-ihv kernel-source-2.4.20-8.i386.rpm command to install, if successful, the package will be installed in the/usr/src directory, generate a linux-2.4.20 folder, which is the content of the kernel source code 3. however, the above steps require the support of some underlying systems, that is, the corresponding software packages must be installed in the system beforehand. Otherwise, the kernel package cannot be installed, or an error will be prompted in the next step after the kernel package is installed. These software includes: gcc ncurses make dev86 glibc-kernheader cpp binutils. Now let's check it first -- use rpm-qa | grep packagename, it seems that the software has been installed, So execute rpm-ihv kernel-source-2.4.20-8.i386.rpm on the line. 4. after the installation is complete, we have the kernel source code file in the/usr/src directory: The two directories shown just now are actually one directory, another linked file points to the linux-2.4.20 directory, so cd/usr/src cd linux-2.4.20 5. compile now: (because the compilation methods of the 2.4 and 2.6 kernels are not the same, we will discuss the two cases separately.) Compile the 2.4 kernel: Compile the 2.6 kernel first step: make mrproper -- clear the kernel source code tree (clear junk information) make mrproper Step 2: make menuconfig -- configure the kernel and kernel module make menuconfig (related Commands include make config, make oldconfig, and make xconfig) (Interactive Q & A) (generated through the old kernel) (compiled on the GUI) we recommend that you use make menuconfig to configure the kernel most conveniently. After the menu, in principle, you can change it with confidence. If you are not sure about the menu, do not modify it. Otherwise, compilation may fail. In addition, if * appears during the change, it indicates that the compilation enters the kernel-starts M with the system startup, and the compilation enters the module-does not start with the system startup, call as needed (some unimportant external drivers can be compiled as the kernel module, so that the kernel will not be too large and will not affect the startup speed, does not compile into the kernel or compile into the module ---- give up this function. if the system does not support this function, you can discard the following changes. As you can see, I have changed a lot. I don't know whether the compilation is successful. Note that NTFS must be compiled into the kernel instead of a module. If you are unsure, do not modify it. Also, I think kernel compilation is very random and the compilation fails normally, for example, my current changes cannot be guaranteed to be successful. After the configuration is complete, a name is configured and saved. When you exit, you are prompted to save the configuration. Here, the configuration is saved as a name. the configuration file of config, whether we use make menuconfig, make oldconfig, make xconfig, and make config, will eventually generate this. config file. All subsequent operations will be performed based on the content in the file, which stores the changes we just made and can be less. config check Step 3: make dep -- Build dependency Step 4: make bzImage -- generate new kernel make (2.6 kernel simplifies the three steps on the left to make) Step 5: make modules -- it takes a long time to compile the kernel module! This step is the longest execution time. Step 6: make modules_install -- install the kernel module Step 7: make install -- install the kernel (all the compilation steps are best performed on the Character interface, otherwise the speed will be slow in the graphic interface) in addition, after completing all the steps mentioned above, check whether there are any errors, that is, whether the words "error" are displayed, if any error is displayed, It will be returned to make mrproper. You can see that all our steps have been completed just now, and no error is reported. It seems that the situation is good. But don't be happy too early. Further tests should be conducted: 1. vi/etc/grub. conf ----> check whether a new kernel startup Item is generated. (just now, custom is the new kernel boot item. This step is okay.) 2. ls/boot ----> check whether there is a new kernel file generated by vmlinuz (just now with custom, this is the new kernel file, and this step is no problem). Now it's almost done, but you have to restart it, check whether a new kernel can start the system with a new boot item: It seems that the system can be started, but the sendmail service is slow and should be shut down in advance, however, this will not affect the startup of the new kernel. Wait... Now that I have successfully entered the system, run uname-a to check whether we are using the new kernel: the kernel is 2.4.20-8 custom, which proves that the kernel has been compiled successfully! Success!

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.