Harald Hoyer 35271e
From ec3c59518d9341b6aa2f59ca2eabbe78274efd23 Mon Sep 17 00:00:00 2001
Harald Hoyer 35271e
From: Dave Young <dyoung@redhat.com>
Harald Hoyer 35271e
Date: Mon, 21 May 2012 16:37:06 +0800
Harald Hoyer 35271e
Subject: [PATCH] add option --printsize
Harald Hoyer 35271e
Harald Hoyer 35271e
Add --printsize for measuring module installed size to initramfs
Harald Hoyer 35271e
Harald Hoyer 35271e
Signed-off-by: Dave Young <dyoung@redhat.com>
Harald Hoyer 35271e
---
Harald Hoyer 35271e
 dracut.sh |   11 +++++++++++
Harald Hoyer 35271e
 1 file changed, 11 insertions(+)
Harald Hoyer 35271e
Harald Hoyer 35271e
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 35271e
index bf9e79f..c5151d7 100755
Harald Hoyer 35271e
--- a/dracut.sh
Harald Hoyer 35271e
+++ b/dracut.sh
Harald Hoyer 35271e
@@ -123,6 +123,7 @@ Creates initial ramdisk images for preloading modules
Harald Hoyer 35271e
   -M, --show-modules    Print included module's name to standard output during
Harald Hoyer 35271e
                          build.
Harald Hoyer 35271e
   --keep                Keep the temporary initramfs for debugging purposes
Harald Hoyer 35271e
+  --printsize           Print out the module install size
Harald Hoyer 35271e
   --sshkey [SSHKEY]     Add ssh key to initramfs (use with ssh-client module)
Harald Hoyer 35271e
 
Harald Hoyer 35271e
 If [LIST] has multiple arguments, then you have to put these in quotes.
Harald Hoyer 35271e
@@ -268,6 +269,7 @@ while (($# > 0)); do
Harald Hoyer 35271e
                        show_modules_l="yes"
Harald Hoyer 35271e
                        ;;
Harald Hoyer 35271e
         --keep)        keep="yes";;
Harald Hoyer 35271e
+        --printsize)   printsize="yes";;
Harald Hoyer 35271e
         -*) printf "\nUnknown option: %s\n\n" "$1" >&2; usage; exit 1;;
Harald Hoyer 35271e
         *)
Harald Hoyer 35271e
             if ! [[ ${outfile+x} ]]; then
Harald Hoyer 35271e
@@ -700,6 +702,7 @@ mods_to_load=""
Harald Hoyer 35271e
 for_each_module_dir check_module
Harald Hoyer 35271e
 for_each_module_dir check_mount
Harald Hoyer 35271e
 
Harald Hoyer 35271e
+_isize=0 #initramfs size
Harald Hoyer 35271e
 modules_loaded=" "
Harald Hoyer 35271e
 # source our modules.
Harald Hoyer 35271e
 for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
Harald Hoyer 35271e
@@ -723,6 +726,14 @@ for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
Harald Hoyer 35271e
         fi
Harald Hoyer 35271e
         mods_to_load=${mods_to_load// $_d_mod /}
Harald Hoyer 35271e
         modules_loaded+="$_d_mod "
Harald Hoyer 35271e
+
Harald Hoyer 35271e
+        #print the module install size
Harald Hoyer 35271e
+        if [ -n "$printsize" ]; then
Harald Hoyer 35271e
+            _isize_new=$(du -sk ${initdir}|cut -f1)
Harald Hoyer 35271e
+            _isize_delta=$(($_isize_new - $_isize))
Harald Hoyer 35271e
+            echo "$_d_mod install size: ${_isize_delta}k"
Harald Hoyer 35271e
+            _isize=$_isize_new
Harald Hoyer 35271e
+        fi
Harald Hoyer 35271e
     fi
Harald Hoyer 35271e
 done
Harald Hoyer 35271e
 unset moddir