4

Why does the kernel image have to be compressed vmlinuz, instead of vmlinux?

"vmlinuz is a compressed Linux kernel, and it is bootable. Bootable means that it is capable of loading the operating system into memory so that the computer becomes usable and application programs can be run.

vmlinuz should not be confused with vmlinux, which is the kernel in a non-compressed and non-bootable form. vmlinux is generally just an intermediate step to producing vmlinuz."
Source: http://www.linfo.org/vmlinuz.html

I understand the benefits of compression, but a compressed image has to be decompressed eventually (and even if it doesn't have to, I don't think it should affect this), so how can an uncompressed image not be executable/bootable?

user551044
  • 51
  • 3
  • I don't think it does. See here: https://unix.stackexchange.com/a/5602/350394 I think the page you were reading was just making it clear that vmlinu**z** and vmlinu**x** are not the same despite the similar name. – ARF Nov 28 '22 at 13:19
  • @ARF So the website is simply wrong? vmlinux and vmlinuz are both executable and bootable, but one is compressed and the other is not. Right? – user551044 Nov 28 '22 at 14:47
  • That's not what I said. The compression has nothing to do with whether or not it's bootable, they are two separate things. In the link I shared above there's reference to a `vmlinux.bin` which is bootable and not compressed. The link you gave doesn't go into all the variations of kernel file names, it just mentions the two because it's easy to confuse those two names. – ARF Nov 28 '22 at 15:25
  • @ARF Alright: vmlinux image is not bootable (so what exactly is it?). vmlinux.bin is like vmlinux but executable/bootable. vmlinuz is like compressed vmlinux.bin, and of course it is executable and bootable. Did this go right? Hmm, somehow it would be more logical if vmlinux and vmlinuz (or better vmlinuxz) were the names of executable/bootable ones and the name of the non-bootable one was vmlinux-something. – user551044 Nov 28 '22 at 15:44

1 Answers1

1

The linux kernel does not need to be compressed at all.

However… for most of us…

It will necessarily be :


Let's investigate the Kernel compression mode sub menu offered as part of the make menuconfig kernel makefile :

( ) Gzip
( ) Bzip2
( ) LZMA
( ) XZ
( ) LZO
(X) LZ4

You just get the choice between compression algos. Just no way to escape compression.

Wait! Let's now investigate the help from the kernel :

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_UNCOMPRESSED [=n]

OK all this will depend on the availability of compression algorithms but also on the setting of the HAVE_KERNEL_UNCOMPRESSED config option.

Unfortunately this option is not offered for modification as part of the menu. It is hardcoded in init/Kconfig :

config KERNEL_UNCOMPRESSED
    bool "None"
    depends on HAVE_KERNEL_UNCOMPRESSED
    help
      Produce uncompressed kernel image. This option is usually not what
      you want. It is useful for debugging the kernel in slow simulation
      environments, where decompressing and moving the kernel is awfully
      slow. This option allows early boot code to skip the decompressor
      and jump right at uncompressed kernel image.

You then get the answer to your question : No, the kernel image does not need to be compressed and the kernel configuration offers a somehow hidden possibility not to compress it. However for any standard user the kernel image will obligatorily be compressed because… because… an uncompressed image is "usually not what you want"… ;-)

Moreover : The patch allowing the build of uncompressed image (via an option directly available from make menuconfig) appeared buggy on x86_64 arches. I cannot tell its current status on this arch but is indeed working on s390 arches (see arch/s390/Kconfig)

MC68020
  • 6,281
  • 2
  • 13
  • 44
  • 1
    So that website is wrong about that vmlinux isn't be bootable? If I compile myself or download an uncompressed vmlinux image from my distribution's repos, I can boot it and replace the vmlinuz image? – user551044 Nov 28 '22 at 14:30
  • @user551044 : It might also depend on your arch (I reedited my answer) but it seems that QEMU can boot into an x86_64 uncompressed kernel. ( https://stefano-garzarella.github.io/posts/2019-08-23-qemu-linux-kernel-pvh/ ) – MC68020 Nov 28 '22 at 15:29
  • I don't understand this :( "OK all this will [depend] on the availability of compression algorithms" – user551044 Nov 28 '22 at 15:47
  • "Unfortunately this option is not offered for modification as part of the menu. It is hardcoded in init/Kconfig" But the init/Kconfig configuration is just an instruction for the build software (GNU Make?). How can anything be hardcoded into it? It's just source material/code right? – user551044 Nov 28 '22 at 15:48
  • How can the Linux kernel source code restrict/prevent the compiler (example gcc) to not compile it to an uncompressed image? – user551044 Nov 28 '22 at 15:48