From 9cb33aa9b9295bc55d772b542356b1ca0742aa6e Mon Sep 17 00:00:00 2001 From: steve Date: Fri, 23 Feb 2007 15:37:06 +0000 Subject: [PATCH] 2007-02-23 15:37:05 by steve Installation methods are now updated so that I can add in the image server method for use @Bytemark. --- bin/xen-create-image | 293 ++++++++++++++----------------------------- bin/xt-install-image | 135 ++++++++++---------- debian/changelog | 6 +- etc/xen-tools.conf | 35 ++++-- misc/xen-tools | 14 ++- 5 files changed, 196 insertions(+), 287 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index 8c16aeb..6076950 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -82,40 +82,21 @@ xen-create-image - Easily create new Xen instances with networking and OpenSSH. Installation options: - --arch Pass the given architecture to debootstrap or rpmstrap. - This argument is ignored if you install with a different - installation type. + --arch Pass the given architecture to debootstrap or rpmstrap. + This argument is ignored if you install with a different + installation type. - --copy Install a new image by copying a directory recursively, - this is assumed to be a previously installed system. - This is much faster than installing from scratch. + --dist Specify the distribution you wish to install. - --copy-cmd This allows you to specify the command actually used for - installation when using "--copy" - NOTE: This option is *only* valid in the configuration file. + --install-method Specify the installation method to use. - --dist Specify the distribution you wish to install. + --install-source Specify the source path to use when installing via + a copy or tarball installation. - --debootstrap Use debootstrap to install the guest system. - --dist should be used to specify a distribution debootstrap - understands. + --mirror Setup the mirror to use when installing via debootstrap. - --mirror Setup the mirror to use when installing via debootstrap. - - --rpmstrap Use rpmstrap to install the guest distribution. - --dist should be used to specify a distribution rpmstrap - understands. - - --tar Install the new image by untarring the specified file. - Similar to --copy this is signficantly faster than - installing via rpmstrap or debootstrap. - - --tar-cmd This allows you to specify the command actually used for - installation when using "--tar". - NOTE: This option is *only* valid in the configuration file. - - --template Specify which template file to use when creating the - Xen configuration file. + --template Specify which template file to use when creating the + Xen configuration file. @@ -268,12 +249,9 @@ Create a configuration file in /etc/xen so that xm can create the new image. netmask = 255.255.255.0 # - # Installation options. + # Installation method, one of "copy", "debootstrap", "rpmstrap", "tar". # - # copy = /path/to/pristine/image - debootstrap = 1 - # rpmstrap = 1 - # tar = /path/to/img.tar + install-method = debootstrap =for example end @@ -420,7 +398,7 @@ Create a configuration file in /etc/xen so that xm can create the new image. xen-create-image --size=2Gb --swap=128Mb --dhcp \ --lvm=myvolumegroup --hostname=vm01.my.flat \ - --tar=/path/to/tar.file.tar + --install-method=tar --install-source=/path/to/tar.file.tar The advantage of the tarfile approach is that you'll not need to keep a disk image mounted if you were to use the --copy argument @@ -428,7 +406,7 @@ Create a configuration file in /etc/xen so that xm can create the new image. xen-create-image --size=2Gb --swap=128Mb --dhcp \ --lvm=myvolumegroup --hostname=vm01.my.flat \ - --copy=/path/to/copy/from + --install-method=copy --install-source=/path/to/copy/from =cut @@ -520,7 +498,7 @@ Install an X11 server, using VNC and XDM -- http://www.steve.org.uk/ - $Id: xen-create-image,v 1.125 2007-02-22 19:39:02 steve Exp $ + $Id: xen-create-image,v 1.126 2007-02-23 15:37:05 steve Exp $ =cut @@ -702,6 +680,7 @@ else { # Can't happen we didn't get an installation type. logprint( "Error: No recognised installation type.\n" ); + logprint( "Please specify either a directory, lvm, or evms volume to use.\n"); exit; } @@ -937,12 +916,9 @@ sub setupDefaultOptions $CONFIG{'roledir'} = '/etc/xen-tools/role.d'; # - # Installation methods + # Installation method defaults to "debootstrap". # - $CONFIG{'rpmstrap'} = 0; - $CONFIG{'debootstrap'} = 0; - $CONFIG{'copy'} = ''; - $CONFIG{'tar'} = ''; + $CONFIG{'install-method'} = 'debootstrap'; # # The program to run to create a filesystem. @@ -1058,11 +1034,7 @@ sub parseCommandLineArguments # file. # my %install; - $install{'debootstrap'} = 0; - $install{'rpmstrap'} = 0; $install{'evms'} = undef; - $install{'copy'} = undef; - $install{'tar'} = undef; $install{'dir'} = undef; $install{'lvm'} = undef; @@ -1101,12 +1073,11 @@ sub parseCommandLineArguments # # NOTE: We set the local variable here, not the global. # - "copy=s", \$install{'copy'}, - "copy-cmd=s", \$CONFIG{'copy-cmd'}, # NOP - IGNORED. - "debootstrap", \$install{'debootstrap'}, - "rpmstrap", \$install{'rpmstrap'}, - "tar=s", \$install{'tar'}, - "tar-cmd=s", \$CONFIG{'tar-cmd'}, # NOP - IGNORED. + "copy=s", \$install{'copy'}, + "copy-cmd=s", \$CONFIG{'copy-cmd'}, # NOP - IGNORED. + "install-method=s", \$CONFIG{'install-method'}, + "install-source=s", \$CONFIG{'install-source'}, + "tar-cmd=s", \$CONFIG{'tar-cmd'}, # NOP - IGNORED. # Misc. options "accounts", \$CONFIG{'accounts'}, @@ -1139,7 +1110,7 @@ sub parseCommandLineArguments if ( $VERSION ) { - my $REVISION = '$Revision: 1.125 $'; + my $REVISION = '$Revision: 1.126 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; @@ -1151,99 +1122,8 @@ sub parseCommandLineArguments # - # If we have had one of the local installation methods specified, - # and *only* one of them the we'll reset the global option(s) which - # came from the configuration file. - # - # Count the number which wer supplied - # - my $count = 0; - foreach my $key ( qw/debootstrap rpmstrap copy tar/ ) - { - if ( $install{$key} ) - { - $count += 1; - } - } - - # - # If we had exactly one specified then we can proceed. - # - if ( $count == 1 ) - { - foreach my $key ( qw/debootstrap rpmstrap copy tar/ ) - { - $CONFIG{$key} = $install{$key}; - } - } - elsif ( $count > 1 ) - { - my $err =< +=item B Install the distribution specified by the B<--dist> argument using the debootstrap. If you use this option you must specify a mirror with B<--mirror>. -=item B<--copy> -Copy the given directory recursively. This local directory is assumed to contain a complete installation. +=item B +Copy the given directory recursively. This local directory is assumed to contain a complete installation. Specify the directory to copy with the B<--install-source> argument. -=item B<--rpmstrap> +=item B Install the distribution specified by B<--dist> using the rpmstrap command. -=item B<--tar> -Untar a .tar file into the new installation location. This tarfile is assumed to contain a complete archived system. +=item B +Untar a .tar file into the new installation location. This tarfile is assumed to contain a complete archived system. Specify the directory to copy with the B<--install-source> argument. =back @@ -82,7 +80,7 @@ Untar a .tar file into the new installation location. This tarfile is assumed t -- http://www.steve.org.uk/ - $Id: xt-install-image,v 1.44 2006-12-26 00:55:58 steve Exp $ + $Id: xt-install-image,v 1.45 2007-02-23 15:37:05 steve Exp $ =cut @@ -159,7 +157,7 @@ checkArguments(); # # Simplest cases first. # -if ( $CONFIG{'copy'} ) +if ( lc($CONFIG{'install-method'}) eq "copy" ) { # # Make sure we have the cp binary present. @@ -183,7 +181,7 @@ if ( $CONFIG{'copy'} ) # # Expand the source and the destination. # - $cmd =~ s/\$src/$CONFIG{'copy'}/g; + $cmd =~ s/\$src/$CONFIG{'install-source'}/g; $cmd =~ s/\$dest/$CONFIG{'location'}/g; # @@ -192,7 +190,7 @@ if ( $CONFIG{'copy'} ) runCommand( $cmd ); } -elsif ( $CONFIG{'tar'} ) +elsif ( lc($CONFIG{'install-method'}) eq "tar" ) { # # Make sure we have the tar binary present. @@ -216,14 +214,14 @@ elsif ( $CONFIG{'tar'} ) # # Expand the tarfile. # - $cmd =~ s/\$src/$CONFIG{'tar'}/g; + $cmd =~ s/\$src/$CONFIG{'install-source'}/g; # # Run a command to copy an installed system into the new root. # runCommand( "cd $CONFIG{'location'} && $cmd" ); } -elsif ( $CONFIG{'debootstrap'} ) +elsif ( lc($CONFIG{'install-method'}) eq "debootstrap" ) { # # Make sure we have the debootstrap binary present. @@ -236,7 +234,7 @@ elsif ( $CONFIG{'debootstrap'} ) installDebootstrapImage(); } -elsif ( $CONFIG{'rpmstrap'} ) +elsif ( lc($CONFIG{'install-method'}) eq "rpmstrap" ) { # # Make sure we have the rpmstrap binary present. @@ -374,11 +372,9 @@ sub parseCommandLineArguments "dist=s", \$CONFIG{'dist'}, "hostname=s", \$CONFIG{'hostname'}, - # Exclusive. - "tar=s", \$CONFIG{'tar'}, - "copy=s", \$CONFIG{'copy'}, - "rpmstrap", \$CONFIG{'rpmstrap'}, - "debootstrap", \$CONFIG{'debootstrap'}, + # Installation method + "install-method=s", \$CONFIG{'install-method'}, + "install-source=s", \$CONFIG{'install-source'}, # Misc "arch=s", \$CONFIG{'arch'}, @@ -399,7 +395,7 @@ sub parseCommandLineArguments if ( $VERSION ) { - my $REVISION = '$Revision: 1.44 $'; + my $REVISION = '$Revision: 1.45 $'; if ( $REVISION =~ /1.([0-9.]+) / ) { $REVISION = $1; @@ -478,54 +474,55 @@ E_OR exit 1; } - - ## - # Now check the mutually distinct arguments - ## - my $count = 0; - foreach my $key ( qw(copy debootstrap rpmstrap tar ) ) + my $valid = 0; + if ( defined( $CONFIG{'install-method'} ) ) { - if ( defined( $CONFIG{$key} ) ) + foreach my $recognised ( qw/ copy debootstrap rpmstrap tar / ) { - $count += 1; + $valid = 1 if ( lc($CONFIG{'install-method'}) eq lc($recognised) ); + } + + # + # If we have "copy" or "tar" make sure we have a source. + # + if ( lc($CONFIG{'install-method'}) eq "copy" ) + { + # not defined. + $valid = 0 if (!defined( $CONFIG{'install-source'} ) ); + + # defined but not a directory. + $valid = 0 if (defined( $CONFIG{'install-source'} ) && + (! -d $CONFIG{'install-source'} ) ) + } + if ( lc($CONFIG{'install-method'}) eq "tar" ) + { + # not defined. + $valid = 0 if (!defined( $CONFIG{'install-source'} ) ); + + # defined but not a file. + $valid = 0 if (defined( $CONFIG{'install-source'} ) && + (! -e $CONFIG{'install-source'} ) ) } } - - # - # If count == 0 we had no recognised installation method. - # - if ( $count == 0 ) + else { - print < 1 ) + + if ( !$valid ) { print < Fri, 23 Feb 2007 13:36:28 +0000 xen-tools (3.0-1) unstable; urgency=low + -- Radu Spineanu Wed, 13 Dec 2006 11:17:28 +0000 [ Steve Kemp ] * New upstream release of 3.0 - Tests that config files exists. (Closes: #402328) - New option to create image but not install. (Closes: #383057, #402315) - Made "etch" the default target to install. (Closes: #399705) - -- Radu Spineanu Wed, 13 Dec 2006 11:17:28 +0000 xen-tools (3.0~beta1-2) unstable; urgency=low diff --git a/etc/xen-tools.conf b/etc/xen-tools.conf index 50a4e40..071e97a 100644 --- a/etc/xen-tools.conf +++ b/etc/xen-tools.conf @@ -42,7 +42,7 @@ # # Installation method. # -# There are four different methods you can use to install a new copy +# There are four distinct methods which you may to install a new copy # of Linux to use in your Xen guest domain: # # - Installation via the debootstrap command. @@ -54,16 +54,24 @@ # that the image you're left with matches the 'dist' setting later in # this file. # -# Note that you can only uncomment one method - they are mutually exclusive. -# However the command line installation method will allow you to override -# the choice you make here. # ## +# # -# copy = /path/to/pristine/image -# debootstrap = 1 -# rpmstrap = 1 -# tar = /path/to/img.tar +# install-method = [ debootstrap | rpmstrap | copy | tar ] +# +# +install-method = debootstrap + +# +# If you're using "copy", or "tar" you will need to specify the +# source location to copy from, or the source .tar file to unpack. +# +# You may specify that with a line such as: +# +# install-source = /path/to/copy +# install-source = /some/path/img.tar +# # # @@ -71,14 +79,15 @@ # Command definitions. ## # -# The "debootstrap" and "rpmstrap" commands are hardwired, but if you -# wish to alter the commands invoked when using the "--copy" + "--tar" -# options you can adjust these two settings: +# The "debootstrap" and "rpmstrap" commands are hardwired into the +# script, but if you wish to modify the commands which are executed +# when installing new systems by a "copy" or "tar" method you can +# do so here: # -# --copy: +# instlal-method=copy: # copy-cmd = /bin/cp -a $src/* $dest # -# --tar: +# install-method=tar: # tar-cmd = /bin/tar --numeric-owner -xvf $src # # diff --git a/misc/xen-tools b/misc/xen-tools index b6324ad..011804b 100644 --- a/misc/xen-tools +++ b/misc/xen-tools @@ -18,7 +18,7 @@ # -- # http://www.steve.org.uk # -# $Id: xen-tools,v 1.40 2006-12-25 12:25:40 steve Exp $ +# $Id: xen-tools,v 1.41 2007-02-23 15:37:06 steve Exp $ # @@ -53,7 +53,7 @@ _xen_create_image() COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} - opts='--accounts --broadcast --boot --cache --config --debootstrap --dhcp --dir --dist --evms --force --fs --gateway --help --hostname --ide --image --initrd --ip --kernel --lvm --mac --manual --memory --mirror --no-hooks --no-install --noswap --p2p --passwd --role --rpmstrap --size --swap --version --verbose' + opts='--admins --accounts --broadcast --boot --cache --config --dhcp --dir --dist --evms --force --fs --gateway --help --hostname --ide --image --install-method --install-source --initrd --ip --kernel --lvm --mac --manual --memory --mirror --no-hooks --no-install --noswap --p2p --passwd --role --size --swap --version --verbose' # @@ -109,6 +109,10 @@ _xen_create_image() COMPREPLY=( $( compgen -W 'sparse full' -- "${COMP_WORDS[COMP_CWORD]}" ) ) return 0 ;; + --install-method) + COMPREPLY=( $( compgen -W 'copy debootstrap rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) ) + return 0 + ;; --ip) ip=`echo ${ip} | sed -e 's/[.][^.]*$/./'` COMPREPLY=( $(compgen -W "${ip}" -- ${cur}) ) @@ -366,7 +370,7 @@ _xt-install-image() COMPREPLY=() cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} - opts='--copy --cache --config --debootstrap --dist --help --location --manual --mirror --rpmstrap --tar --verbose --version' + opts='--cache --config --dist --help --install-source --install-method --location --manual --mirror --verbose --version' # @@ -394,6 +398,10 @@ _xt-install-image() COMPREPLY=( $( compgen -W '${dists} sid sarge etch' -- "${COMP_WORDS[COMP_CWORD]}" ) ) return 0 ;; + --install-method) + COMPREPLY=( $( compgen -W 'copy debootstrap rpmstrap tar' -- "${COMP_WORDS[COMP_CWORD]}" ) ) + return 0 + ;; --location) _filedir -d return 0