How do I demonstrate the type of kernel compression in practice?
Your Wikipedia quote,
Although there is the popular misconception that the
bz
prefix means that bzip2 compression is used [...], this is not the case.
says the opposite of your theory: the bz
in bzImage
has no relation to bzip2
, and bzImage
doesn’t have to be compressed with bzip2
. In fact, the kernel’s default compression mode is still gzip
, and there is little reason to use bzip2
nowadays — it is slower than LZMA and xz
but doesn’t compress as well.
To conclusively determine what compression was used for a given kernel image, without needing to run it or find its configuration, you can follow the approach used by the kernel’s own extract-vmlinux
script:
look for the compressor’s signature in the image:
gunzip
:\037\213\010
xz
:\3757zXZ\000
bzip2
:BZh
lzma
:\135\0\0\0
lzo
:\211\114\132
lz4
:\002!L\030
zstd
:(\265/\375
try to extract the data from the image, starting at the offset of any signature you’ve found;
- check that the result (if any) is an ELF image.
I’ve adapted the script here so that it only reports the compression type. I’m not including it here because it is licensed under the GPL 2 only.
You can look at what compression methods your kernel supports. Only one can be selected, so that'll prove which one it is.
Here, I'm using gzip:
$ zgrep CONFIG_KERNEL_ /proc/config.gz
CONFIG_KERNEL_GZIP=y
# CONFIG_KERNEL_BZIP2 is not set
# CONFIG_KERNEL_LZMA is not set
# CONFIG_KERNEL_XZ is not set
# CONFIG_KERNEL_LZO is not set
# CONFIG_KERNEL_LZ4 is not set