"Kernel" several important Linux kernel files "Go"

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/lcw/p/3159394.html

Preface

When a user compiles a Linux kernel code, several files are generated: Vmlinz, initrd.img, and System.map, and if the Grub Boot manager program is configured, the files are seen in the/boot directory.

Vmlinuz

The Vmlinuz is a bootable, compressed kernel file.

The file contains a minimal functional kernel, which is usually performed first on the PC, then the initrd.img file is loaded, and the root partition is loaded at the end of the Vmlinuz.

In fact, initrd.img is optional, from the file size, initrd.img is much larger than the Vmlinuz file, Initrd.img also contains a lot of features, if you do not need additional features, such as in some functional requirements of the embedded system, can only use the Vmlinuz file to store the kernel, and save Go to initrd.img file.

"VM" stands for "Virtual Memory". Linux supports virtual memory, unlike older operating systems such as DOS, which have 640KB memory limitations. Linux is able to use hard disk space as virtual memory, hence the name "VM". Vmlinuz is an executable Linux kernel, which is located in/boot/vmlinuz, which is generally a soft link.

There are two ways to build a vmlinuz.

One is to build the kernel with "make zimage". Zimage is suitable for small cores, it exists for backwards compatibility.

The second is to compile the kernel by "make bzimage" created, and then through. Bzimage is a compressed kernel image, it should be noted that bzimage is not compressed with bzip2, the BZ in Bzimage is prone to misunderstanding, BZ said "Big Zimage". B in Bzimage is the meaning of "big".

Zimage (Vmlinuz) and Bzimage (Vmlinuz) are compressed with gzip. Not only are they a compressed file, they are also embedded with the Gzip decompression code at the beginning of these two files. So you can't unpack vmlinuz with Gunzip or GZIP–DC.

The kernel file contains a miniature gzip to decompress the kernel and boot it. The difference is that zimage unzip the kernel to low-end memory (the first 640K), bzimage the kernel to high-end memory (1M or more). If the kernel is small, you can use one of the zimage or Bzimage, and the two modes of booting the system run the same. The large kernel uses bzimage and cannot use Zimage.

After the kernel compiles there is also a vmlinux file, Vmlinux is an uncompressed kernel, Vmlinuz is the Vmlinux compressed file.

INITRD file

INITRD is a shorthand for "initial RAMDisk". is the memory disk initialized by the bootloader.

Before the Linux kernel starts, bootloader will load the INITRD files in the storage media (such as flash memory) into the RAM, and the kernel will access the in-memory INITRD file system before accessing the real root file system.

If Bootloader is configured with INITRD, the kernel boot is divided into two stages:

    • The first stage is to load the driver module in the INITRD file system first;

    • The/sbin/init process in the real root file system is performed in the second phase.

The purpose of the first phase of the launch is to clear the barrier for the second phase of boot, the Linux root file system supports a variety of storage media (such as IDE, SCSI, USB, etc.), if the driver of these devices are compiled into the kernel, the kernel will be very large, the use of INITRD storage device driver is a good solution to this problem.

In the boot order, INITRD will be loaded after the Vmlinuz code execution, using the INITRD mechanism can be a good solution to different hardware environments, is the Linux distribution, USB device to start the necessary. In the embedded system, when the hardware is relatively fixed, the INITRD function is not as large as that of the PC, but it is the function of simplifying the debugging steps for the debugging device driver.

INITRD is generally used to temporarily boot the hardware to the actual kernel vmlinuz to be able to take over and continue the boot state. For example, if you are using a SCSI hard disk, and the kernel Vmlinuz does not have this SCSI hardware driver, the kernel cannot load the root file system until the SCSI module is loaded, but the SCSI module is stored under the/lib/modules of the root file system. To solve this problem, you can boot a INITRD kernel that reads the actual kernel and fix the SCSI boot problem with INITRD.

INITRD implements loading some modules and installing file systems.

The INITRD image file was created using MKINITRD. The MKINITRD utility is capable of creating INITRD image files. This command is Redhat proprietary. Other Linux distributions may have the appropriate commands. This is a handy utility. For details, see Help: Man MKINITRD

System.map

System.map is a kernel symbol table for a specific kernel. It is a link to the system.map of the kernel you are currently running.

System.map are produced by "nm Vmlinux" and are not related to the symbol being filtered out.

When you are programming, you name symbols such as variable names or function names. The Linux kernel is a very complex block of code, with lots of global symbols.

Instead of using symbolic names, the Linux kernel uses the address of a variable or function to identify a variable or function name. For example, instead of using symbols such as size_t bytesread, this variable is referenced like C0343f20.

For people who use computers, they prefer to use names like size_t bytesread rather than names like C0343f20. The kernel is written in C, so the compiler/connector allows us to encode using the symbol name when the kernel is running with an address (using the symbol table to query the address of a symbol, or a symbolic name from a memory address).

However, in some cases, we need to know the address of the symbol, or we need to know the corresponding symbol of the address. This is done by the symbol table, which is a list of all the symbols along with their addresses.

The Linux symbol table uses 2 files:

    • /proc/ksyms

    • System.map

/proc/ksyms is a "proc file" that is created when the kernel is booted. In fact, it's not really a file, it's just a representation of the kernel data, but it gives people the illusion of a disk file, which can be seen from its file size of 0.

System.map is the actual file that exists on your file system. When you compile a new kernel, the address of each symbol name changes, and your old system.map has the wrong symbolic information. Each time the kernel compiles a new system.map, you should replace the old System.map with the new System.map.

Although the kernel itself does not really use SYSTEM.MAP, other programs such as KLOGD, lsof and PS need a correct system.map. If you use the wrong or no SYSTEM.MAP,KLOGD output will be unreliable, this will be difficult to troubleshoot the program.

Without System.map, you may face some annoying tips.

The other few drivers need system.map to parse the symbols, and there are no system.map created for the specific kernel that you are currently running, and they do not work properly.

The kernel log daemon for Linux KLOGD requires the use of system.map in order to perform name-address resolution. The system.map should be placed where the software using it can find it.

Execution: Man klogd that if you do not give klogd the position of System.map as a variable, it will find System.map in three places in the following order:

    • /boot/system.map

    • /system.map

    • /usr/src/linux/system.map

System.map also has version information, KLOGD is able to intelligently find the correct image (map) file.

"Kernel" several important Linux kernel files "Go"

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.