Skip to contentSkip to conversation

lzma support: lzma compressed kernel image

PATCH In review Christian Leber 3 participants 6 messages Jun 7, 2005 – Jun 15, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 lzma support: lzma compressed kernel image

This patch is against 2.6.12-rc6.

Makes it possible on i386 to select lzma compression instead of gzip compression, this is especially usefull for embedded systems or when there are special size restrictions, like a kernel on a floppy image.

Other architectures aren't affected, obviously.

I also want to mention that the misc_lzma.c is much cleaner than the orginal misc.c :-)

The memory requirements are only a little big higher than with gzip, namely low_buffer_size or even lower when !high_loaded.

Size example:

-rw-r--r--  1 ijuz ijuz 1233099 Jun  7 20:12 bzImage.gz
-rw-r--r--  1 ijuz ijuz 1041267 Jun  7 20:12 bzImage.lzma

(download them from here to try them out:
http://debian.christian-leber.de/kernel_lzma/)

To build a kernel with lzma compression you have to go to:
Executable file formats -> Kernel compression format

Building the lzma tool cut and paste style:

mkdir build-lzma
wget http://www.7-zip.org/dl/lzma417.tar.bz2
tar xjf lzma417.tar.bz2
cd SRC/7zip/Compress/LZMA_Alone/
make
cp lzma ../../../../../
cd ../../../../../

arch/i386/Kconfig +28 -0
@@ -1236,6 +1236,34 @@
 
 source "fs/Kconfig.binfmt"
 
+choice
+       prompt "Kernel compression format"
+       depends on EXPERIMENTAL
+       default KERNEL_GZIP
+
+config KERNEL_GZIP
+       bool "Compress kernel image using gzip"
+       help
+         The linux kernel is a self-extracting executable.
+
+         Choosing Gzip here, makes the kernel image beeing compressed
+         using Gzip.
+
+         Gzip is the standard compression method for the kernel image.
+         If you do not know what to say, take gzip.
+
+
+config KERNEL_LZMA
+       bool "Compress kernel image using lzma (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       help
+         The linux kernel is a self-extracting executable.
+
+         Choosing lzma here, makes the kernel beeing compressed using
+         lzma.
+
+endchoice
+
 endmenu
 
 source "drivers/Kconfig"
arch/i386/boot/compressed/misc_lzma.c +296 -0

296 lines not on this page · raw message

arch/i386/boot/compressed/Makefile +25 -6
@@ -4,22 +4,41 @@
 # create a compressed vmlinux image from the original vmlinux
 #
 
-targets		:= vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
+targets		:= vmlinux vmlinux.bin head.o piggy.o
 EXTRA_AFLAGS	:= -traditional
 
 LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32
 
-$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
-	$(call if_changed,ld)
-	@:
+LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
 
 $(obj)/vmlinux.bin: vmlinux FORCE
 	$(call if_changed,objcopy)
 
+ifeq ($(CONFIG_KERNEL_GZIP),y)
+targets                += vmlinux.bin.gz misc.o
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
+	$(call if_changed,ld)
+	@:
+
 $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
 	$(call if_changed,gzip)
 
-LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
-
 $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
 	$(call if_changed,ld)
+endif
+
+ifeq ($(CONFIG_KERNEL_LZMA),y)
+targets                += vmlinux.bin.lzma misc_lzma.o
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc_lzma.o $(obj)/piggy.o FORCE
+	$(call if_changed,ld)
+	@:
+
+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
+	lzma e $(obj)/vmlinux.bin $(obj)/vmlinux.bin.lzma
+
+$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.lzma FORCE
+	$(call if_changed,ld)
+endif
+
#1 lore raw

On Tue, Jun 07, 2005 at 11:41:28PM +0200, Christian Leber wrote:

Also refined.
And btw. it is together with PATCH 1/2 allready used by a rescue distribution :-)

This patch is against 2.6.12-rc6.

Makes it possible on i386 to select lzma compression instead of gzip compression, this is especially usefull for embedded systems or when there are special size restrictions, like a kernel on a floppy image.

Other architectures aren't affected, obviously.

I also want to mention that the misc_lzma.c is much cleaner than the orginal misc.c :-)

The memory requirements are only a little big higher than with gzip, namely low_buffer_size or even lower when !high_loaded.

Size example:

-rw-r--r--  1 ijuz ijuz 1233099 Jun  7 20:12 bzImage.gz
-rw-r--r--  1 ijuz ijuz 1041267 Jun  7 20:12 bzImage.lzma

(download them from here to try them out:
http://debian.christian-leber.de/kernel_lzma/)

To build a kernel with lzma compression you have to go to:
Executable file formats -> Kernel compression format

Building the lzma tool cut and paste style:

mkdir build-lzma
wget http://www.7-zip.org/dl/lzma417.tar.bz2
tar xjf lzma417.tar.bz2
cd SRC/7zip/Compress/LZMA_Alone/
make
cp lzma ../../../../../
cd ../../../../../

arch/i386/Kconfig +28 -0
@@ -1236,6 +1236,34 @@
 
 source "fs/Kconfig.binfmt"
 
+choice
+       prompt "Kernel compression format"
+       depends on EXPERIMENTAL
+       default KERNEL_GZIP
+
+config KERNEL_GZIP
+       bool "Compress kernel image using gzip"
+       help
+         The linux kernel is a self-extracting executable.
+
+         Choosing Gzip here, makes the kernel image beeing compressed
+         using Gzip.
+
+         Gzip is the standard compression method for the kernel image.
+         If you do not know what to say, take gzip.
+
+
+config KERNEL_LZMA
+       bool "Compress kernel image using lzma (EXPERIMENTAL)"
+       depends on EXPERIMENTAL
+       help
+         The linux kernel is a self-extracting executable.
+
+         Choosing lzma here, makes the kernel beeing compressed using
+         lzma.
+
+endchoice
+
 endmenu
 
 source "drivers/Kconfig"
arch/i386/boot/compressed/Makefile +25 -6
@@ -4,22 +4,41 @@
 # create a compressed vmlinux image from the original vmlinux
 #
 
-targets		:= vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
+targets		:= vmlinux vmlinux.bin head.o piggy.o
 EXTRA_AFLAGS	:= -traditional
 
 LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup_32
 
-$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
-	$(call if_changed,ld)
-	@:
+LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
 
 $(obj)/vmlinux.bin: vmlinux FORCE
 	$(call if_changed,objcopy)
 
+ifeq ($(CONFIG_KERNEL_GZIP),y)
+targets                += vmlinux.bin.gz misc.o
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
+	$(call if_changed,ld)
+	@:
+
 $(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
 	$(call if_changed,gzip)
 
-LDFLAGS_piggy.o := -r --format binary --oformat elf32-i386 -T
-
 $(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.gz FORCE
 	$(call if_changed,ld)
+endif
+
+ifeq ($(CONFIG_KERNEL_LZMA),y)
+targets                += vmlinux.bin.lzma misc_lzma.o
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc_lzma.o $(obj)/piggy.o FORCE
+	$(call if_changed,ld)
+	@:
+
+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
+	lzma e $(obj)/vmlinux.bin $(obj)/vmlinux.bin.lzma
+
+$(obj)/piggy.o: $(obj)/vmlinux.scr $(obj)/vmlinux.bin.lzma FORCE
+	$(call if_changed,ld)
+endif
+
arch/i386/boot/compressed/misc_lzma.c +351 -0

351 lines not on this page · raw message

#2 lore raw
Quoted 5 lines · Christian Leber

On Tue, Jun 07, 2005 at 11:41:28PM +0200, Christian Leber wrote:

Also refined.
And btw. it is together with PATCH 1/2 allready used by a rescue distribution :-)

(...)

arch/i386/boot/compressed/Makefile line 39

Quoted 2 lines

+$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE

arch/i386/boot/compressed/Makefile +1 -0
+	lzma e $(obj)/vmlinux.bin $(obj)/vmlinux.bin.lzma
        ^^^^

Would you please use $(call if_changed,lzma) as it is in other places ? This is very handy as it allows you to use another binary by simply passing "cmd_lzma=" to make.

Thanks,
Willy

#3 lore raw
In reply to Christian Leber

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 9 lines · Christian Leber

Building the lzma tool cut and paste style:

mkdir build-lzma
wget http://www.7-zip.org/dl/lzma417.tar.bz2
tar xjf lzma417.tar.bz2
cd SRC/7zip/Compress/LZMA_Alone/
make
cp lzma ../../../../../
cd ../../../../../

Other than the coding style issues which need to be addressed, the patches appear to work as advertised. lzma reduced my kernel by approximately 25%, so I'd say it looks promising.

I do have a gripe about the need for the external lzma program when building the kernel. gzip can reasonably be expected to be on people's systems, but lzma is (currently, at least) rather obscure, and isn't likely to be on very many systems.

I think one or more of the following ought to happen:
- - Modify the help text in the Kconfig option to show people how to obtain, compile, and install lzma (and warn them they'll need to install it).
- - Detect that the lzma application isn't present, and fall back to gzip (with a warning) if lzma fails.
- - If we can embed the decompressor into the boot-time kernel, can't we put a compressor into the kernel source, and avoid the need for the external program?
- - ...

Frank
- --
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
[email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCrjyRaI0dwg4A47wRAk3PAKCZiMzdEP1UefLN3ETO/c64zrjedACfaz+T RSAM/qgCehDj2Gs6e03T3RY=
=oIaY
-----END PGP SIGNATURE-----

#4 lore raw
Quoted 1 line · Frank Sorenson

patches appear to work as advertised.

I don't like the moving of the initrd, but i don't know another way to get it working otherwise.

Quoted 2 lines

lzma reduced my kernel by
approximately 25%, so I'd say it looks promising.

25%? i would have expected a smaller saving

Quoted 4 lines

I think one or more of the following ought to happen:
- - Modify the help text in the Kconfig option to show people how to obtain, compile, and install lzma (and warn them they'll need to install it).

How to obtain should be enough, i'll add it.

Quoted 2 lines

- - Detect that the lzma application isn't present, and fall back to gzip (with a warning) if lzma fails.

No.
If you select lzma you have to have it, you also don't download a compiler when somebody tries to compile the kernel without a compiler.

Quoted 3 lines

- - If we can embed the decompressor into the boot-time kernel, can't we put a compressor into the kernel source, and avoid the need for the external program?

How do think will people react to a hundreds of kb sized C++ patch that is not - i repeat - NOT in proper coding style?

Christian Leber

Signature · 1 line
http://www.nosoftwarepatents.com
#5 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 10 lines · Christian Leber
Quoted 1 line · Frank Sorenson

patches appear to work as advertised.

I don't like the moving of the initrd, but i don't know another way to get it working otherwise.

Quoted 2 lines

lzma reduced my kernel by
approximately 25%, so I'd say it looks promising.

25%? i would have expected a smaller saving

- -rw-r--r--   1 root root  2959194 Jun 12 14:28 vmlinuz-2.6.12-rc6-fs1
- -rw-r--r--   1 root root  2192674 Jun 13 21:47 vmlinuz-2.6.12-rc6-fs2
Quoted 1 line

How to obtain should be enough, i'll add it.

Great, thanks.

Quoted 6 lines
Quoted 2 lines

- - Detect that the lzma application isn't present, and fall back to gzip (with a warning) if lzma fails.

No.
If you select lzma you have to have it, you also don't download a compiler when somebody tries to compile the kernel without a compiler.

Uhm, no, I wasn't saying that. Just suggesting a simple failsafe. It's not important.

Quoted 6 lines
Quoted 3 lines

- - If we can embed the decompressor into the boot-time kernel, can't we put a compressor into the kernel source, and avoid the need for the external program?

How do think will people react to a hundreds of kb sized C++ patch that is not - i repeat - NOT in proper coding style?

I wasn't suggesting that we include the entire source code as-is. Just that if we can include the decompressor in < 45K of code, surely the compression could be included easily. Again, it's not very important. Giving enough information to build and run is most important.

Frank
- --
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
[email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCsJ1JaI0dwg4A47wRAlu8AJ4svae4WhrMnZf8HRNJl0PBCsTaXACeIhIa 8rmljN+/ZG1Vtg5OPa5KSAc=
=rOJl
-----END PGP SIGNATURE-----