Linux kernel được nén kiểu gì? Phần 1

Kernel compression mode

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) <alain@knaff.lu>. (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'

Defined at init/Kconfig:247
  Prompt: Kernel compression mode
  Depends on: HAVE_KERNEL_GZIP [=y] || HAVE_KERNEL_BZIP2 [=y] || HAVE_KERNEL_LZMA [=y] || HAVE_KERNEL_XZ [=y] || HAVE_KERNEL_LZO [=y] || HAVE_KERNEL_LZ4 [=y] || HAVE_KERNEL_ZSTD [=y] || HAVE_KERNEL_UNCOMPRESSED [=n]
  Location:
    -> General setup
      -> Kernel compression mode (<choice> [=y])
Selected by [m]:
  - (HAVE_KERNEL_GZIP [=y] || HAVE_KERNEL_BZIP2 [=y] || HAVE_KERNEL_LZMA [=y] || HAVE_KERNEL_XZ [=y] || HAVE_KERNEL_LZO [=y] || HAVE_KERNEL_LZ4 [=y] || HAVE_KERNEL_ZSTD [=y] || HAVE_KERNEL_UNCOMPRESSED [=n]) && m

Linux kernel thường ở dạng nén chứ hổng phải ở dạng chạy được ELF (Executable and Linkable Format).

Biên dịch Linux kernel cho mình 7 kiểu nén Linux kernel như hình ở trên trển.

Linux kernel nén bằng gzip.

Gzip

CONFIG_KERNEL_GZIP:

The old and tried gzip compression. It provides a good balance
between compression ratio and decompression speed.

Symbol: KERNEL_GZIP [=n]
Type  : bool
Defined at init/Kconfig:269
  Prompt: Gzip
  Depends on: <choice> && HAVE_KERNEL_GZIP [=y]
  Location:
    -> General setup
      -> Kernel compression mode (<choice> [=y])
        -> Gzip (KERNEL_GZIP [=n])

Linux kernel nén bằng bzip2.

Bzip2

CONFIG_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.

Symbol: KERNEL_BZIP2 [=n]
Type  : bool
Defined at init/Kconfig:276
  Prompt: Bzip2
  Depends on: <choice> && HAVE_KERNEL_BZIP2 [=y]
  Location:
    -> General setup
      -> Kernel compression mode (<choice> [=y])
        -> Bzip2 (KERNEL_BZIP2 [=n])

Linux kernel nén bằng LZMA.

LZMA

CONFIG_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.

Symbol: KERNEL_LZMA [=n]
Type  : bool
Defined at init/Kconfig:286
  Prompt: LZMA
  Depends on: <choice> && HAVE_KERNEL_LZMA [=y]
  Location:
    -> General setup
      -> Kernel compression mode (<choice> [=y])
        -> LZMA (KERNEL_LZMA [=n])

Linux kernel nén bằng XZ.

XZ

CONFIG_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.

Symbol: KERNEL_XZ [=n]
Type  : bool
Defined at init/Kconfig:294
  Prompt: XZ
  Depends on: <choice> && HAVE_KERNEL_XZ [=y]
  Location:
    -> General setup
      -> Kernel compression mode (<choice> [=y])
        -> XZ (KERNEL_XZ [=n])