Linux compile core detailed explanation
August 04, 2002 03:52:44
Introduction to the kernel core is the core of an operating system. It is responsible for managing system processes, memory, equipment drivers, files, and network systems, which determines the performance and stability of the system. An important feature of LINUX is the disclosure of its source code, all kernel source programs can be found under / usr / src / linux, most of the applications are also designed with GPL, you can get The corresponding source code code. Any software engineer in the world can add ourselves to the code, and an obvious advantage that is triggered is the rapidness of Linux repair vulnerabilities and the utilization of the latest software technology. The LINUX kernel is the most direct representative of these features. Imagine, what does the source of the kernel do? First, we can understand how the system works. Through the password source code, we can understand the working principle of the system, which is simply in Windows. Second, we can make our own system, and customize the system that is suitable for your own, so you need to recompile the kernel. What is the situation under Windows? I believe that many people have been more and more huge windows. Again, we can modify the kernel to meet your needs. what does this mean? Yes, it is equivalent to developing an operating system, but most of the work is already done, what you have to do is to increase and implement the features you need. Under Windows, unless you are a Microsoft's core technician, you don't want to think.
Nuclear version number
Since Linux's source program is completely disclosed, anyone can modify and publish it to others as long as the GPL is followed. The development of Linux is a market model (Bazaar, corresponding to CATHEDRAL - church model - corresponding), in order to ensure that these disruptible development processes can be done in an orderly manner, Linux uses a double tree system. A tree is a stable tree, and the other tree is a unsteable tree or a development tree. Some new features, experimental improvements, etc. will be carried out in the development tree. If the improvements made in the development tree can also be applied to stabilizing trees, then the same improvements will be performed in the stabilizing tree after the test is tested in the development tree. Once the development tree has been sufficiently developing, the development tree will become a new stable tree. The number of developments is reflected in the version number of the source program; the source version number is XYZ: For stabilization tree, Y is an even number; for the development tree, Y is more stable than the corresponding stable tree (therefore, odd) ). So far, the highest version of the stable tree is 2.2.16, the latest release of RedHat7.0 is the 2.2.16 core; the latest version of the development tree is 2.3.99. Maybe you have found that there are 2.4.0-Test9-Pre7 kernels on the multi-site, but this is not a formal version. Update of the kernel version can be accessed http://www.kernel.org.
Why recompile the kernel
LINUX as a free software, with the support of the majority of enthusiasts, the kernel version is constantly updated. The new core revised the BUG of the old kernel and added many new features. If the user wants to use these new features, or want to customize a more efficient and more stable kernel according to your own system, you need to recompile the kernel. Usually, the updated kernel will support more hardware, with better process management capabilities, faster running, more stable, and generally repair many vulnerabilities found in the old release, etc., often choose upgrade updates The system kernel is the necessary operational content of the Linux user. In order to properly set the kernel compilation configuration option, only the code required by the system needs, generally have the following four considerations: the Lord of the Customized kernel is faster (with less code) The Slowly compile the kernel compilation mode than the mode of compiling into the kernel.
In order to increase support for a part of the function, such as the network, you can compile the corresponding part into the kernel (build-in), or the part can be compiled into a module, dynamically called. If you compile into the kernel, you can automatically support the function of the corresponding part when the kernel is started, this advantage is convenient, fast, the machine is started, you can use this part of the function; the shortcomings will make the kernel huge No matter if you need this part of the function, it will exist, this is the tricks used to Windows. It is recommended to use the part to use directly to the kernel, such as the network card. If you compile into a module, you will generate a corresponding .o file, you can dynamically load it when you are using, the advantage is that you won't make the kernel, the disadvantage is that you have to call these modules. Nuclear compilation details
Get and update of new version kernels
The official website published by the Linux core version is http://www.kernel.org, and some version of the kernel can generally be found on major FTPs in China. There are two forms of the release of the new version of the kernel, one is a complete kernel version, and the other is the Patch file, that is, a patch. The complete kernel version is relatively large, such as Linux-2.4.0-test8.tar.bz2 has more than 18m, and users fast online can be downloaded. The complete core version is generally .tar.gz (.tgz) file or .bz2 file, both are files using Gzip or Bzip2, and need to decompress when using. The PATCH file is smaller, usually only tens of k to a few hundred k, very little more than 1m, and the speed of the network speed can use the patch file to upgrade the kernel. But the Patch file is for a specific version, you need to find your own version to use. Compile the kernel requires root permissions, the following operations assume that you are root users. Please copy you need to upgrade the kernel to / usr / src / down (hereinafter taken as an example of Linux-2.4.0 Test8.tar.gz of 2.4.0 Test8), command to
#CP Linux-2.4.0 Test8.tar.gz / USR / SRC
Let's take the content of the current / usr / src, note that there is a Linux symbolic link, pointing to a directory similar to Linux-2.2.14 (corresponding to the kernel version number you are using now). First delete this link:
#CD / USR / SRC #RM-F Linux
now decompress the source program file we downloaded. If the downloaded .tar.gz (.tgz) file, use the following command: #tar -xzvf linux-2.4.0test8.tar.gz
If you download it is .bz2 file, such as 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 us look at the content under / usr / src, you will find that there is a directory called Linux, which is the source program we need to upgrade the version of the kernel. Remember the link named Linux? The reason for using that link is to prevent the source process of the original version of the original version of the kernel inadvertently. We also need to deal with:
#mv Linux Linux-2.4.0test8 #LN-S Linux-2.4.0 Test8 Linux
In this way, we also have a symbolic link called Linux, you don't have to worry about override it later (maybe you will feel that the symbolic link to re-establish Linux is not necessary, but actually this is essential, below Will be an introduction). If you have also downloaded the Patch file, such as Patch-2.4.0Test8, you can perform Patch action (below, Patch-2.4.0Test8 is already in / usr / src directory, otherwise you need to copy this file to / usr Under / SRC):
#patch -p0 Now, we have upgraded the kernel source to the latest version, let's start the kernel compilation journey. Ready to work The first command to run is: #CD / USR / SRC / Linux; Make MRPROPER This command ensures that there is no incorrect .o file and the mutual dependence of the file in the source code directory. This step can be omitted because we use the complete source of origin of the just downloaded. And if you have used these source programs many times, then you should first run this command. Make sure the ASM, Linux, and SCSIs in the / usr / include / directory is to point to the kernel source code to be upgraded. They have a true Include subdirectory required to chain to the true INCLUDE subdirectories required by the computer architecture (for the PC for the PC. Such as: ASM points / usr / src / linux / include / asm-i386, etc. If there is no such link, you need to manually create, follow the steps below: # CD / usr / include / # rm -r ASM Linux SCSI # ln -s / usr / src / linux / include / asm-i386 ASM # ln -s / usr / src / linux / include / linux linux # ln -s / usr / src / linux / include / SCSI SCSI This is a very important part of the configuration. After deleting the ASM, Linux, and SCSI links under / usr / include link, create a new link to the directory of the same name in the new kernel source code directory. These header files contain important header files that ensure that the kernel is properly compiled. Now you should understand why we have created a link to Linux under / usr / src under the / usr / src? Configure The next kernel configuration process is more cumbersome, but the appropriate configuration is directly related to the running Linux running, it is necessary to understand some of the main and often used options. Configuring the kernel can use one of the following commands as needed: #make config (Based on the most traditional configuration interface, not recommended) #make menuconfig (Recommended Underline Configuration Interface Based on Text Menu, Recommended Under Terminal Terminal) #make XConfig (Recommended Underline Based on Graphic Window Mode, Recommended User Under XWindow #Make oldconfig (if you only want to modify some small places on the basis of the original kernel configuration, you will save a lot of trouble). In these three commands, make Xconfig's interface is the most friendly. If you can use xwindow, then It is recommended that you use this command, the interface is as follows: Figure XCONFIG_MAIN.JPG If you can't use XWindow, then use make menuconfig. Although the interface is better than the above, it is much better than Make Config, and the picture below is the interface of Make MenuConfig: MenuConfig_main.jpg When choosing the corresponding configuration, there are three options, which represent the meaning of the other: Y - Compile this function into the kernel N-- Do not compile the function into the kernel M - compile this function into need when needed Modules that are dynamically inserted into the kernel If you use Make Xconfig, you can select the corresponding option using the mouse. If you use Make MenuConfig, you need to use the space bar to choose. You will find that there is a bracket before every option, but some are a bracket, and there is a parenthery. When you use the space bar to choose, you can find that in the middle brackets, either "*", and the angle of "*" and "m" indicate that the former corresponds to the kernel, either compile into the kernel The latter is more choice, and can be compiled into a module. The content of parentheses is to select an item in several options provided. In the process of compiling the kernel, the most annoying thing is that this step is working, and many newers don't know how to choose these options. In fact, most of the options can use their default values, only small parts need to be selected according to different needs. The principle of choice is to compile the partial function code that is far from other partial relationships of the kernel, and is used to use the portion of the function code to be loaded to reduce the length of the kernel, reduce the memory consumption of kernel, simplify the corresponding environment changes. The impact of the kernel; do not choose the function; close to the kernel, and often use the partial function code that is used directly into the kernel. Let us introduce the commonly used options. 1. Code Maturity Level Options Code maturity level. There is only one item: prompt for development and / or ibplete code, if you want to test the functionality that is still in the experimental phase, such as khttpd, IPv6, etc., you must choose the item as y; otherwise you can choose it N. 2. Loadable Module Support Support for modules. There are three items in this: . Set Version Information On All Module Symbols: You can don't choose it. Keernel Module Loader: Let the kernel have its own ability to load the required module when starting, and suggest it. 3. Processor type and features CPU type. There are quite a lot, and it is not one of them. Several as follows: processor family: Select the CPU type according to your own situation. HuiGh Memory Support: Support for large capacity memory. You can support 4G, 64G, usually not available. Math Emulation: Coprocessor Simulation. The coordinator is the pet in the 386 era, and now it is no longer available. MTTR Support: MTTR support. Optional. Symmetric Multi-Processing Support: Symmetric multi-processing support. Unless you are rich in multiple CPUs, you don't have to choose. 4. General setup here is the most common attribute settings. This part of the content is very large, usually using the default settings. Let's introduce some of the options that are often used: NetWorking Support: Network Support. Must, no NIC also suggest you choose. PCI Support: PCI support. If the card of the PCI is used, it is certain. PCI Access Mode: PCI Access Mode. Alternative to BIOS, Direct and Any, choose ANY. SUPPORT for Hot-Pluggabel Devices: Hot-swap equipment support. Support is not too good, you can not choose. PCMCIA / Cardbus Support: PCMCIA / Cardbus support. There is a PCMCIA. Tem V IPC programctl support: The above three is the process processing / IPC call, mainly in both SYSTEM V and BSD. If you are not using BSD, follow the default. ProPower Management Support: Power Management Support. ADVANCED POWER Management BIOS Support: Advanced Power Management BIOD Support. 5. MEMORY TECHNOLOGY Device (MTD) MTD device support. Optional. 6. Parallel Port Support Serial Port Support. If you don't plan to use the serial port, don't choose. 7. Plug and play configuration Plug and Play support. Although Linux is not as good as Windows for plug and play, but still select it, so you can unplug the mouse to experience the feeling of playback under Linux. 8. Block Devices Support. This has to be selected for your own situation, briefly explain it: Normal PC Floppy Disk Support: Ordinary PC floppy disk support. This should be necessary. ? network block device support. If you want to access something on the online neighbors, you choose. Logical Volume Manager (LVM) Support: Logical Volume Management Support. Multiple Devices Driver Support: Multi-device Drive Support. ARM Disk Support: RAM disk support. 9. Networking options network option. The network protocol is configured here. There are too many content, introduce it, look at it, if you know what to understand the network protocol, you should be able to understand. If you are too lazy, use the default option (you must select TCP / IP Networking oh). Let's see, TCP / IP, ATM, IPX, Decnet, AppleTalk ... supported protocols, IPv6 also supports, QoS and / or fair queueing also supports, and khttpd, but These are still in the experimental phase. 10. Telephony Support telephone support. What is this stuff? Let me check the help, it is for Linux to support the phone card so you can provide voice service using a normal phone on IP. Remember, phone cards can have no relationship with MODEM. 11. ATA / IDE / MFM / RLL Support This is a hard disk / optical drive / tape / floppy disk support for various interfaces. It is too much to use the default option. If you use a relatively special device, For example, PCMCIA, etc., come to find the appropriate options yourself. 12. SCSI Support SCSI device support. I don't have SCSI's equipment, so I don't have to choose at all. If you use SCSI hard drive / optical drive / tape, you can find it. 13. IEEE 1394 (FireWire) What is this? I haven't seen the low version, see help and say. It turned out to be a FireWare hardware to improve the performance of the serial bus, I didn't, I didn't choose. 14. I2O Device Support This is not clear, the help say is this requires the I2O interface adapter to support, in the intelligent input / output (i2o) system interface, but also hardware, not selected. 15. Network Device Support Support. The above is selected, and now the device is now, it is impossible to know that the content is certain. Fortunately, it is probably classified, with Arcnet equipment, Ethernet (10 or 100 mbit), Ethernet (1000Mbit), Wireless Lan (Non-Hamradio), Token Ring Device, Wan Interface, PCMCIA Network Device Support, Best Class. I use 10 / 100m Ethernet, it seems that I only need to choose this. Still 10 / 100m Ethernet device is familiar, the content is much, you can see the realteck RTL-8139 PCI Fast Ethernet Adapter Support I used, in order to avoid trouble, compiled into the kernel, do not choose M, choose Y . Patience, usually you can find your own network card. If not, you have to go to the manufacturer to drive. 16. Amateur Radio Support is another unknown, it should be to configure the amateur wireless broadcast, no, don't. 17. Irda (Infrared) Support this infrared support, free. 18. Isdn Subsystem If you use ISDN to access the Internet, this will not be less. I have a good job. 19. Old CD-ROM Drivers (Not SCSI, Not IDE) Done, the original, those who are non-SCSI / IDE mouth, who are still use, choose it, anyway, I use the IDE CD- ROM, don't choose this. 20. Character Devices Character equipment. This content is too much, first use the default settings, you need to modify it. Let's introduce a big class: I2C Support: I2C is a low-speed serial bus protocol used in the PHILIPS push-driven microcontrol application. If you want to choose the following Video for Linux, this must be selected. Mice: mouse. You can now support bus, serial port, PS / 2, C & T 82C710 MOUSE PORT, PC110 Digitizer Pad, you can choose as needed. Joysticks: Handle. Even if you drive the handle under Linux, it is not too big, and the game is too small. Watchdog Cards: Although it is called Cards, this can be implemented with pure software, of course, has hardware. If you choose this, you will create a file called WatchDog under your / dev, which can record your system's operation, until the system restarts for about 1 minute. With this file, you can recover the status before the system is restarted. Video for Linux: Supports the relevant audio / video card. FTAPE, The Floppy Tape Device Driver: Pcmcia Character Device Support: 21. File Systems file system. There are too many content, the old man, modified on the basis of the default option. Introduce the following: QUOTA Support: Quota can limit the upper limit of the hard disk space that each user can use, which is very effective in the case of multi-user uses a host. DOS FAT FS Support: Support for DOS FAT file format, FAT16, FAT32 can be supported. @ Tem Support: The disc use is the file format of ISO 9660. NTFS File System Support: NTFS is the file format used by NT. / Proc File System Support: / proc file system is a channel that Linux is provided to users and systems, and suggests, otherwise some features cannot be executed correctly. There are also three major categories to regulate it here: Network file systems, Partition Types, Native Language Support (local language support). It is worth mentioning that both of the NETWORK File Systems: NFS and SMBs are Linux and Windows to access the file system used by each other in the form of network neighbors, and select as needed. 22. Console Drivers The console driver. Generally, VGA Text Console is usable, standard 80 * 25 text console. 23. Sound sound card driver. If you can find the sound card driver in the list, you will try the OSS. 24. USB Supprot Many USB devices, such as mice, modems, printers, scanners, etc., can be supported in Linux, and choose it as needed. 25. kernel hacking configured this, even when the system crashes, you can do a certain job. Ordinary users don't need this feature. The final configuration is over, now the deployment exits, of course, you can also save the current profile, so saving it next time. Compile After completing the complicated configuration, you can wait for yourself to the cup of tea. There are procedures related to compilation: #make dep #make clean #make zimage #make bzimage #make modules #make modules_install #depmod -a The first command Make DEP actually reads the configuration file generated by the configuration process to create the dependency tree corresponding to the configuration, which is required to compile and do not need; the second command Make Clean completes the removal front steps File to avoid some errors; the third command make zimage and the fourth command make bzimage implement full compile kernel, the core generated by Gzip is compressed, as long as one is used, their difference is Using Make Bzimage can generate a large number of kernels, such as using the make zimage command when compiling 2.4.0 version, then the error prompt of System TOO BIG will appear. It is recommended that you use the make bzimage command. The latter three commands only in the process of configuring, "Yes" is selected when answering Enable Loadable Module Support (config_modules) is necessary, make modules and make modules_install generate the corresponding module and copy the module to In the directory you need. Strictly, the seventh command and the compilation process do not have a relationship. It is a dependency between the module so that you can properly locate the module when you start the new kernel. Update After the above steps, we finally got a new version of the kernel. In order to be able to use the new version of the kernel, we also need to do some changes: #cp /usr/src/linux/system.map /boot/system.map-2.4.0test8 #cp / usr / src / linux / arch / i386 / bzimage /Boot/VMLINUZ-2.4.0Test8 The above two files are newly generated when we have just compiled. The two links System.map and VMLinuz under / boot are modified to point to the files of the new kernel: #CD / boot; rm -f system.map vmlinuz #ln -s vmlinuz-2.4.0test8 VMLinuz #LN-System.map-2.4.0test8 system.map Then modify /etc/lilo.conf: #vi /etc/lilo.conf Increase as follows: Image = / boot / vmlinuz-2.4.0test8 label = linux240 read-only root = / dev / hda2 in which root = / dev / hda2 must be modified as needed. Run: # / sbin / lilo -v confirmed the editing of /etc/lilo.conf, now restart the system: #SHUTDOWN -R Now When the machine is restarted, press the Tab button, enter Linux240, and our new kernel works, and enjoy it.