[PATCH 2/2] Export initial ramdisk compression config

From: P J P
Date: Sun Sep 15 2013 - 05:19:33 EST


Hello,

While building the 3.11 kernel recently, I bumped into this issue.

Menuconfig allows one to choose compression format of an initial ramdisk image. But this selection does not result in creation of a duly compressed initramfs image. Because - $ make install - does not pass on the selected compression option to dracut(8) tool, which generates the initramfs file. This leads to a situation wherein the initramfs file is gzip(1) compressed, but the kernel knows only to decompress the user's chosen compression format.

The attached patch herein, attempts to fix this issue by exporting the compression configuration option to an environment variable of a sub-shell spawned by Make(1) with the invocation of installkernel(8) during the installation process.

The dracut(8) & new-kernel-pkg(8) tools need to be patched to recognise and read such an environment variable and use the selected compression algorithm while creating the initial ramdisk image files.

Could someone please review this one too?

Thank you.
--
Prasad J Pandit / Red Hat Security Response Team
DB7A 84C5 D3F9 7CD1 B5EB C939 D048 7860 3655 602BFrom 88878c7dfb04e69b75f1518fe809b917095a33b8 Mon Sep 17 00:00:00 2001
From: P J P <prasad@xxxxxxxxxx>
Date: Sun, 15 Sep 2013 13:37:43 +0530
Subject: [PATCH 2/2] Export initial ramdisk compression config option

Make menuconfig allows one to choose compression format of an
initial ramdisk image. But this choice does not result in duly
compressed ramdisk image. Because - $ make install - does not
pass on the selected compression choice to the dracut(8) tool,
which creates the initramfs file. dracut(8) generates the image
with the default compression, ie. gzip(1).

This patch exports the selected compression option to a sub-shell
environment, so that it could be used by dracut(8) tool to generate
appropriately compressed initramfs images.

There isn't a straight forward way to pass on options to dracut(8)
via positional parameters. Because it is indirectly invoked at the
end of a $ make install sequence.

# make install
-> arch/$arch/boot/Makefile
-> arch/$arch/boot/install.sh
-> /sbing/installkernel ...
-> /sbin/new-kernel-pkg ...
-> /sbin/dracut ...

Signed-off-by: P J P <prasad@xxxxxxxxxx>

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index 41250fb..9f4cdf1d 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -11,6 +11,23 @@ else
KBUILD_DEFCONFIG := $(ARCH)_defconfig
endif

+# Select initial ramdisk compression format, default is gzip(1).
+# This shall be used by the dracut(8) tool while creating an initramfs image.
+#
+INITRD_COMPRESS=gzip
+ifeq ($(CONFIG_RD_BZIP2), y)
+ INITRD_COMPRESS=bzip2
+else ifeq ($(CONFIG_RD_LZMA), y)
+ INITRD_COMPRESS=lzma
+else ifeq ($(CONFIG_RD_XZ), y)
+ INITRD_COMPRESS=xz
+else ifeq ($(CONFIG_RD_LZO), y)
+ INITRD_COMPRESS=lzo
+else ifeq ($(CONFIG_RD_LZ4), y)
+ INITRD_COMPRESS=lz4
+endif
+export INITRD_COMPRESS
+
# BITS is used as extension for files which are available in a 32 bit
# and a 64 bit version to simplify shared Makefiles.
# e.g.: obj-y += foo_$(BITS).o
diff --git a/init/do_mounts_rd.c b/init/do_mounts_rd.c
index 76faec1..b3d6c38 100644
--- a/init/do_mounts_rd.c
+++ b/init/do_mounts_rd.c
@@ -57,6 +57,11 @@ static int __init crd_load(int in_fd, int out_fd, decompress_fn deco);
* cramfs
* squashfs
* gzip
+ * bzip2
+ * lzma
+ * xz
+ * lzo
+ * lz4
*/
static int __init
identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor)
--
1.8.3.1