From 9cf3beefb865ea3e1a4bbe570d632649540788cc Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Mon, 30 Mar 2009 15:14:29 +0100 Subject: Added febootstrap-run command. Examples need more VM RAM when run in Rawhide. Also use 'set -e' in example scripts. --- .gitignore | 2 ++ Makefile.am | 20 +++++++++++ README | 8 ++--- examples/guestfs-test.sh | 4 ++- examples/minimal-filesystem.sh | 4 ++- febootstrap-run.pod | 74 ++++++++++++++++++++++++++++++++++++++++ febootstrap-run.sh | 77 ++++++++++++++++++++++++++++++++++++++++++ febootstrap.pod | 45 ++++++++++++++++++------ 8 files changed, 218 insertions(+), 16 deletions(-) create mode 100644 febootstrap-run.pod create mode 100755 febootstrap-run.sh diff --git a/.gitignore b/.gitignore index 2c6f170..c50e549 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*~ febootstrap*.8 febootstrap*.txt febootstrap-*.tar.gz @@ -12,6 +13,7 @@ config.status configure febootstrap.spec febootstrap +febootstrap-run febootstrap-minimize febootstrap-to-initramfs install-sh diff --git a/Makefile.am b/Makefile.am index 8893794..7f590da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,6 +21,7 @@ SUBDIRS = examples bin_SCRIPTS = \ febootstrap \ + febootstrap-run \ febootstrap-minimize \ febootstrap-to-initramfs DISTCLEANFILES = $(bin_SCRIPTS) @@ -31,6 +32,12 @@ febootstrap: febootstrap.sh chmod 0555 $@-t mv $@-t $@ +febootstrap-run: febootstrap-run.sh + rm -f $@ + cp $< $@-t + chmod 0555 $@-t + mv $@-t $@ + febootstrap-minimize: febootstrap-minimize.sh rm -f $@ cp $< $@-t @@ -45,6 +52,7 @@ febootstrap-to-initramfs: febootstrap-to-initramfs.sh man_MANS = \ febootstrap.8 \ + febootstrap-run.8 \ febootstrap-minimize.8 \ febootstrap-to-initramfs.8 @@ -60,6 +68,16 @@ febootstrap.8: febootstrap.pod febootstrap.txt: febootstrap.pod pod2text $< > $@ +febootstrap-run.8: febootstrap-run.pod + pod2man \ + --section 8 \ + -c "Virtualization Support" \ + --release "$(PACKAGE_NAME)-$(PACKAGE_VERSION)" \ + $< > $@ + +febootstrap-run.txt: febootstrap-run.pod + pod2text $< > $@ + febootstrap-minimize.8: febootstrap-minimize.pod pod2man \ --section 8 \ @@ -88,6 +106,8 @@ EXTRA_DIST = \ fakechroot-svn-no-dup-envs.patch \ febootstrap.8 febootstrap.txt febootstrap.pod \ febootstrap.sh \ + febootstrap-run.8 febootstrap-run.txt febootstrap-run.pod \ + febootstrap-run.sh \ febootstrap-minimize.8 febootstrap-minimize.txt \ febootstrap-minimize.pod \ febootstrap-minimize.sh \ diff --git a/README b/README index e9391e8..1abbc27 100644 --- a/README +++ b/README @@ -17,10 +17,10 @@ Requirements - Tested with version 1.11. fakechroot > 2.8 or 2.8 + patch - - NB. KNOWN NOT TO WORK WITH 2.8. You MUST apply the patch - 'fakechroot-2.8-relchroot.patch' to the fakechroot sources - and recompile. Hopefully this patch will be included in - future versions of fakechroot. + - **** NB. KNOWN NOT TO WORK WITH 2.8 ***** You MUST apply + the patch 'fakechroot-2.8-relchroot.patch' to the fakechroot + sources and recompile. Hopefully this patch will be included + in future versions of fakechroot. yum - Tested with version 3.2. diff --git a/examples/guestfs-test.sh b/examples/guestfs-test.sh index b45c1f4..f487f50 100755 --- a/examples/guestfs-test.sh +++ b/examples/guestfs-test.sh @@ -13,6 +13,8 @@ # This is a realistic example for 'libguestfs', which contains a # selection of command-line tools, LVM, NTFS and an NFS server. +set -e + if [ $(id -u) -eq 0 ]; then echo "Don't run this script as root. Read instructions in script first." exit 1 @@ -62,6 +64,6 @@ chmod +x init # Now run qemu to boot this guestfs system. qemu-system-$(arch) \ - -m 128 \ + -m 256 \ -kernel vmlinuz -initrd guestfs-initrd.img \ -hda guest-image -boot c diff --git a/examples/minimal-filesystem.sh b/examples/minimal-filesystem.sh index 9a0f575..678d612 100755 --- a/examples/minimal-filesystem.sh +++ b/examples/minimal-filesystem.sh @@ -12,6 +12,8 @@ # few command line utilities. One of the joys of Fedora is that even # this minimal install is still 200 MB ... +set -e + if [ $(id -u) -eq 0 ]; then echo "Don't run this script as root. Read instructions in script first." exit 1 @@ -55,6 +57,6 @@ dd if=/dev/zero of=zero bs=2048 count=1 # Now run qemu to boot this minimal system. qemu-system-$(arch) \ - -m 128 \ + -m 256 \ -kernel vmlinuz -initrd minimal-initrd.img \ -hda zero -boot c diff --git a/febootstrap-run.pod b/febootstrap-run.pod new file mode 100644 index 0000000..c5e713c --- /dev/null +++ b/febootstrap-run.pod @@ -0,0 +1,74 @@ +=head1 NAME + +febootstrap-run - Run extra commands in febootstrap root filesystem + +=head1 SYNOPSIS + + febootstrap-run [--options] DIR [--] [CMD ...] + +=head1 DESCRIPTION + +This can be used to run extra commands in the febootstrap root +filesystem. It is just a simple wrapper around the standard +C and C commands. + +If given, the C is run inside the root filesystem. The +command acts as if it was run as root and chrooted into the root +filesystem. + +If the command is omitted, then we start a shell. + +If C could contain anything starting with a C<-> character +then use C<--> to separate C parameters from the +command: + + febootstrap-run ./f10 -- ls -l + +=head1 OPTIONS + +=over 4 + +=item B<--ro> + +Usually any changes to permissions made by the command are recorded in +the C file. However if C<--ro> flag is given, then +changes to permissions are not recorded. (Note: changes to file +contents still happen). + +=back + +=head1 ENVIRONMENT VARIABLES + +Some L environment variables are applicable. In +particular you may want to set: + + export FAKECHROOT_EXCLUDE_PATH=/proc + +=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-run.sh b/febootstrap-run.sh new file mode 100755 index 0000000..55df233 --- /dev/null +++ b/febootstrap-run.sh @@ -0,0 +1,77 @@ +#!/bin/bash - +# febootstrap-run +# (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 g:i: \ + --long help,ro \ + -n febootstrap-run -- "$@"` +if [ $? != 0 ]; then + echo "febootstrap-run: problem parsing the command line arguments" + exit 1 +fi +eval set -- "$TEMP" + +readonly=no + +usage () +{ + echo "Usage: febootstrap-run [--options] DIR [CMD]" + echo "Please read febootstrap-run(8) man page for more information." +} + +while true; do + case "$1" in + --ro) + readonly=yes + shift;; + --help) + usage + exit 0;; + --) + shift + break;; + *) + echo "Internal error!" + exit 1;; + esac +done + +if [ $# -lt 1 ]; then + usage + exit 1 +fi + +target="$1" +shift + +if [ ! -f "$target"/fakeroot.log ]; then + echo "febootstrap-run: $target: not a root filesystem" + exit 1 +fi + +if [ "$readonly" = "no" ]; then + fakeroot -i "$target"/fakeroot.log -s "$target"/fakeroot.log \ + fakechroot -s \ + chroot "$target" "$@" +else + fakeroot -i "$target"/fakeroot.log \ + fakechroot -s \ + chroot "$target" "$@" +fi diff --git a/febootstrap.pod b/febootstrap.pod index dfc93fc..b2d7470 100644 --- a/febootstrap.pod +++ b/febootstrap.pod @@ -75,27 +75,46 @@ L (If necessary replace C with your architecture, but it seems unlikely that this list will change based on architecture). -=head1 FAKEROOT LOGFILE +=head1 RUNNING EXTRA COMMANDS IN THE ROOT FILESYSTEM + +If you want to run further commands inside the root filesystem, for +example additional C installs, then use C. See +the L manual page for more details. + +You have to be careful about modifying files in the root filesystem +directly (without using C). It's easy to confuse +fakeroot and end up with the wrong permissions on files (see FAKEROOT +LOGFILE below). + +C runs the command inside the root filesystem, which +means it won't normally have access to files outside the root. You +can use C environment variable (see +L) or copy files into the root first. + +=head2 FAKEROOT LOGFILE When febootstrap is run as non-root (the normal case) we use fakeroot so that yum thinks it is running as root. Fakeroot keeps track of "real" file permissions in a log file which is saved into the target directory as C/fakeroot.log>. -You can use the fakeroot logfile in a number of ways: +This logfile is indexed by inode number, which makes certain +operations safe and other operations unsafe. For example, deleting +files is usually safe. Files should be replaced only by doing: -=over 4 + echo updated-content > old-file -=item * +(since that preserves the original inode). In most cases it's usually +safest to use C. -Run +You can use the fakeroot logfile in a number of ways: - fakeroot -i fakeroot.log command +=over 4 -in order to run a command with the faked file permissions. If the -command will make updates, then do: +=item * - fakeroot -i fakeroot.log -s fakeroot.log command +Use L to run a command with the faked file +permissions. =item * @@ -109,7 +128,12 @@ tool C (requires root). =back -=head1 COMPARISON TO debootstrap +=head1 RUNNING FEBOOTSTRAP AS ROOT + +There is some rudimentary support for running C as root. +However it is not well-tested and generally not recommended. + +=head1 COMPARISON TO DEBOOTSTRAP febootstrap cannot do cross-architecture installs (C). The reason is that C<%pre> and C<%post> scripts cannot @@ -153,6 +177,7 @@ L L, L, +L, L, L, L, -- cgit