From 1b640fb0bd84f88d378b6c4a74088ac22c8f7d75 Mon Sep 17 00:00:00 2001 From: rjones Date: Fri, 20 Mar 2009 11:01:39 +0000 Subject: [PATCH] Add first version of the febootstrap-minimize script. --- .cvsignore | 2 +- Makefile.am | 30 +++++--- configure.ac | 2 +- examples/minimal-filesystem.sh | 10 ++- febootstrap-fix-root.pod | 41 ----------- febootstrap-minimize.pod | 113 +++++++++++++++++++++++++++++ febootstrap-minimize.sh | 159 +++++++++++++++++++++++++++++++++++++++++ febootstrap-to-initramfs.pod | 1 - febootstrap.pod | 14 +++- febootstrap.sh | 12 +++- 10 files changed, 326 insertions(+), 58 deletions(-) delete mode 100644 febootstrap-fix-root.pod create mode 100644 febootstrap-minimize.pod create mode 100755 febootstrap-minimize.sh diff --git a/.cvsignore b/.cvsignore index 9abf25a..4842195 100644 --- a/.cvsignore +++ b/.cvsignore @@ -11,6 +11,6 @@ config.log config.status configure febootstrap -febootstrap-fix-root +febootstrap-minimize febootstrap-to-initramfs stamp-h1 diff --git a/Makefile.am b/Makefile.am index 2c7cfcc..afa11f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,10 @@ SUBDIRS = examples -bin_SCRIPTS = febootstrap febootstrap-to-initramfs +bin_SCRIPTS = \ + febootstrap \ + febootstrap-minimize \ + febootstrap-to-initramfs febootstrap: febootstrap.sh rm -f $@ @@ -27,15 +30,25 @@ febootstrap: febootstrap.sh chmod 0555 $@-t mv $@-t $@ +febootstrap-minimize: febootstrap-minimize.sh + rm -f $@ + cp $< $@-t + chmod 0555 $@-t + mv $@-t $@ + febootstrap-to-initramfs: febootstrap-to-initramfs.sh rm -f $@ cp $< $@-t chmod 0555 $@-t mv $@-t $@ -man_MANS = febootstrap.8 febootstrap-to-initramfs.8 febootstrap-fix-root.8 +man_MANS = \ + febootstrap.8 \ + febootstrap-minimize.8 \ + febootstrap-to-initramfs.8 if HAVE_PERLDOC + febootstrap.8: febootstrap.pod pod2man \ --section 8 \ @@ -46,32 +59,33 @@ febootstrap.8: febootstrap.pod febootstrap.txt: febootstrap.pod pod2text $< > $@ -febootstrap-to-initramfs.8: febootstrap-to-initramfs.pod +febootstrap-minimize.8: febootstrap-minimize.pod pod2man \ --section 8 \ -c "Virtualization Support" \ --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \ $< > $@ -febootstrap-to-initramfs.txt: febootstrap-to-initramfs.pod +febootstrap-minimize.txt: febootstrap-minimize.pod pod2text $< > $@ -febootstrap-fix-root.8: febootstrap-fix-root.pod +febootstrap-to-initramfs.8: febootstrap-to-initramfs.pod pod2man \ --section 8 \ -c "Virtualization Support" \ --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \ $< > $@ -febootstrap-fix-root.txt: febootstrap-fix-root.pod +febootstrap-to-initramfs.txt: febootstrap-to-initramfs.pod pod2text $< > $@ + endif EXTRA_DIST = \ fakechroot-2.8-relchroot.patch \ febootstrap.8 febootstrap.txt febootstrap.pod \ + febootstrap-minimize.8 febootstrap-minimize.txt \ + febootstrap-minimize.pod \ febootstrap-to-initramfs.8 febootstrap-to-initramfs.txt \ febootstrap-to-initramfs.pod \ - febootstrap-fix-root.8 febootstrap-fix-root.txt \ - febootstrap-fix-root.pod \ febootstrap.sh febootstrap-to-initramfs.sh diff --git a/configure.ac b/configure.ac index 48bb839..d47d668 100644 --- a/configure.ac +++ b/configure.ac @@ -17,7 +17,7 @@ dnl Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. dnl dnl Written by Richard W.M. Jones -AC_INIT(febootstrap,0.8) +AC_INIT(febootstrap,0.9) AM_INIT_AUTOMAKE AC_CHECK_PROG(PERLDOC,[perldoc],[perldoc],[no]) diff --git a/examples/minimal-filesystem.sh b/examples/minimal-filesystem.sh index 74a4c2c..1ef6928 100755 --- a/examples/minimal-filesystem.sh +++ b/examples/minimal-filesystem.sh @@ -12,7 +12,13 @@ # few command line utilities. One of the joys of Fedora is that even # this minimal install is still 200 MB ... -../febootstrap -i bash -i coreutils fedora-10 ./minimal +../febootstrap -i bash -i coreutils fedora-10 ./minimal $1 + +# ... but let's minimize it aggressively. + +echo -n "Before minimization: "; du -sh minimal +../febootstrap-minimize --all ./minimal +echo -n "After minimization: "; du -sh minimal # Create the /init which is just a simple script to give users an # interactive shell. @@ -39,6 +45,6 @@ dd if=/dev/zero of=zero bs=2048 count=1 # Now run qemu to boot this minimal system. qemu-system-$(arch) \ - -m 1024 \ + -m 128 \ -kernel vmlinuz -initrd minimal-initrd.img \ -hda zero -boot c diff --git a/febootstrap-fix-root.pod b/febootstrap-fix-root.pod deleted file mode 100644 index 78e5d3d..0000000 --- a/febootstrap-fix-root.pod +++ /dev/null @@ -1,41 +0,0 @@ -=head1 NAME - -febootstrap-fix-root - Fix ownership and permissions inside febootstrap root - -=head1 SYNOPSIS - - febootstrap-fix-root DIR - -=head1 DESCRIPTION - - - - -=head1 SEE ALSO - -L, -L, -L. - -=head1 AUTHORS - -Richard W.M. Jones - -=head1 COPYRIGHT - -(C) Copyright 2009 Red Hat Inc., -L. - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. diff --git a/febootstrap-minimize.pod b/febootstrap-minimize.pod new file mode 100644 index 0000000..8d02d5d --- /dev/null +++ b/febootstrap-minimize.pod @@ -0,0 +1,113 @@ +=head1 NAME + +febootstrap-minimize - Minimize an febootstrap image + +=head1 SYNOPSIS + + febootstrap-minimize [--options] DIR + +=head1 DESCRIPTION + +I minimizes an L-created +filesystem. This means that unneeded files and cruft are removed from +the image. + +If no options are given, the default is to minimize the image as much +as possible. This means, for example, that locales are removed so the +image will only be usable in US-English, there will be no +documentation or manual pages, and the image will only work in a UTC +timezone. + +Note that image minimization involves deleting files that have been +installed by RPM. Thus after minimization, it is no longer guaranteed +that RPM will function correctly on the image. You should only do +this as a final step for "throwaway" appliances that do not need to be +modified or upgraded in future. + +=head1 OPTIONS + +=over 4 + +=item B<--all> + +Perform all minimization operations, to produce the smallest possible +image. Note in particular that locales are discarded. + +You can perform all minimization operations I X, Y and Z by +doing: + + febootstrap-minimize --all --keep-X --keep-Y --keep-Z ... + +(C<--all> can be omitted since it is the default). + +=item B<--none> + +Start with no minimization operations. You can specify I +minimization operations X, Y and Z like this: + + febootstrap-minimize --none --drop-X --drop-Y --drop-Z ... + +=item B<--keep-locales> + +=item B<--drop-locales> + +Keep or drop locale support. + +=item B<--keep-docs> + +=item B<--drop-docs> + +Keep or drop documentation and man pages. + +=item B<--keep-yum-cache> + +=item B<--drop-yum-cache> + +Keep or drop the yum cache. + +=item B<--keep-cracklib> + +=item B<--drop-cracklib> + +Keep or drop cracklib libraries. + +=item B<--keep-i18n> + +=item B<--drop-i18n> + +Keep or drop C. + +=item B<--keep-zoneinfo> + +=item B<--drop-zoneinfo> + +Keep or drop all timezones (except UTC which is never deleted). + +=back + +=head1 SEE ALSO + +L. + +=head1 AUTHORS + +Richard W.M. Jones + +=head1 COPYRIGHT + +(C) Copyright 2009 Red Hat Inc., +L. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. diff --git a/febootstrap-minimize.sh b/febootstrap-minimize.sh new file mode 100755 index 0000000..f39beaa --- /dev/null +++ b/febootstrap-minimize.sh @@ -0,0 +1,159 @@ +#!/bin/bash - +# febootstrap minimize +# (C) Copyright 2009 Red Hat Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Written by Richard W.M. Jones + +TEMP=`getopt \ + -o '' \ + --long help,all,none,keep-locales,drop-locales,keep-docs,drop-docs,keep-yum-cache,drop-yum-cache,keep-cracklib,drop-cracklib,keep-i18n,drop-i18n,keep-zoneinfo,drop-zoneinfo \ + -n febootstrap-minimize -- "$@"` +if [ $? != 0 ]; then + echo "febootstrap-minimize: problem parsing the command line arguments" + exit 1 +fi +eval set -- "$TEMP" + +set_all () +{ + keep_locales=no + keep_docs=no +keep_yum_cache=no + keep_cracklib=no + keep_i18n=no + keep_zoneinfo=no +} + +set_none () +{ + keep_locales=yes + keep_docs=yes +keep_yum_cache=yes + keep_cracklib=yes + keep_i18n=yes + keep_zoneinfo=yes +} + +set_all + +usage () +{ + echo "Usage: febootstrap-minimize [--options] DIR" + echo "Please read febootstrap-minimize(8) man page for more information." +} + +while true; do + case "$1" in + --all) + set_all + shift;; + --none) + set_none + shift;; + --keep-locales) + keep_locales=yes + shift;; + --drop-locales) + keep_locales=no + shift;; + --keep-docs) + keep_docs=yes + shift;; + --drop-docs) + keep_docs=no + shift;; + --keep-yum-cache) + keep_yum_cache=yes + shift;; + --drop-yum-cache) + keep_yum_cache=no + shift;; + --keep-cracklib) + keep_cracklib=yes + shift;; + --drop-cracklib) + keep_cracklib=no + shift;; + --keep-i18n) + keep_i18n=yes + shift;; + --drop-i18n) + keep_i18n=no + shift;; + --keep-zoneinfo) + keep_zoneinfo=yes + shift;; + --drop-zoneinfo) + keep_zoneinfo=no + shift;; + --help) + usage + exit 0;; + --) + shift + break;; + *) + echo "Internal error!" + exit 1;; + esac +done + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +target="$1" + +#---------------------------------------------------------------------- + +if [ ! -d "$target" ]; then + echo "febootstrap-minimize: $target: target directory not found" + exit 1 +fi + +#du -sh "$target" + +if [ "$keep_locales" != "yes" ]; then + rm -f "$target"/usr/lib/locale/* + rm -rf "$target"/usr/share/locale +fi + +if [ "$keep_docs" != "yes" ]; then + rm -rf "$target"/usr/share/man + rm -rf "$target"/usr/share/doc +fi + +if [ "$keep_yum_cache" != "yes" ]; then + rm -rf "$target"/var/cache/yum/* +fi + +if [ "$keep_cracklib" != "yes" ]; then + rm -rf "$target"/usr/share/cracklib +fi + +if [ "$keep_i18n" != "yes" ]; then + rm -rf "$target"/usr/share/i18n +fi + +if [ "$keep_zoneinfo" != "yes" ]; then + mv "$target"/usr/share/zoneinfo/{UCT,UTC,Universal,Zulu,GMT*,*.tab} \ + "$target" + rm -rf "$target"/usr/share/zoneinfo/* + mv "$target"/{UCT,UTC,Universal,Zulu,GMT*,*.tab} \ + "$target"/usr/share/zoneinfo/ +fi diff --git a/febootstrap-to-initramfs.pod b/febootstrap-to-initramfs.pod index 4bb418c..be5985c 100644 --- a/febootstrap-to-initramfs.pod +++ b/febootstrap-to-initramfs.pod @@ -65,7 +65,6 @@ this in mind when creating very large filesystems. =head1 SEE ALSO -L, L, L. diff --git a/febootstrap.pod b/febootstrap.pod index a610f88..da97766 100644 --- a/febootstrap.pod +++ b/febootstrap.pod @@ -55,6 +55,14 @@ If no packages or groups are given, then we install the C group which is the smallest working Fedora installation. Use C to list the packages currently in the C group. +=item B<--no-clean> + +Normally febootstrap will clean up the yum repository +(C inside the image). This contains the downloaded +RPMs and metadata. However if you give the C<--no-clean> option, then +the yum repository is left. This is useful if you want to run further +yum commands inside the filesystem by hand. + =back =head1 REPOSITORIES @@ -89,8 +97,8 @@ permissions using the tool C. =item * -Apply the permissions to the target directory using the tool -C (requires root). +Apply the permissions to the target directory using the forthcoming +tool C (requires root). =back @@ -137,7 +145,7 @@ L =head1 SEE ALSO L, -L, +L, L, L, L, diff --git a/febootstrap.sh b/febootstrap.sh index e9a197f..41fc84c 100755 --- a/febootstrap.sh +++ b/febootstrap.sh @@ -20,7 +20,7 @@ TEMP=`getopt \ -o g:i: \ - --long groupinstall:,group-install:,help,install: \ + --long groupinstall:,group-install:,help,install:,noclean,no-clean \ -n febootstrap -- "$@"` if [ $? != 0 ]; then echo "febootstrap: problem parsing the command line arguments" @@ -32,6 +32,8 @@ declare -a packages packages[0]="@Core" i=0 +clean=yes + usage () { echo "Usage: febootstrap [--options] REPO TARGET [MIRROR]" @@ -46,6 +48,9 @@ while true; do --groupinstall|--group-install) packages[i++]="@$2" shift 2;; + --noclean|--no-clean) + clean=no + shift;; --help) usage exit 0;; @@ -164,3 +169,8 @@ if [ $(id -u) -ne 0 ]; then else run_yum "${packages[@]}" fi + +# Clean up the yum repository. +if [ "$clean" = "yes" ]; then + rm -rf "$target"/var/cache/yum/febootstrap +fi -- 1.8.3.1