Blame SOURCES/0212-Dracut-Add-a-new-argument-rebuild.patch

18971c
From f2c5c5c961a91765640f381ec37af085dc91312b Mon Sep 17 00:00:00 2001
18971c
From: Hari Bathini <hbathini@linux.vnet.ibm.com>
18971c
Date: Thu, 16 Jan 2014 12:11:27 +0530
18971c
Subject: [PATCH] Dracut: Add a new argument "--rebuild"
18971c
18971c
Add "rebuild" option to dracut to  append the current  arguments
18971c
to those with  which the input initramfs image was  built.  This
18971c
option helps in incrementally building initramfs for testing.
18971c
18971c
    Usage: dracut [output_file] --rebuild input_file
18971c
18971c
If optional output file  is not provided, input file provided to
18971c
rebuild will be used as output file.
18971c
18971c
This patch alters  the creation of the initramfs image by adding
18971c
the file "/tmp/params.txt" to the image. Command line parameters
18971c
excluding "--rebuild",  input  &  output image names and "kernel
18971c
version" are stored in this file.  In case "--rebuild" parameter
18971c
is specified, "/tmp/params.txt" file, if present in input image,
18971c
is read and its contents "prepend"ed to the current command line
18971c
parameters, that is if such a file is already present. Also,  it
18971c
stores the  cumulative parameters to the file "/tmp/params.txt",
18971c
in the  new image. This patch  has been tested successfully on a
18971c
PowerBox with f19. It does not alter the behaviour of any of the
18971c
existing  options.
18971c
18971c
Signed-off-by: Manik Bajpai <manibajp@linux.vnet.ibm.com>
18971c
Signed-off-by: Hari Bathini <hbathini@linux.vnet.ibm.com>
18971c
18971c
[Edited-by: Harald Hoyer]
18971c
Simplified the cpio extraction process by using 'lsinitrd'.
18971c
18971c
(cherry picked from commit 659dc319d950999f8d191a81fdc4d3114e9213de)
18971c
---
18971c
 dracut.sh | 342 +++++++++++++++++++++++++++++++++---------------------
18971c
 1 file changed, 210 insertions(+), 132 deletions(-)
18971c
18971c
diff --git a/dracut.sh b/dracut.sh
18971c
index 8e5e86f7..eff096e5 100755
18971c
--- a/dracut.sh
18971c
+++ b/dracut.sh
18971c
@@ -70,6 +70,7 @@ Creates initial ramdisk images for preloading modules
18971c
   --kver [VERSION]      Set kernel version to [VERSION].
18971c
   -f, --force           Overwrite existing initramfs file.
18971c
   -a, --add [LIST]      Add a space-separated list of dracut modules.
18971c
+  --rebuild         Append arguments to those of existing image and rebuild
18971c
   -m, --modules [LIST]  Specify a space-separated list of dracut modules to
18971c
                          call when building the initramfs. Modules are located
18971c
                          in /usr/lib/dracut/modules.d.
18971c
@@ -283,132 +284,213 @@ dropindirs_sort()
18971c
     }
18971c
 }
18971c
 
18971c
+rearrange_params()
18971c
+{
18971c
+    # Workaround -i, --include taking 2 arguments
18971c
+    set -- "${@/--include/++include}"
18971c
+
18971c
+    # This prevents any long argument ending with "-i"
18971c
+    # -i, like --opt-i but I think we can just prevent that
18971c
+    set -- "${@/%-i/++include}"
18971c
+
18971c
+    TEMP=$(unset POSIXLY_CORRECT; getopt \
18971c
+        -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
18971c
+        --long kver: \
18971c
+        --long add: \
18971c
+        --long force-add: \
18971c
+        --long add-drivers: \
18971c
+        --long omit-drivers: \
18971c
+        --long modules: \
18971c
+        --long omit: \
18971c
+        --long drivers: \
18971c
+        --long filesystems: \
18971c
+        --long install: \
18971c
+        --long fwdir: \
18971c
+        --long libdirs: \
18971c
+        --long fscks: \
18971c
+        --long add-fstab: \
18971c
+        --long mount: \
18971c
+        --long device: \
18971c
+        --long add-device: \
18971c
+        --long nofscks: \
18971c
+        --long ro-mnt \
18971c
+        --long kmoddir: \
18971c
+        --long conf: \
18971c
+        --long confdir: \
18971c
+        --long tmpdir: \
18971c
+        --long stdlog: \
18971c
+        --long compress: \
18971c
+        --long prefix: \
18971c
+        --long rebuild: \
18971c
+        --long force \
18971c
+        --long kernel-only \
18971c
+        --long no-kernel \
18971c
+        --long print-cmdline \
18971c
+        --long kernel-cmdline: \
18971c
+        --long strip \
18971c
+        --long nostrip \
18971c
+        --long prelink \
18971c
+        --long noprelink \
18971c
+        --long hardlink \
18971c
+        --long nohardlink \
18971c
+        --long noprefix \
18971c
+        --long mdadmconf \
18971c
+        --long nomdadmconf \
18971c
+        --long lvmconf \
18971c
+        --long nolvmconf \
18971c
+        --long debug \
18971c
+        --long profile \
18971c
+        --long sshkey: \
18971c
+        --long logfile: \
18971c
+        --long verbose \
18971c
+        --long quiet \
18971c
+        --long local \
18971c
+        --long hostonly \
18971c
+        --long host-only \
18971c
+        --long no-hostonly \
18971c
+        --long no-host-only \
18971c
+        --long hostonly-cmdline \
18971c
+        --long no-hostonly-cmdline \
18971c
+        --long persistent-policy: \
18971c
+        --long fstab \
18971c
+        --long help \
18971c
+        --long bzip2 \
18971c
+        --long lzma \
18971c
+        --long xz \
18971c
+        --long lzo \
18971c
+        --long lz4 \
18971c
+        --long no-compress \
18971c
+        --long gzip \
18971c
+        --long list-modules \
18971c
+        --long show-modules \
18971c
+        --long keep \
18971c
+        --long printsize \
18971c
+        --long regenerate-all \
18971c
+        --long noimageifnotneeded \
18971c
+        --long early-microcode \
18971c
+        --long no-early-microcode \
18971c
+        -- "$@")
18971c
+
18971c
+    if (( $? != 0 )); then
18971c
+        usage
18971c
+        exit 1
18971c
+    fi
18971c
+}
18971c
+
18971c
 verbosity_mod_l=0
18971c
 unset kernel
18971c
 unset outfile
18971c
 
18971c
-# Workaround -i, --include taking 2 arguments
18971c
-set -- "${@/--include/++include}"
18971c
-
18971c
-# This prevents any long argument ending with "-i"
18971c
-# -i, like --opt-i but I think we can just prevent that
18971c
-set -- "${@/%-i/++include}"
18971c
-
18971c
-TEMP=$(unset POSIXLY_CORRECT; getopt \
18971c
-    -o "a:m:o:d:I:k:c:L:fvqlHhMN" \
18971c
-    --long kver: \
18971c
-    --long add: \
18971c
-    --long force-add: \
18971c
-    --long add-drivers: \
18971c
-    --long omit-drivers: \
18971c
-    --long modules: \
18971c
-    --long omit: \
18971c
-    --long drivers: \
18971c
-    --long filesystems: \
18971c
-    --long install: \
18971c
-    --long fwdir: \
18971c
-    --long libdirs: \
18971c
-    --long fscks: \
18971c
-    --long add-fstab: \
18971c
-    --long mount: \
18971c
-    --long device: \
18971c
-    --long add-device: \
18971c
-    --long nofscks: \
18971c
-    --long ro-mnt \
18971c
-    --long kmoddir: \
18971c
-    --long conf: \
18971c
-    --long confdir: \
18971c
-    --long tmpdir: \
18971c
-    --long stdlog: \
18971c
-    --long compress: \
18971c
-    --long prefix: \
18971c
-    --long force \
18971c
-    --long kernel-only \
18971c
-    --long no-kernel \
18971c
-    --long print-cmdline \
18971c
-    --long kernel-cmdline: \
18971c
-    --long strip \
18971c
-    --long nostrip \
18971c
-    --long prelink \
18971c
-    --long noprelink \
18971c
-    --long hardlink \
18971c
-    --long nohardlink \
18971c
-    --long noprefix \
18971c
-    --long mdadmconf \
18971c
-    --long nomdadmconf \
18971c
-    --long lvmconf \
18971c
-    --long nolvmconf \
18971c
-    --long debug \
18971c
-    --long profile \
18971c
-    --long sshkey: \
18971c
-    --long logfile: \
18971c
-    --long verbose \
18971c
-    --long quiet \
18971c
-    --long local \
18971c
-    --long hostonly \
18971c
-    --long host-only \
18971c
-    --long no-hostonly \
18971c
-    --long no-host-only \
18971c
-    --long hostonly-cmdline \
18971c
-    --long no-hostonly-cmdline \
18971c
-    --long persistent-policy: \
18971c
-    --long fstab \
18971c
-    --long help \
18971c
-    --long bzip2 \
18971c
-    --long lzma \
18971c
-    --long xz \
18971c
-    --long lzo \
18971c
-    --long lz4 \
18971c
-    --long no-compress \
18971c
-    --long gzip \
18971c
-    --long list-modules \
18971c
-    --long show-modules \
18971c
-    --long keep \
18971c
-    --long printsize \
18971c
-    --long regenerate-all \
18971c
-    --long noimageifnotneeded \
18971c
-    --long early-microcode \
18971c
-    --long no-early-microcode \
18971c
-    -- "$@")
18971c
-
18971c
-if (( $? != 0 )); then
18971c
-    usage
18971c
-    exit 1
18971c
+rearrange_params "$@"
18971c
+eval set -- "$TEMP"
18971c
+
18971c
+# parse command line args to check if '--rebuild' option is present
18971c
+unset append_args_l
18971c
+unset rebuild_file
18971c
+while :
18971c
+do
18971c
+	if [ "$1" == "--" ]; then
18971c
+	    shift; break
18971c
+	fi
18971c
+	if [ "$1" == "--rebuild" ]; then
18971c
+	    append_args_l="yes"
18971c
+            rebuild_file=$2
18971c
+            if [ ! -e $rebuild_file ]; then
18971c
+                echo "Image file '$rebuild_file', for rebuild, does not exist!"
18971c
+                exit 1
18971c
+            fi
18971c
+            abs_rebuild_file=$(readlink -f "$rebuild_file") && rebuild_file="$abs_rebuild_file"
18971c
+	    shift; continue
18971c
+	fi
18971c
+	shift
18971c
+done
18971c
+
18971c
+# get output file name and kernel version from command line arguments
18971c
+while (($# > 0)); do
18971c
+    case ${1%%=*} in
18971c
+        ++include)
18971c
+            shift 2;;
18971c
+        *)
18971c
+            if ! [[ ${outfile+x} ]]; then
18971c
+                outfile=$1
18971c
+            elif ! [[ ${kernel+x} ]]; then
18971c
+                kernel=$1
18971c
+            else
18971c
+                printf "\nUnknown arguments: %s\n\n" "$*" >&2
18971c
+                usage; exit 1;
18971c
+            fi
18971c
+            ;;
18971c
+    esac
18971c
+    shift
18971c
+done
18971c
+
18971c
+# extract input image file provided with rebuild option to get previous parameters, if any
18971c
+if [[ $append_args_l == "yes" ]]; then
18971c
+    unset rebuild_param
18971c
+
18971c
+    # determine resultant file
18971c
+    if ! [[ $outfile ]]; then
18971c
+        outfile=$rebuild_file
18971c
+    fi
18971c
+
18971c
+    if ! rebuild_param=$(lsinitrd $rebuild_file '*lib/dracut/build-parameter.txt'); then
18971c
+        echo "Image '$rebuild_file' has no rebuild information stored"
18971c
+        exit 1
18971c
+    fi
18971c
+
18971c
+    # prepend previous parameters to current command line args
18971c
+    if [[ $rebuild_param ]]; then
18971c
+        TEMP="$rebuild_param $TEMP"
18971c
+        eval set -- "$TEMP"
18971c
+        rearrange_params "$@"
18971c
+    fi
18971c
+
18971c
+    # clean the temporarily used scratch-pad directory
18971c
+    rm -rf $scratch_dir
18971c
 fi
18971c
 
18971c
+unset PARMS_TO_STORE
18971c
+PARMS_TO_STORE=""
18971c
+
18971c
 eval set -- "$TEMP"
18971c
 
18971c
 while :; do
18971c
+    if [ $1 != "--" ] && [ $1 != "--rebuild" ]; then
18971c
+        PARMS_TO_STORE+=" $1";
18971c
+    fi
18971c
     case $1 in
18971c
-        --kver)        kernel="$2"; shift;;
18971c
-        -a|--add)      push add_dracutmodules_l  "$2"; shift;;
18971c
-        --force-add)   push force_add_dracutmodules_l  "$2"; shift;;
18971c
-        --add-drivers) push add_drivers_l        "$2"; shift;;
18971c
-        --omit-drivers)
18971c
-                       push omit_drivers_l      "$2"; shift;;
18971c
-        -m|--modules)  push dracutmodules_l      "$2"; shift;;
18971c
-        -o|--omit)     push omit_dracutmodules_l "$2"; shift;;
18971c
-        -d|--drivers)  push drivers_l            "$2"; shift;;
18971c
-        --filesystems) push filesystems_l        "$2"; shift;;
18971c
-        -I|--install)  push install_items_l      "$2"; shift;;
18971c
-        --fwdir)       push fw_dir_l             "$2"; shift;;
18971c
-        --libdirs)     push libdirs_l            "$2"; shift;;
18971c
-        --fscks)       push fscks_l              "$2"; shift;;
18971c
-        --add-fstab)   push add_fstab_l          "$2"; shift;;
18971c
-        --mount)       push fstab_lines          "$2"; shift;;
18971c
+        --kver)        kernel="$2";                    PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -a|--add)      push add_dracutmodules_l  "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --force-add)   push force_add_dracutmodules_l  "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --add-drivers) push add_drivers_l        "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --omit-drivers) push omit_drivers_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -m|--modules)  push dracutmodules_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -o|--omit)     push omit_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -d|--drivers)  push drivers_l            "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --filesystems) push filesystems_l        "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -I|--install)  push install_items_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --fwdir)       push fw_dir_l             "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --libdirs)     push libdirs_l            "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --fscks)       push fscks_l              "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --add-fstab)   push add_fstab_l          "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --mount)       push fstab_lines          "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
         --add-device|--device)
18971c
-                       push add_device_l         "$2"; shift;;
18971c
-        --kernel-cmdline)
18971c
-                       push kernel_cmdline_l  "$2"; shift;;
18971c
+                       push add_device_l         "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --kernel-cmdline) push kernel_cmdline_l  "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
18971c
         --nofscks)     nofscks_l="yes";;
18971c
         --ro-mnt)      ro_mnt_l="yes";;
18971c
-        -k|--kmoddir)  drivers_dir_l="$2"; shift;;
18971c
-        -c|--conf)     conffile="$2"; shift;;
18971c
-        --confdir)     confdir="$2"; shift;;
18971c
-        --tmpdir)      tmpdir_l="$2"; shift;;
18971c
-        -L|--stdlog)   stdloglvl_l="$2"; shift;;
18971c
-        --compress)    compress_l="$2"; shift;;
18971c
-        --prefix)      prefix_l="$2"; shift;;
18971c
+        -k|--kmoddir)  drivers_dir_l="$2";             PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -c|--conf)     conffile="$2";                  PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --confdir)     confdir="$2";                   PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --tmpdir)      tmpdir_l="$2";                  PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        -L|--stdlog)   stdloglvl_l="$2";               PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --compress)    compress_l="$2";                PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --prefix)      prefix_l="$2";                  PARMS_TO_STORE+=" '$2'"; shift;;
18971c
+        --rebuild)     if [ $rebuild_file == $outfile ]; then
18971c
+                           force=yes
18971c
+                       fi
18971c
+                       shift
18971c
+                       ;;
18971c
         -f|--force)    force=yes;;
18971c
         --kernel-only) kernel_only="yes"; no_kernel="no";;
18971c
         --no-kernel)   kernel_only="no"; no_kernel="yes";;
18971c
@@ -431,7 +513,7 @@ while :; do
18971c
         --nolvmconf)   lvmconf_l="no";;
18971c
         --debug)       debug="yes";;
18971c
         --profile)     profile="yes";;
18971c
-        --sshkey)      sshkey="$2"; shift;;
18971c
+        --sshkey)      sshkey="$2";                    PARMS_TO_STORE+=" '$2'"; shift;;
18971c
         --logfile)     logfile_l="$2"; shift;;
18971c
         -v|--verbose)  ((verbosity_mod_l++));;
18971c
         -q|--quiet)    ((verbosity_mod_l--));;
18971c
@@ -449,11 +531,10 @@ while :; do
18971c
         --no-hostonly-cmdline)
18971c
                        hostonly_cmdline_l="no" ;;
18971c
         --persistent-policy)
18971c
-                       persistent_policy_l="$2"; shift;;
18971c
+                       persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
18971c
         --fstab)       use_fstab_l="yes" ;;
18971c
         -h|--help)     long_usage; exit 1 ;;
18971c
-        -i|--include)
18971c
-                       push include_src "$2"
18971c
+        -i|--include)  push include_src "$2";          PARMS_TO_STORE+=" '$2'";
18971c
                        shift;;
18971c
         --bzip2)       compress_l="bzip2";;
18971c
         --lzma)        compress_l="lzma";;
18971c
@@ -483,21 +564,12 @@ done
18971c
 # the old fashioned way
18971c
 
18971c
 while (($# > 0)); do
18971c
-    case ${1%%=*} in
18971c
-        ++include) push include_src "$2"
18971c
-                       push include_target "$3"
18971c
-                       shift 2;;
18971c
-        *)
18971c
-            if ! [[ ${outfile+x} ]]; then
18971c
-                outfile=$1
18971c
-            elif ! [[ ${kernel+x} ]]; then
18971c
-                kernel=$1
18971c
-            else
18971c
-                printf "\nUnknown arguments: %s\n\n" "$*" >&2
18971c
-                usage; exit 1;
18971c
-            fi
18971c
-            ;;
18971c
-    esac
18971c
+    if [ ${1%%=*} == "++include" ]; then
18971c
+        push include_src "$2"
18971c
+        push include_target "$3"
18971c
+        PARMS_TO_STORE+=" --include '$2' '$3'"
18971c
+        shift 2
18971c
+    fi
18971c
     shift
18971c
 done
18971c
 
18971c
@@ -1405,6 +1477,12 @@ if [[ $acpi_override = yes ]] && [[ -d $acpi_table_dir ]]; then
18971c
     done
18971c
 fi
18971c
 
18971c
+dinfo "*** Store current command line parameters ***"
18971c
+if ! ( echo $PARMS_TO_STORE > $initdir/lib/dracut/build-parameter.txt ); then
18971c
+    dfatal "Could not store the current command line parameters"
18971c
+    exit 1
18971c
+fi
18971c
+
18971c
 rm -f -- "$outfile"
18971c
 dinfo "*** Creating image file ***"
18971c