Linux compilation system introduction and kernel compilation and Installation
This article not only describes how to compile and install the Linux kernel, but also describes the kernel compilation system and various important files. Finally, you can use the compiled and installed Linux kernel to change the Linux 01 scheduling to random scheduling. If you only need several commands to compile and install the kernel, go to the later part of the article. If you have any mistakes or are not clear about them, please correct them. Thank you for reading!
The kernel is the core of Linux. If you use Linux to listen to songs, watch movies, and access the Internet, I think Linux is not suitable for you. But if you can open this article, you should be interested in Linux. Here we will compile the most perfect art in IT in the world together! ---- Linux Kernel
Before compilation, let's take a look at the source code directory structure of the Linux kernel. It will help you understand the Linux kernel and get familiar with her, so there will be no fear or helplessness.
Kernel source code directory structure:
1) there is no code in Documentation. Some of them are just a variety of documents, but they can help us a lot.
2) All the Source Code related to the architecture of arch is here, and it is also in the include/asm-*/directory. All supported architectures have corresponding subdirectories under the arch directory, and contain at least three subdirectories.
Kernel: supports the implementation of specific architectures such as signal processing and SMP.
Lib: the implementation of general functions such as strlen and memcpy in the architecture.
Mm: Obviously, this is the implementation of memory management related to the architecture.
Most sub-directories contain the boot sub-directory, and some or all of the code used to start the kernel on the hardware platform.
3) drivers includes the graphics card, scsi adapter pic bus, usb bus, and other linux-supported peripheral devices and bus drivers. Is the largest directory in the kernel.
4) fs file system. There are VFS and various file system code here.
5) include contains most of the header files in the kernel.
6) communication between ipc processes, including semaphores, shared memory, and other forms of ipc code.
7) the kernel includes another part of the core Code related to the process scheduling, creation, revocation, and platform. Is the core of the kernel.
8) Code of init kernel initialization. Including main. c and code for creating early user spaces.
9) lib library code
10) mm Memory Management Code unrelated to the architecture.
11) net implementation code, common protocols such as TCP/IP and IPX.
12) There is no code in scripts. There are only some script files used to configure the kernel. When we compile the kernel and run commands such as make menuconfig, we interact with the scripts in this directory.
13) Implement the block layer.
14) security linux security model code.
15) crypto. The kernel's own encryption API implements Common encryption algorithms and hash algorithms, and some compression and CRC verification algorithms.
16) Audio Card Driver and other audio-related code.
17) usr is used for packaging and compressing cpio.
Files
At this point, you will not feel so helpless when you open the linux source code. Next let's continue.
The following describes several important files.
1) vmlinuz kernel boot file
Vmlinuz is a bootable compression kernel. "vm" represents "Virtual Memory ". Linux can use hard disk space as virtual memory, so it is named "vm ". Vmlinuz is not an executable Linux kernel (it is an executable Kernel on the Internet and may be incorrect. Because it is compressed, it must be decompressed. Hope you can advise me !), Therefore, the primary task in the startup phase is to decompress the kernel image, which is located in/boot/vmlinuz and is generally a soft link. ZImage (vmlinuz, small kernel smaller than KB) and bzImage (vmlinuz, large kernel larger than KB) are compressed using gzip. They are not only a compressed file, but are embedded with gzip decompression code at the beginning of the two files. Therefore, you cannot use gunzip or gzip-dc to unpackage vmlinuz. The kernel file contains a micro gzip used to extract the kernel and boot it. The difference between the two is that the old zImage decompress the kernel to the low-end memory (the first 640 K), and The bzImage decompress the kernel to the high-end memory (more than 1 MB ). If the kernel is small, zImage or bzImage can be used. The two methods guide the same system runtime. BzImage is used for large kernels, and zImage cannot be used.
2) vmlinux
Vmlinuz is a compressed version of vmlinux.
Vmlinuz Structure
3) initrd. img
Initrd. img, that is, "initrd RAM disk", is a small image that contains the smallest linux system. The general step is to start the kernel first, decompress the vmlinuz Kernel File, but before the real root file system starts, the initrd. imgfile will be loaded into the memory. The kernel mounts initrd. img and executes the scripts to further mount various modules. Then, it finds the real root partition, mounts and executes/sbin/init. If there is no initrd. img, the kernel tries to mount the root partition directly.
Linux root file systems can be stored in many media, such as SCSI, IDE, USB, etc. If these drivers are compiled into the kernel, then the kernel will become very bloated and huge! Therefore, linux kernel only retains the most basic startup code, and stores the support of various hardware devices in the form of modules in initrd. img. The advantage is that the required modules can be loaded from the root file system mounted by initrd during startup, so that the kernnel remains unchanged, modify the content of initrd to flexibly support different hardware. At the end of the startup, the root file system is remounted to another device.
For example, if your hard disk is a SCSI interface but your kernel does not support this interface, your kernel cannot access the hard disk, and you cannot load the file system on the hard disk, what should I do ?? Initrd. img is a ram disk image file. Ram disk is a part of the memory used to simulate the disk, so that our operating system can access it. Ram disk is a device (/dev/ram0) recognized by standard kernel files and a file system recognized by the standard kernel. The kernel loads this ram disk as the root file system and starts to execute a file named init (more than 2.6 of the kernel is the init file, which is located in/sbin/) to load various modules and services. After some configuration and operation, you can attach the real root partition to the physical disk, and then perform some configuration and finally start successfully.
Therefore, the role of initrd. img is to package some drivers and command tools into img to simplify the kernel. This fully complies with the linux design philosophy and the linux philosophy!
4) system. map, kernel symbol table, in/boot/System. map. When you compile a new kernel, the address of each symbol in the kernel changes. The information in the old kernel symbol table is incorrect for the new kernel, if the old kernel symbol table is used, an error occurs. Therefore, a new kernel symbol table, namely system, is generated. map
For more details, please continue to read the highlights on the next page: