Linux server kernel compilation foundation
- Several important redhat linux kernel file introductions
Mynix compiles from www.linux.org Linux Howto Kernel Howto
In the network, many servers use the Linux system. In order to further improve the performance of the server, it may be necessary to recompile the Linux kernel based on specific hardware and requirements. Compiling the Linux kernel and needs to be performed according to the prescribed steps, and several important files are involved in the compiled kernel. For example, for Redhat Linux, there are some files related to the Linux kernel in the / boot directory, enter / boot execution: ls -l, as shown. The person compiled the Redhat Linux kernel may be deeply impressed by the system.map, vmlinuz, initrd-2.4.7-10.img, because the compiled kernel is involved in the establishment of these files. So how did these documents produce? What role is there? This article describes this.
First, VMLinuz
VMLinuz is bootable, compressed kernel. "VM" represents "Virtual Memory". Linux supports virtual memory, unlike old operating systems such as DOS, 640KB memory restrictions. Linux can use the hard disk space as a virtual memory, so the name "VM". VMLinuz is an executable Linux kernel, which is located / boot / vmlinuz, which is generally a soft link, such as a soft link of VMLinuz-2.4.7-10 in the figure.
VMLinuz has two ways. First, the compile core is created by "Make Zimage" and then passed:
"Cp /usr/src/linux-2.4/Arch/i386/linux/boot/zimage / boot / vmlinuz" is generated. ZIMAGE is suitable for small kernels, and its existence is to rearward compatibility. Second, the kernel is created by the command Make Bzimage, and then passed: "cp /usr/src/linux-2.4/Arch/i386/linux/boot/bzimage / boot / vmlinuz" is generated. Bzimage is a compressed kernel image, it is important to note that BziMage is not compressed with BZIP2, BZImage is easily misunderstood, BZ represents "BIG ZIMAGE". BZIMAGE is "BIG" meaning.
Zimage (VMLinuz) and Bzimage (VMLinuz) are compressed with Gzip. They are not only a compressed file, but also in the beginning of these two files, Gzip decompression code is embedded. So you can't use Gunzip or Gzip -DC to unpack VMLinuz.
The kernel file contains a miniature Gzip to extract the kernel and boot it. The difference between the two is that the old zimage decompressed core to low-end memory (first 640K), Bzimage decompressed kernel to high-end memory (more than 1M). If the kernel is relatively small, one of Zimage or BziMage can be used, and the system runs in two ways is the same. The large kernel adopts BZImage, and Zimage cannot be used.
VMLinux is an uncompressed kernel, VMLinuz is a VMLinux compressed file.
Second, INITRD-X.x.x.img
Initrd is a short written by "Initial Ramdisk". Initrd is generally used to tempted boot hardware to actual kernel VMLinuz to take over and continue to boot. Initrd-2.4.7-10.img in the figure is mainly used to load file systems such as EXT3 and the drivers of SCSI devices. For example, use the SCSI hard disk, and the kernel VMLinuz does not driver this SCSI hardware, then the kernel cannot load the root file system before being loaded into the SCSI module, but the SCSI module is stored under / lib / modules of the root file system. In order to solve this problem, you can guide an initrd core that can read the actual kernel and use initrd to correct SCSI boot issues. INITRD-2.4.7-10.IMG is a file compressed with gzip. Here, look at this file. The operation steps are shown below: From the contents of the Linuxrc script, the initrd implementation is loaded with some modules. And install the file system, etc..
The initrd image file is created using Mkinitrd. The MKinitrd utility can create an initrd image file. This command is the redhat. Other Linux distributions may have a corresponding command. This is a very convenient utility. Please see help: man mkinitrd
The following command creates an initrd image file:
Third, System.map
System.map is a kernel symbol table for a specific kernel. It is the link to System.map in your current running kernel.
How is the kernel symbol table creation? System.map is created by "NM VMLinux" and is not related to the symbol. For the examples in this article, compile the core, System.map creates in /usr/src/linux-2.4/system.map. Like this:
NM /BOOT/VMLINUX-2.4.7-10> System.map
The following line from /usr/src/linux-2.4/makefile:
NM VMLINUX | GREP -V '| (.o $$) | (. ng $$) | (Lash [RL] DI) | Sort> System.map
Then copy it to / boot:
Cp /usr/src/linux/system.map /boot/system.map-2.4.7-10
The picture below is part of the System.map file:
When the program is designed, a symbol of some variable names or function names is named. The Linux kernel is a very complex code block with many global symbols.
The Linux kernel does not use the symbol name, but the variable or function name is identified by the address of the variable or function. For example, it is not a symbol such as SIZE_T BYTESREAD, but is like c0343f20 to reference this variable.
For those who use a computer, I prefer to use those names like size_t bytesread, and don't like the name like C0343F20. The kernel is mainly written with C, so the compiler / connector allows us to use the symbol name when the core is used, and the address is used when the kernel is run.
However, in some cases, we need to know the address of the symbol, or you need to know the address corresponding to the address. This is done by the symbol table, and the symbol table is a list of all symbols along with their address. The above figure is a kernel symbol table, which is known to the above-drawn CHECKCPUTYPE in the kernel address C01000A5.
The Linux symbol table uses 2 files:
/ proc / ksyms
SYSTEM.MAP
The following figure is part of / proc / ksyms.
/ proc / ksyms is a "proc file" created when kernel boots. In fact, it is not really a file, it is just a represented by kernel data, but it is a description of a disk file, which can be seen from its file size. However, System.map is an actual file that exists on your file system. When you compile a new kernel, the address of each symbol name changes, your old system.map has the wrong symbol information. Generate a new system.map at each kernel, you should use the new system.map to replace the old system.map. Although the kernel itself does not really use System.map, other programs such as Klogd, LSOF, and PS require a correct system.map. If you use a wrong or there is no system.map, Klogd's output will be unreliable, which will be difficult to eliminate the program failure. Without system.map, you may face some troublesome prompt information.
Another few drivers require system.map to resolve symbols, and they cannot work properly for system.map created by your currently running specific kernel.
Linux's kernel log daemon KLOGD To perform the name-address resolution, Klogd needs to use System.map. System.map should be placed in using its software to find it. Execute: Man Klogd, if you do not give the system.map as a variable to klogd, then it will look for system.map in three places in three places.
/BOOT/SYSTEM.MAP
/System.map
/usr/src/linux/system.map
System.map also has version information, Klogd can intelligently find the correct image (MAP) file.