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

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