Blame 0031-dracut.sh-Add-noimageifnotneeded-parameter.patch

Harald Hoyer a20c0e
From 83bb0893edc1c12bbaca20267134b01df2836e1c Mon Sep 17 00:00:00 2001
Harald Hoyer a20c0e
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer a20c0e
Date: Wed, 13 Mar 2013 14:47:24 +0100
Harald Hoyer a20c0e
Subject: [PATCH] dracut.sh: Add --noimageifnotneeded parameter
Harald Hoyer a20c0e
Harald Hoyer a20c0e
Do not create an image in host-only mode, if no kernel driver is needed
Harald Hoyer a20c0e
and no $initdir/etc/cmdline/*.conf is generated.
Harald Hoyer a20c0e
---
Harald Hoyer a20c0e
 50-dracut.install         | 19 ++++++++++++++++++-
Harald Hoyer a20c0e
 dracut-bash-completion.sh |  2 +-
Harald Hoyer a20c0e
 dracut.sh                 | 12 ++++++++++++
Harald Hoyer a20c0e
 3 files changed, 31 insertions(+), 2 deletions(-)
Harald Hoyer a20c0e
Harald Hoyer a20c0e
diff --git a/50-dracut.install b/50-dracut.install
Harald Hoyer a20c0e
index 9e99899..6b63da9 100755
Harald Hoyer a20c0e
--- a/50-dracut.install
Harald Hoyer a20c0e
+++ b/50-dracut.install
Harald Hoyer a20c0e
@@ -2,10 +2,27 @@
Harald Hoyer a20c0e
 # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
Harald Hoyer a20c0e
 # ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
+if [[ -f /etc/kernel/cmdline ]]; then
Harald Hoyer a20c0e
+    readarray -t BOOT_OPTIONS < /etc/kernel/cmdline
Harald Hoyer a20c0e
+fi
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+if ! [[ "${BOOT_OPTIONS[@]}" ]]; then
Harald Hoyer a20c0e
+    readarray -t BOOT_OPTIONS < /proc/cmdline
Harald Hoyer a20c0e
+fi
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+unset noimageifnotneeded
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+for ((i=0; i < "${#BOOT_OPTIONS[@]}"; i++)); do
Harald Hoyer a20c0e
+    if [[ ${BOOT_OPTIONS[$i]} == root\=PARTUUID\=* ]]; then
Harald Hoyer a20c0e
+        noimageifnotneeded="yes"
Harald Hoyer a20c0e
+        break
Harald Hoyer a20c0e
+    fi
Harald Hoyer a20c0e
+done
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
 ret=0
Harald Hoyer a20c0e
 case "$1" in
Harald Hoyer a20c0e
     add)
Harald Hoyer a20c0e
-	dracut "$3"/initrd "$2"
Harald Hoyer a20c0e
+	dracut ${noimageifnotneeded+--noimageifnotneeded} "$3"/initrd "$2"
Harald Hoyer a20c0e
         ret=$?
Harald Hoyer a20c0e
 	;;
Harald Hoyer a20c0e
     remove)
Harald Hoyer a20c0e
diff --git a/dracut-bash-completion.sh b/dracut-bash-completion.sh
Harald Hoyer a20c0e
index da067c5..38e2ebd 100644
Harald Hoyer a20c0e
--- a/dracut-bash-completion.sh
Harald Hoyer a20c0e
+++ b/dracut-bash-completion.sh
Harald Hoyer a20c0e
@@ -33,7 +33,7 @@ _dracut() {
Harald Hoyer a20c0e
                               --lvmconf --nolvmconf --debug --profile --verbose --quiet
Harald Hoyer a20c0e
                               --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
Harald Hoyer a20c0e
                               --xz --no-compress --gzip --list-modules --show-modules --keep
Harald Hoyer a20c0e
-                              --printsize --regenerate-all'
Harald Hoyer a20c0e
+                              --printsize --regenerate-all --noimageifnotneeded'
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
                        [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
Harald Hoyer a20c0e
                               --omit-drivers --modules --omit --drivers --filesystems --install
Harald Hoyer a20c0e
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer a20c0e
index 2582f74..69f5282 100755
Harald Hoyer a20c0e
--- a/dracut.sh
Harald Hoyer a20c0e
+++ b/dracut.sh
Harald Hoyer a20c0e
@@ -330,6 +330,7 @@ TEMP=$(unset POSIXLY_CORRECT; getopt \
Harald Hoyer a20c0e
     --long keep \
Harald Hoyer a20c0e
     --long printsize \
Harald Hoyer a20c0e
     --long regenerate-all \
Harald Hoyer a20c0e
+    --long noimageifnotneeded \
Harald Hoyer a20c0e
     -- "$@")
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
 if (( $? != 0 )); then
Harald Hoyer a20c0e
@@ -408,6 +409,7 @@ while :; do
Harald Hoyer a20c0e
         --keep)        keep="yes";;
Harald Hoyer a20c0e
         --printsize)   printsize="yes";;
Harald Hoyer a20c0e
         --regenerate-all) regenerate_all="yes";;
Harald Hoyer a20c0e
+        --noimageifnotneeded) noimageifnotneeded="yes";;
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
         --) shift; break;;
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
@@ -1020,6 +1022,16 @@ if [[ $no_kernel != yes ]]; then
Harald Hoyer a20c0e
     dinfo "*** Installing kernel module dependencies and firmware ***"
Harald Hoyer a20c0e
     dracut_kernel_post
Harald Hoyer a20c0e
     dinfo "*** Installing kernel module dependencies and firmware done ***"
Harald Hoyer a20c0e
+
Harald Hoyer a20c0e
+    if [[ $noimageifnotneeded == yes ]] && [[ $hostonly ]]; then
Harald Hoyer a20c0e
+        if [[ ! -f "$initdir/lib/dracut/need-initqueue" ]] && \
Harald Hoyer a20c0e
+            [[ -f ${initdir}/lib/modules/$kernel/modules.dep && ! -s ${initdir}/lib/modules/$kernel/modules.dep ]]; then
Harald Hoyer a20c0e
+            for i in ${initdir}/etc/cmdline.d/*.conf; do
Harald Hoyer a20c0e
+                # We need no initramfs image and do not generate one.
Harald Hoyer a20c0e
+                [[ $i == "${initdir}/etc/cmdline.d/*.conf" ]] && exit 0
Harald Hoyer a20c0e
+            done
Harald Hoyer a20c0e
+        fi
Harald Hoyer a20c0e
+    fi
Harald Hoyer a20c0e
 fi
Harald Hoyer a20c0e
 
Harald Hoyer a20c0e
 if [[ $kernel_only != yes ]]; then