[PATCH] initramfs: allow again choice of the embedded compression algorithm
Date: Thu Sep 25 2014 - 00:47:53 EST
Choosing the appropriate option (for example on my tests, choosing
CONFIG_INITRAMFS_COMPRESSION_NONE when compressing the using XZ) results in
up to 500KiB differences (9MiB to 8.5MiB) in the kernel size as the
will not get polluted with uncomprensible data and may reuse kernel data
Despite embedding an uncompressed initramfs, a user may want to allow for a
compressed extra initramfs to be passed using the rd system, for example to
boot a recovery system. Commit 9ba4bcb645898d562498ea66a0df958ef0e7a68c
("initramfs: read CONFIG_RD_ variables for initramfs compression") broke
that behavior by making the choice based on CONFIG_RD_* instead of adding
CONFIG_INITRAMFS_COMPRESSION_LZ4. Saddly, CONFIG_RD_* is also used to
choose the supported RD compression algorithms by the kernel and a user may
want to suppport more than one.
This patch also reverses 3e4e0f0a8756dade3023d1f47d50fbced7749788
remove "compression mode" choice") restoring back the "compression mode"
choice and includes the CONFIG_INITRAMFS_COMPRESSION_LZ4 option which was
As a result the following options are added or readed affecting the embedded
INITRAMFS_COMPRESSION_NONE Do no compression
INITRAMFS_COMPRESSION_GZIP Compress using gzip
INITRAMFS_COMPRESSION_BZIP2 Compress using bzip2
INITRAMFS_COMPRESSION_LZMA Compress using lzma
INITRAMFS_COMPRESSION_XZ Compress using xz
INITRAMFS_COMPRESSION_LZO Compress using lzo
INITRAMFS_COMPRESSION_LZ4 Compress using lz4
These depend on the corresponding CONFIG_RD_* option (except NONE which
Signed-off-by: Francisco Blas Izquierdo Riera (klondike)
Cc: P J P <ppandit@xxxxxxxxxx>
Cc: Paul Bolle <pebolle@xxxxxxxxxx>
This patch is applied against Torvald's linux tree
Note: scripts/checkpatch.pl complains about style:
"WARNING: please write a paragraph that describes the config symbol fully"
this seems to be a false positive.
usr/Kconfig | 85
usr/Makefile | 13 +++++++------
2 files changed, 92 insertions(+), 6 deletions(-)
diff --git a/usr/Kconfig b/usr/Kconfig
index 2d4c77e..09de7b9 100644
@@ -98,3 +98,88 @@ config RD_LZ4
Support loading of a LZ4 encoded initial ramdisk or cpio buffer
If unsure, say N.
+ prompt "Built-in initramfs compression mode" if INITRAMFS_SOURCE!=""
+ This option decides by which algorithm the builtin initramfs
+ will be compressed. 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
+ initramfs, mail me (Alain Knaff) <alain@xxxxxxxx>.
+ High compression options are mostly useful for users who are
+ low on RAM, since it reduces the memory consumption during
+ If in doubt, select 'gzip'
+ bool "None"
+ Do not compress the built-in initramfs at all. This may
+ sound wasteful in space, but, you should be aware that the
+ built-in initramfs will be compressed at a later stage
+ anyways along with the rest of the kernel, on those
+ architectures that support this.
+ However, not compressing the initramfs may lead to slightly
+ higher memory consumption during a short time at boot, while
+ both the cpio image and the unpacked filesystem image will
+ be present in memory simultaneously
+ bool "Gzip"
+ depends on RD_GZIP
+ The old and tried gzip compression. It provides a good balance
+ between compression ratio and decompression speed.
+ bool "Bzip2"
+ depends on RD_BZIP2
+ Its compression ratio and speed is intermediate.
+ Decompression speed is slowest among the choices. The initramfs
+ 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.
+ bool "LZMA"
+ depends on RD_LZMA
+ This algorithm's compression ratio is best.
+ Decompression speed is between the other choices.
+ Compression is slowest. The initramfs size is about 33%
+ smaller with LZMA in comparison to gzip.
+ bool "XZ"
+ depends on RD_XZ
+ XZ uses the LZMA2 algorithm. The initramfs size is about 30%
+ smaller with XZ in comparison to gzip. Decompression speed
+ is better than that of bzip2 but worse than gzip and LZO.
+ Compression is slow.
+ bool "LZO"
+ depends on RD_LZO
+ Its compression ratio is the second poorest among the choices. The
+ kernel size is about 10% bigger than gzip; however its decompression
+ speed is the second fastest.
+ bool "LZ4"
+ depends on RD_LZ4
+ Its compression ratio is the poorest among the choices. The kernel
+ size is about 15% bigger than gzip; however its decompression speed
+ is the fastest.
diff --git a/usr/Makefile b/usr/Makefile
index e767f01..4031e23 100644
@@ -5,24 +5,25 @@
PHONY += klibcdirs
+#If unset it means we use CONFIG_INITRAMFS_COMPRESSION_NONE
-suffix_$(CONFIG_RD_BZIP2) = .bz2
+suffix_$(CONFIG_INITRAMFS_COMPRESSION_BZIP2) = .bz2
-suffix_$(CONFIG_RD_LZMA) = .lzma
+suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZMA) = .lzma
-suffix_$(CONFIG_RD_XZ) = .xz
+suffix_$(CONFIG_INITRAMFS_COMPRESSION_XZ) = .xz
-suffix_$(CONFIG_RD_LZO) = .lzo
+suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZO) = .lzo
-suffix_$(CONFIG_RD_LZ4) = .lz4
+suffix_$(CONFIG_INITRAMFS_COMPRESSION_LZ4) = .lz4
-suffix_$(CONFIG_RD_GZIP) = .gz
+suffix_$(CONFIG_INITRAMFS_COMPRESSION_GZIP) = .gz
Description: OpenPGP digital signature