]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
strip binaries in initramfs
authorHarald Hoyer <harald@redhat.com>
Fri, 24 Jul 2009 13:48:20 +0000 (15:48 +0200)
committerHarald Hoyer <harald@redhat.com>
Sat, 25 Jul 2009 09:09:35 +0000 (11:09 +0200)
       --strip
              strip binaries in the initramfs (default)

       --nostrip
              do not strip binaries in the initramfs

dracut
dracut.8

diff --git a/dracut b/dracut
index 16f0e6ebccd49fc58bedfd22907560fe91f23bf9..f738a63a8c7dc11d8dbd7e6838c074e515c247f2 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -41,6 +41,8 @@ Creates initial ramdisk images for preloading modules
                         firmwares, separated by :
   --kernel-only         Only install kernel drivers and firmware files
   --no-kernel           Do not install kernel drivers and firmware files
+  --strip               Strip binaries in the initramfs (default)
+  --nostrip             Do not strip binaries in the initramfs
   -h, --help            This message
   --debug               Output debug information of the build process
   -v, --verbose         Verbose output during the build process
@@ -71,6 +73,8 @@ while (($# > 0)); do
        --fwdir) fw_dir_l="$2"; shift;;
        --kernel-only) kernel_only="yes"; nokernel="no";;
        --no-kernel) kernel_only="no"; no_kernel="yes";;
+       --strip) do_strip_l="yes";;
+       --nostrip) do_strip_l="no";;
        -h|--help) usage; exit 1 ;;
        --debug) debug="yes";;
        -v|--verbose) beverbose="yes";;
@@ -105,8 +109,10 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
 [[ $drivers_l ]] && drivers=$drivers_l
 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
 [[ $fw_dir_l ]] && fw_dir=$fw_dir_l
+[[ $do_strip_l ]] && do_strip=$do_strip_l
 [[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
 [[ $fw_dir ]] || fw_dir=/lib/firmware
+[[ $do_strip ]] || do_strip=yes
 
 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir
 
@@ -203,6 +209,35 @@ unset item
 
 [[ "$beverbose" = "yes" ]] && (du -c "$initdir" | sort -n)
 
+# strip binaries 
+if [ "$do_strip" = "yes" ] ; then
+    for p in strip objdump sed grep find; do 
+       if ! which $p >/dev/null 2>&1; then
+           derror "Could not find '$p'. You should run $0 with '--nostrip'."
+           do_strip=no
+       fi
+    done
+fi
+
+if [ "$do_strip" = "yes" ] ; then
+    for f in $(find "$initdir" -type f \( -perm -0100 -or -perm -0010 -or -perm -0001 \) -exec file {} \; | 
+       grep -v ' shared object,' | 
+       sed -n -e 's/^\(.*\):[  ]*ELF.*, not stripped/\1/p'); do
+       dinfo "Stripping $f"
+       strip -g "$f" || :
+        #
+        # FIXME: only strip -g for now
+        #
+       #strip -g --strip-unneeded "$f" || :
+       #note="-R .note"
+       #if objdump -h $f | grep '^[    ]*[0-9]*[       ]*.note[        ]' -A 1 | \
+       #    grep -q ALLOC; then
+       #    note=
+       #fi
+       #strip -R .comment $note "$f" || :
+    done
+fi
+
 ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; )
 
 [[ "$beverbose" = "yes" ]] && ls -lh "$outfile"
index 4578d38e41d2442b8c40cd69bf037e09ab12c9f2..37c73bfb7a1fe51ab31c4da94eb953e0440de258 100644 (file)
--- a/dracut.8
+++ b/dracut.8
@@ -42,6 +42,12 @@ only install kernel drivers and firmware files
 .BR \-\-no-kernel
 do not install kernel drivers and firmware files
 .TP
+.BR \-\-strip
+strip binaries in the initramfs (default)
+.TP
+.BR \-\-nostrip
+do not strip binaries in the initramfs
+.TP
 .BR \-h ", " \-\-help
 display help text and exit. 
 .TP