Detailed explanation of Linux kernel files

There are three main Linux kernel files, vmlinuz, initrd.img and System.map. For people studying the kernel, these three files are very important.

1.vmlinuz

vmlinuz is a bootable, compressed kernel. "Vm" stands for "Virtual Memory". Linux supports virtual memory.

There are two ways to establish vmlinuz. One is created by "make zImage" when compiling the kernel. zImage is suitable for small kernels, and it exists for backward compatibility. The second is that it is created by the command make bzImage when the kernel is compiled. bzImage is a compressed kernel image. It should be noted that bzImage is not compressed with bzip2. The bz in bzImage is misleading, and bz stands for "big zImage". The b in bzImage means "big".

Both zImage (vmlinuz) and bzImage (vmlinuz) are compressed with gzip. They are not only a compressed file, but the gzip decompression code is embedded in the beginning of the two files. So you cannot unpack vmlinuz with gunzip or gzip -dc.

The kernel file contains a tiny gzip to decompress the kernel and boot it. The difference between the two is that the old zImage decompresses the kernel to the low-end memory (the first 640K), and the bzImage decompresses the kernel to the high-end memory (above 1M). If the kernel is relatively small, one of zImage or bzImage can be used, and the operating time of the system booted by the two methods is the same. The big kernel uses bzImage, but not zImage.

In addition, vmlinux is an uncompressed kernel, and vmlinuz is a compressed file of vmlinux.

2.initrd.img

initrd is short for "initial ramdisk". Initrd is generally used to temporarily boot the hardware to a state where the actual kernel vmlinuz can take over and continue booting. Initrd is mainly used to load ext3 and other file systems and drivers for scsi devices. For example, if the scsi hard disk is used and the scsi hardware driver is not in the kernel vmlinuz, the kernel cannot load the root file system before loading 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 boot an initrd kernel that can read the actual kernel and use initrd to correct the scsi boot problem. initrd.img is a file compressed with gzip.

The initrd image file is created using mkinitrd. The mkinitrd utility can create an initrd image file. This command is proprietary to RedHat. Other Linux distributions may have corresponding commands. This is a very convenient utility.

3.System.map

System.map is a kernel symbol table of a specific kernel. It is a link to the System.map of the kernel you are currently running.
How is the kernel symbol table created? System.map is generated by "nm vmlinux" and irrelevant symbols are filtered out.

nm /boot/vmlinux-2.6.32-10 > System.map
下面几行来自/usr/src/linux-2.6/Makefile:
nm vmlinux | grep -v ‘compiled\|\.o$$\|
[aUw]\|\.\.ng$$\|LASH[RL]DI’ | sort > System.map

4. The difference between initrd and initramfs

First of all, we will introduce two schemes of kernel startup init.
The first is ramdisk, which uses a piece of memory (ram) as a disk (disk) to mount, and then finds the init in the ram to execute it.
The second is ramfs, which mounts the file system directly on the ram and executes init in the file system.
Initrd (init ramdisk) is the realization of ramdisk, and initramfs is the realization of ramfs.
tmpfs is an enhanced version of ramfs. rootfs, is a special instance of ramfs/tmpfs. So initramfs can also be an implementation of tmpfs/rootfs.

Don't be confused by the file name, since kernel 2.6 has been initramfs, but many still use the traditional initrd name.

Reference: https://blog.csdn.net/zhongbeida_xue/article/details/106627102

Guess you like

Origin blog.51cto.com/14207158/2659291