3

I'm just curious, how to compress latest (2.6.32 at time of writing) kernel using UPX?

It worked well for older kernels but now repacked with UPX kernel fails to boot, standard compression methods (gzip, bzip2, lzma) work fine though.

quack quixote
  • 43,504
Alex Bolotov
  • 1,422

2 Answers2

1

Should be related with some config options from kernel.

$ zcat /proc/config.gz | grep -i lzma

CONFIG_HAVE_KERNEL_LZMA=y

<p>CONFIG_DECOMPRESS_LZMA=y</p>

Check your config in General Setup tab from kernel

dvd
  • 220
0

I was able to compress Linux kernel 2.6.33.0 i386 bzImage and boot it with qemu-system-i386. Details:

  • I've built the bzImage using make bzImage using the default CONFIG_KERNEL_GZIP=y in .config.
  • I was using UPX 4.2.4 installed as command upx.
  • I've run these UPX commands to recompress the bzImage compressed with CONFIG_KERNEL_GZIP=y:
    upx -f --no-lzma --best arch/x86/boot/bzImage -o bzImage.nolzma.upx
    upx -f --lzma    --best arch/x86/boot/bzImage -o bzImage.lzma.upx
    
  • I've booted all kernel bzImage files successfully using qemu-system-i386 version 2.11.1:
    qemu-system-i386 -kernel bzImage.nolzma.upx -initrd ... ...
    
  • The UPX-compressed kernel images boot a tiny bit faster: about 0.03s. At this size, LZMA decompression is not slower than NRV (upx --no-lzma) decompression.
  • File sizes:
    • vmlinux: 2 268 129 bytes including symbols (i386 ELF-32 executable, uncompressed, not stripped, not bootable by qemu-system-i386)
      • 1 200 128 bytes of code (.text)
      • 237 131 bytes of initialized data (.data)
      • 1 008 053 bytes of uninitialized data (.bss)
      • 1 437 259 bytes to be compressed (total of .text and .data)
    • bzImage.nolzma.upx: 805 200 bytes (UPX NRV compression, bootable)
    • bzImage.lzma.upx: 726 608 bytes (UPX LZMA compression, bootable)
    • arch/x86/boot/bzImage: 857 264 bytes (gzip CONFIG_KERNEL_GZIP=y compression, bootable)
    • arch/x86/boot/bzImage.lzma: 728 896 bytes (LZMA CONFIG_KERNEL_LZMA=y compression, bootable)
pts
  • 7,648