dracut/0048-Cleanup-compressor-handling.patch
Harald Hoyer 368a0cb66f dracut-043-60.git20150811
- fixed checkiso timeout
- fixed log output although quiet is set
- fixed qemu detection
- cleanup compressor handling
2015-08-11 11:51:20 +02:00

149 lines
4.3 KiB
Diff

From 693b7a32833b7c141f03d802f6bc9a767bdb11f8 Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Wed, 22 Jul 2015 11:34:08 +0200
Subject: [PATCH] Cleanup compressor handling
If no compressor is specified, try to find a suitable one.
Check if kernel modules can be uncompressed.
---
dracut.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++--------------
dracut.spec | 7 +++---
2 files changed, 64 insertions(+), 21 deletions(-)
diff --git a/dracut.sh b/dracut.sh
index ee0a039..27be54a 100755
--- a/dracut.sh
+++ b/dracut.sh
@@ -751,25 +751,53 @@ if [[ -n "$logfile" ]];then
fi
# handle compression options.
-[[ $compress ]] || compress="gzip"
+if [[ $_no_compress_l = "cat" ]]; then
+ compress="cat"
+fi
+
+if ! [[ $compress ]]; then
+ # check all known compressors, if none specified
+ for i in pigz gzip lz4 lzop lzma xz lbzip2 bzip2 cat; do
+ command -v "$i" &>/dev/null || continue
+ compress="$i"
+ break
+ done
+ if [[ $compress = cat ]]; then
+ printf "%s\n" "dracut: no compression tool available. Initramfs image is going to be big." >&2
+ fi
+fi
+
+# choose the right arguments for the compressor
case $compress in
- bzip2) compress="bzip2 -9";
- command -v lbzip2 > /dev/null 2>&1 && compress="lbzip2 -9";;
- lzma) compress="lzma -9 -T0";;
- xz) compress="xz --check=crc32 --lzma2=dict=1MiB -T0";;
- gzip) compress="gzip -n -9";
- if command -v pigz > /dev/null 2>&1; then
+ bzip2|lbzip2)
+ if [[ "$compress" = lbzip2 ]] || command -v lbzip2 &>/dev/null; then
+ compress="lbzip2 -9"
+ else
+ compress="bzip2 -9"
+ fi
+ ;;
+ lzma)
+ compress="lzma -9 -T0"
+ ;;
+ xz)
+ compress="xz --check=crc32 --lzma2=dict=1MiB -T0"
+ ;;
+ gzip|pigz)
+ if [[ "$compress" = pigz ]] || command -v pigz &>/dev/null; then
compress="pigz -9 -n -T -R"
- elif command -v gzip --help 2>&1 | grep -q rsyncable; then
+ elif command -v gzip &>/dev/null && gzip --help 2>&1 | grep -q rsyncable; then
compress="gzip -n -9 --rsyncable"
+ else
+ compress="gzip -n -9"
fi
;;
- lzo) compress="lzop -9";;
- lz4) compress="lz4 -l -9";;
+ lzo|lzop)
+ compress="lzop -9"
+ ;;
+ lz4)
+ compress="lz4 -l -9"
+ ;;
esac
-if [[ $_no_compress_l = "cat" ]]; then
- compress="cat"
-fi
[[ $hostonly = yes ]] && hostonly="-h"
[[ $hostonly != "-h" ]] && unset hostonly
@@ -887,10 +915,26 @@ esac
abs_outfile=$(readlink -f "$outfile") && outfile="$abs_outfile"
-if [[ -d $srcmods ]]; then
- [[ -f $srcmods/modules.dep ]] || {
- dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
- }
+if [[ $no_kernel != yes ]] && [[ -d $srcmods ]]; then
+ if ! [[ -f $srcmods/modules.dep ]]; then
+ dwarn "$srcmods/modules.dep is missing. Did you run depmod?"
+ elif ! ( command -v gzip &>/dev/null && command -v xz &>/dev/null); then
+ read _mod < $srcmods/modules.dep
+ _mod=${_mod%%:*}
+ if [[ -f $srcmods/"$_mod" ]]; then
+ # Check, if kernel modules are compressed, and if we can uncompress them
+ case "$_mod" in
+ *.ko.gz) kcompress=gzip;;
+ *.ko.xz) kcompress=xz;;
+ esac
+ if [[ $kcompress ]]; then
+ if ! command -v "$kcompress" &>/dev/null; then
+ dfatal "Kernel modules are compressed with $kcompress, but $kcompress is not available."
+ exit 1
+ fi
+ fi
+ fi
+ fi
fi
if [[ ! $print_cmdline ]]; then
diff --git a/dracut.spec b/dracut.spec
index 08b281d..6ef5de7 100644
--- a/dracut.spec
+++ b/dracut.spec
@@ -60,7 +60,6 @@ BuildRequires: docbook-style-xsl docbook-dtds libxslt
BuildRequires: asciidoc
%endif
-
%if 0%{?fedora} > 12 || 0%{?rhel}
# no "provides", because dracut does not offer
# all functionality of the obsoleted packages
@@ -94,17 +93,17 @@ Requires: findutils
Requires: grep
Requires: kmod
Requires: sed
+Requires: xz
+Requires: gzip
%if 0%{?fedora} > 22
Recommends: grubby
Recommends: hardlink
-Recommends: gzip
-Recommends: xz
+Recommends: pigz
Recommends: kpartx
%else
Requires: hardlink
Requires: gzip
-Requires: xz
Requires: kpartx
%endif