a56a5e
From 123feea1fab225478046db43454b10453df95b51 Mon Sep 17 00:00:00 2001
90b079
From: P J P <ppandit@redhat.com>
90b079
Date: Fri, 11 Oct 2013 19:26:51 +0530
90b079
Subject: [PATCH] Add lzo, lz4 compression and read INITRD_COMPRESS
90b079
90b079
This patch adds support for lzop(1) & lz4(1) compression
90b079
algorithms to compress iniramfs image file. Both are supported
90b079
by the Linux kernel.
90b079
90b079
Linux kernel exports user's choice of initramfs compression
90b079
algorithm as a shell environment variable: INITRD_COMPRESS.
90b079
This patch adds support to read this variable and duly compress
90b079
the initramfs image file.
90b079
90b079
Environment variable INITRD_COMPRESS has less precedence than the
90b079
command line options --gzip, etc. Ie. command line options could
90b079
override the compression algorithm defined by $INITRD_COMPRESS.
90b079
90b079
Signed-off-by: P J P <ppandit@redhat.com>
90b079
90b079
[Edited-by: Harald Hoyer: add documentation about lzo and lz4]
90b079
---
90b079
 dracut.8.asc | 16 ++++++++++++++++
90b079
 dracut.sh    | 13 +++++++++++++
90b079
 2 files changed, 29 insertions(+)
90b079
90b079
diff --git a/dracut.8.asc b/dracut.8.asc
1755ca
index 584514c0..2ea67447 100644
90b079
--- a/dracut.8.asc
90b079
+++ b/dracut.8.asc
90b079
@@ -365,6 +365,22 @@ Make sure your kernel has xz decompression support compiled in, otherwise you
90b079
 will not be able to boot. Equivalent to "lzma --compress=xz --check=crc32 --lzma2=dict=1MiB"
90b079
 ====
90b079
 
90b079
+**--lzo**::
90b079
+    Compress the generated initramfs using lzop.
90b079
+[WARNING]
90b079
+====
90b079
+Make sure your kernel has lzo decompression support compiled in, otherwise you
90b079
+will not be able to boot.
90b079
+====
90b079
+
90b079
+**--lz4**::
90b079
+    Compress the generated initramfs using lz4.
90b079
+[WARNING]
90b079
+====
90b079
+Make sure your kernel has lz4 decompression support compiled in, otherwise you
90b079
+will not be able to boot.
90b079
+====
90b079
+
90b079
 **--compress** _<compressor>_::
90b079
     Compress the generated initramfs using the passed compression program. If
90b079
     you pass it just the name of a compression program, it will call that
90b079
diff --git a/dracut.sh b/dracut.sh
1755ca
index d9533dd0..173a259a 100755
90b079
--- a/dracut.sh
90b079
+++ b/dracut.sh
90b079
@@ -165,6 +165,12 @@ Creates initial ramdisk images for preloading modules
90b079
   --xz                  Compress the generated initramfs using xz.
90b079
                          Make sure that your kernel has xz support compiled
90b079
                          in, otherwise you will not be able to boot.
90b079
+  --lzo                  Compress the generated initramfs using lzop.
90b079
+                         Make sure that your kernel has lzo support compiled
90b079
+                         in, otherwise you will not be able to boot.
90b079
+  --lz4                  Compress the generated initramfs using lz4.
90b079
+                         Make sure that your kernel has lz4 support compiled
90b079
+                         in, otherwise you will not be able to boot.
90b079
   --compress [COMPRESSION] Compress the generated initramfs with the
90b079
                          passed compression program.  Make sure your kernel
90b079
                          knows how to decompress the generated initramfs,
90b079
@@ -342,6 +348,8 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
90b079
     --long bzip2 \
90b079
     --long lzma \
90b079
     --long xz \
90b079
+    --long lzo \
90b079
+    --long lz4 \
90b079
     --long no-compress \
90b079
     --long gzip \
90b079
     --long list-modules \
90b079
@@ -430,6 +438,8 @@ while :; do
90b079
         --bzip2)       compress_l="bzip2";;
90b079
         --lzma)        compress_l="lzma";;
90b079
         --xz)          compress_l="xz";;
90b079
+        --lzo)         compress_l="lzo";;
90b079
+        --lz4)         compress_l="lz4";;
90b079
         --no-compress) _no_compress_l="cat";;
90b079
         --gzip)        compress_l="gzip";;
90b079
         --list-modules) do_list="yes";;
90b079
@@ -673,6 +683,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
90b079
 [[ $fw_dir ]] || fw_dir="/lib/firmware/updates /lib/firmware"
90b079
 [[ $tmpdir_l ]] && tmpdir="$tmpdir_l"
90b079
 [[ $tmpdir ]] || tmpdir=/var/tmp
90b079
+[[ $INITRD_COMPRESS ]] && compress=$INITRD_COMPRESS
90b079
 [[ $compress_l ]] && compress=$compress_l
90b079
 [[ $show_modules_l ]] && show_modules=$show_modules_l
90b079
 [[ $nofscks_l ]] && nofscks="yes"
90b079
@@ -689,6 +700,8 @@ case $compress in
90b079
     lzma)  compress="lzma -9";;
90b079
     xz)    compress="xz --check=crc32 --lzma2=dict=1MiB";;
90b079
     gzip)  compress="gzip -9"; command -v pigz > /dev/null 2>&1 && compress="pigz -9";;
90b079
+    lzo)   compress="lzop -9";;
90b079
+    lz4)   compress="lz4 -9";;
90b079
 esac
90b079
 if [[ $_no_compress_l = "cat" ]]; then
90b079
     compress="cat"