Research on linux kernel compression

kernel image format

vmlinuz is a bootable, compressible kernel image, and vm represents Virtual Memory. It is compiled from the source code of the kernel by the user. In essence, it is a file in elf format with symbol table, which can be used for debugging.
Image is the kernel code that contains only binary data and is processed by objcopy without compression.
zImage is a kind of compressed image file commonly used in ARM linux. It is composed of vmlinux and decompressed code by gzip compression. The command format is "make zImage"
bz represents big zImage, whose format is similar to zImage, but different compression algorithms are used. gzip is used for compression. bzImage has a higher compression ratio and is suitable for large kernel.
uImage is a special image file for uboot. It is a header information (tag) with a length of 0x40 added before zImage. In the header information, it describes the type, loading position, generation time, size and other information of the image file. In other words, if you start directly from the 0x40 position of uImage, there is no difference between zImage and uImage. The command format is "make" Most Linux image files in this format are stored on NAND.
There is mkimage tool in the tools directory of u-boot, which can be used to make uImage. Refer to Here.
Most of the Linux image files in this format are stored in NorFlash, and they do not need to be copied to the memory SDRAM when running. They can run directly in NorFlash

linux compression mode configuration options

In init/Kconfig, you can see the following choices about compression methods. According to the following description, you can briefly know the characteristics of various compression algorithms. For the detailed test of these algorithms, please refer to Here.

        prompt "Kernel compression mode"
        default KERNEL_GZIP

          The linux kernel is a kind of self-extracting executable.
          Several compression algorithms are available, which differ
          in efficiency, compression and decompression speed.
          Compression speed is only relevant when building a kernel.
          Decompression speed is relevant at each boot.

          If you have any problems with bzip2 or lzma compressed
          kernels, mail me (Alain Knaff) <>. (An older
          version of this functionality (bzip2 only), for 2.4, was
          supplied by Christian Ludwig)

          High compression options are mostly useful for users, who
          are low on disk space (embedded systems), but for whom ram
          size matters less.

          If in doubt, select 'gzip'

        bool "Gzip"
        depends on HAVE_KERNEL_GZIP
          The old and tried gzip compression. It provides a good balance
          between compression ratio and decompression speed.

        bool "Bzip2"
        depends on HAVE_KERNEL_BZIP2
          Its compression ratio and speed is intermediate.
          Decompression speed is slowest among the choices.  The kernel
                    size is about 10% smaller with bzip2, in comparison to gzip.
          Bzip2 uses a large amount of memory. For modern kernels you
          will need at least 8MB RAM or more for booting.

        bool "LZMA"
        depends on HAVE_KERNEL_LZMA
          This compression algorithm's ratio is best.  Decompression speed
          is between gzip and bzip2.  Compression is slowest.
          The kernel size is about 33% smaller with LZMA in comparison to gzip.

config KERNEL_XZ
        bool "XZ"
        depends on HAVE_KERNEL_XZ
          XZ uses the LZMA2 algorithm and instruction set specific
          BCJ filters which can improve compression ratio of executable
          code. The size of the kernel is about 30% smaller with XZ in
          comparison to gzip. On architectures for which there is a BCJ
          filter (i386, x86_64, ARM, IA-64, PowerPC, and SPARC), XZ
          will create a few percent smaller kernel than plain LZMA.

          The speed is about the same as with LZMA: The decompression
          speed of XZ is better than that of bzip2 but worse than gzip
          and LZO. Compression is slow.

        bool "LZO"
        depends on HAVE_KERNEL_LZO
          Its compression ratio is the poorest among the choices. The kernel
          size is about 10% bigger than gzip; however its speed
          (both compression and decompression) is the fastest.

config KERNEL_LZ4
        bool "LZ4"
        depends on HAVE_KERNEL_LZ4
          LZ4 is an LZ77-type compressor with a fixed, byte-oriented encoding.
          A preliminary version of LZ4 de/compression tool is available at

          Its compression ratio is worse than LZO. The size of the kernel
          is about 8% bigger than LZO. But the decompression speed is
          faster than LZO.


The kernel compression and decompression code is in the directory kernel/arch/arm/boot/compressed. It seems that there is no specific compression algorithm in this document.
More information:
linux kernel image format

Quick Benchmark: Gzip vs Bzip2 vs LZMA vs XZ vs LZ4 vs LZO

Published 30 original articles, won praise 3, visited 5456
Private letter follow

Tags: Linux less encoding Google

Posted on Wed, 26 Feb 2020 21:19:59 -0500 by ondercsn