From: rjones Date: Mon, 23 Mar 2009 16:54:18 +0000 (+0000) Subject: Add an option to pack executables. X-Git-Tag: 1.5~20 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=2c02cadef79f6e488f203ecc7e0d1eda0fafe849;p=febootstrap.git Add an option to pack executables. Be careful to retain same inode number for /etc/services. --- diff --git a/README b/README index 33087a7..e9391e8 100644 --- a/README +++ b/README @@ -34,6 +34,9 @@ Requirements MAKEDEV + upx + - Ultimate Packer for eXecutables, for minimizing binaries + qemu - If you want to test-run your systems. diff --git a/examples/minimal-filesystem.sh b/examples/minimal-filesystem.sh index 01ca9e8..9a0f575 100755 --- a/examples/minimal-filesystem.sh +++ b/examples/minimal-filesystem.sh @@ -27,7 +27,7 @@ fi # ... but let's minimize it aggressively. echo -n "Before minimization: "; du -sh minimal -../febootstrap-minimize --all ./minimal +../febootstrap-minimize --all --pack-executables ./minimal echo -n "After minimization: "; du -sh minimal # Create the /init which is just a simple script to give users an diff --git a/febootstrap-minimize.pod b/febootstrap-minimize.pod index e7a2084..96cb177 100644 --- a/febootstrap-minimize.pod +++ b/febootstrap-minimize.pod @@ -117,6 +117,16 @@ C (the dynamic linking cache). This is not needed. Dynamic linking during program execution will be marginally slower. +=item B<--no-pack-executables> + +=item B<--pack-executables> + +Pack executables and shell scripts using L. + +This is not done by default because although it can reduce the image +size, it increases the amount of memory used since those executables +cannot be shared. + =back =head1 TODO @@ -136,10 +146,6 @@ Remove unused binaries. Remove unused libraries. -=item * - -Pack executables using UPX. - =back =head1 SEE ALSO diff --git a/febootstrap-minimize.sh b/febootstrap-minimize.sh index 58b86fa..90915e3 100755 --- a/febootstrap-minimize.sh +++ b/febootstrap-minimize.sh @@ -20,7 +20,7 @@ TEMP=`getopt \ -o '' \ - --long help,all,none,keep-locales,drop-locales,keep-docs,drop-docs,keep-cracklib,drop-cracklib,keep-i18n,drop-i18n,keep-zoneinfo,drop-zoneinfo,keep-rpmdb,drop-rpmdb,keep-yum-cache,drop-yum-cache,keep-services,drop-services,keep-sln,drop-sln,keep-ldconfig,drop-ldconfig \ + --long help,all,none,keep-locales,drop-locales,keep-docs,drop-docs,keep-cracklib,drop-cracklib,keep-i18n,drop-i18n,keep-zoneinfo,drop-zoneinfo,keep-rpmdb,drop-rpmdb,keep-yum-cache,drop-yum-cache,keep-services,drop-services,keep-sln,drop-sln,keep-ldconfig,drop-ldconfig,no-pack-executables,pack-executables \ -n febootstrap-minimize -- "$@"` if [ $? != 0 ]; then echo "febootstrap-minimize: problem parsing the command line arguments" @@ -57,6 +57,7 @@ keep_yum_cache=yes } set_all +pack_executables=no usage () { @@ -132,6 +133,12 @@ while true; do --drop-ldconfig) keep_ldconfig=no shift;; + --no-pack-executables) + pack_executables=no + shift;; + --pack-executables) + pack_executables=yes + shift;; --help) usage exit 0;; @@ -151,14 +158,21 @@ fi target="$1" -#---------------------------------------------------------------------- - if [ ! -d "$target" ]; then echo "febootstrap-minimize: $target: target directory not found" exit 1 fi -#du -sh "$target" +# Create a temporary directory, make sure it gets cleaned up at the end. +tmpdir=$(mktemp -d) +remove_tmpdir () +{ + status=$? + rm -rf "$tmpdir" && exit $status +} +trap remove_tmpdir EXIT + +#---------------------------------------------------------------------- if [ "$keep_locales" != "yes" ]; then rm -f "$target"/usr/lib/locale/* @@ -199,7 +213,8 @@ if [ "$keep_yum_cache" != "yes" ]; then fi if [ "$keep_services" != "yes" ]; then - rm -f "$target"/etc/services + # NB: Overwrite the same file so that we have the same inode, + # since fakeroot tracks files by inode number. cat > "$target"/etc/services <<'__EOF__' tcpmux 1/tcp tcpmux 1/udp @@ -259,4 +274,19 @@ if [ "$keep_ldconfig" != "yes" ]; then rm -f "$target"/sbin/ldconfig rm -f "$target"/etc/ld.so.cache rm -rf "$target"/var/cache/ldconfig/* -fi \ No newline at end of file +fi + +if [ "$pack_executables" = "yes" ]; then + # NB. Be careful to keep the same inode number, since fakeroot + # tracks files by inode number. + for path in $(find "$target" -type f -perm /111 | + xargs file | + grep executable | + awk -F: '{print $1}'); do + base=$(basename $path) + cp $path $tmpdir + (cd $tmpdir && upx -q -q --best $base) + cat $tmpdir/$base > $path + rm $tmpdir/$base + done +fi diff --git a/febootstrap.spec.in b/febootstrap.spec.in index 0c5db41..ae95abf 100644 --- a/febootstrap.spec.in +++ b/febootstrap.spec.in @@ -19,6 +19,7 @@ Requires: yum >= 3.2 Requires: MAKEDEV Requires: util-linux-ng Requires: cpio +Requires: upx # These are suggestions. However making them hard requirements # pulls in far too much stuff.