1
0
mirror of synced 2026-04-30 05:45:08 +00:00

2006-10-11 16:40:54 by steve

Applied patches from Ray Anthracite for evms support, with only
 minor changes.
This commit is contained in:
steve
2006-10-11 16:40:55 +00:00
parent ae7fab4992
commit 0521563fe0
6 changed files with 414 additions and 42 deletions

View File

@@ -127,12 +127,16 @@ xen-create-image - Easily create new Xen instances with networking and OpenSSH.
--dir Specify where the output images should go.
Subdirectories will be created for each guest
If you do not wish to use loopback images specify --lvm.
(These two options are mutually exclusive.)
If you do not wish to use loopback images specify --lvm
or --evms. (These three options are mutually exclusive.)
--lvm Specify the volume group to save images within.
If you do not wish to use LVM specify --dir.
(These two options are mutually exclusive.)
If you do not wish to use LVM specify --dir or --evms.
(These three options are mutually exclusive.)
--evms Specify the container to save images within, i.e. '--evms
lvm2/mycontainer'. If you do not wish to use EVMS specify
--dir or --lvm. (These three options are mutually exclusive.)
--hostname Set the hostname of the new guest system.
Ideally this will be fully-qualified since several
@@ -209,6 +213,16 @@ Create a configuration file in /etc/xen so that xm can create the new image.
#
# lvm = myvolume
#
# EVMS users should disable the dir setting above and instead specify
# a container. For example, if you have an lvm2 container named box,
# put lvm2/box. This is how it is named in the evms interface.
#
# Warning... this has not been tested with anything but lvm2 but should
# be generalizable.
#
# evms= lvm2/myvolume
#
# Disk and Sizing options.
#
@@ -306,7 +320,7 @@ Create a configuration file in /etc/xen so that xm can create the new image.
=cut
=head1 LVM EXAMPLES
=head1 LVM EXAMPLE
If you wish to use an LVM volume group instead of a pair of loopback
images as shown above you can instead use the --lvm argument to
@@ -328,6 +342,28 @@ Create a configuration file in /etc/xen so that xm can create the new image.
=cut
=head1 EVMS EXAMPLE
If you wish to use an EVMS storage container instead of a pair of loopback
images as shown above you can instead use the --evms argument to
specify one. The below example assumes an lvm2 container.
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--evms=lvm2/myvolumegroup --hostname=vm01.my.flat
The given storage container will have two new EVMS volumes created within it:
${hostname}-swap
${hostname}-disk
The disk image may be mounted, as you would expect, with the following
command:
mkdir -p /mnt/foo
mount /dev/evms/vm01.my.flat-disk /mnt/foo
=cut
=head1 INSTALLATION METHODS
@@ -462,7 +498,7 @@ Install an X11 server, using VNC and XDM
--
http://www.steve.org.uk/
$Id: xen-create-image,v 1.96 2006-10-07 08:38:02 steve Exp $
$Id: xen-create-image,v 1.97 2006-10-11 16:40:54 steve Exp $
=cut
@@ -606,10 +642,17 @@ elsif ( $CONFIG{'lvm'} )
#
createLVMBits();
}
elsif ( $CONFIG{'evms'} )
{
#
# Create our evms partitions.
#
createEVMSBits();
}
else
{
# Can't happen: Neither loopback nor LVM selected
logprint( "Error: Neither loopback nor LVM is selected.\n");
# Can't happen we didn't get an installation type.
logprint( "Error: No recognised installation type.\n" );
exit;
}
@@ -621,7 +664,7 @@ mountImage();
#
# Call xt-install-image to do the install.
# Call xt-install-image to perform the actual install.
#
installSystem();
@@ -901,6 +944,7 @@ sub parseCommandLineArguments
my %install;
$install{'debootstrap'} = 0;
$install{'rpmstrap'} = 0;
$install{'evms'} = undef;
$install{'copy'} = undef;
$install{'tar'} = undef;
$install{'dir'} = undef;
@@ -922,6 +966,7 @@ sub parseCommandLineArguments
# Locations
"dir=s", \$install{'dir'},
"evms=s", \$install{'evms'},
"kernel=s", \$CONFIG{'kernel'},
"initrd=s", \$CONFIG{'initrd'},
"mirror=s", \$CONFIG{'mirror'},
@@ -974,7 +1019,7 @@ sub parseCommandLineArguments
if ( $VERSION )
{
my $REVISION = '$Revision: 1.96 $';
my $REVISION = '$Revision: 1.97 $';
if ( $REVISION =~ /1.([0-9.]+) / )
{
$REVISION = $1;
@@ -1039,18 +1084,26 @@ E_O_ERROR
#
# Now do a similar thing so that the command line setting of
# '--lvm=x' and '--dir=x' override anything in the configuration
# file.
# '--lvm', '--evms' and '--dir=x' override anything in the
# configuration file.
#
if ( $install{'dir'} )
{
$CONFIG{'lvm'} = undef;
$CONFIG{'dir'} = $install{'dir'};
$CONFIG{'dir'} = $install{'dir'};
$CONFIG{'evms'} = undef;
$CONFIG{'lvm'} = undef;
}
if ( $install{'evms'} )
{
$CONFIG{'dir'} = undef;
$CONFIG{'evms'} = $install{'evms'};
$CONFIG{'lvm'} = undef;
}
if ( $install{'lvm'} )
{
$CONFIG{'dir'} = undef;
$CONFIG{'lvm'} = $install{'lvm'};
$CONFIG{'dir'} = undef;
$CONFIG{'evms'} = undef;
$CONFIG{'lvm'} = $install{'lvm'};
}
}
@@ -1160,14 +1213,14 @@ E_OR
}
#
# If using LVM images cannot be sparse
# If using LVM or EVMS then the images may not be sparse
#
if ( $CONFIG{'lvm'} )
if ( $CONFIG{'lvm'} ||
$CONFIG{'evms'} )
{
$CONFIG{'image'} = "full";
}
#
# The kernel + initrd images should exist.
#
@@ -1292,9 +1345,27 @@ sub checkBinariesPresent
exit 1;
}
}
elsif ( defined( $CONFIG{'evms'} ) )
{
#
# EVMS-specific binaries.
#
my @evms = qw ( /sbin/evms /bin/echo );
foreach my $file ( @evms )
{
if ( ! -x $file )
{
logprint( "The following binary is required to run this tool\n");
logprint( "\t$file\n" );
logprint( "(This is only required for EVMS volumes, which you've selected)\n" );
exit;
}
}
}
else
{
# lvm image
# LVM-specific binaries.
my @lvm = qw ( /sbin/lvcreate /sbin/lvremove );
foreach my $file ( @lvm )
@@ -1666,6 +1737,181 @@ sub createLVMBits
=begin doc
This function is responsible for creating two new logical volumes within
a given EVMS container group (which at the moment is either LVM or LVM2), but
should be compatible with any further extentions of evms.
=end doc
=cut
sub createEVMSBits
{
# The two volumes we will need to use..
my $disk = $CONFIG{'hostname'} . "-disk" ;
my $swap = $CONFIG{'hostname'} . "-swap" ;
#
# Check whether the disk volume exists already, and if so abort
# unless '--force' is specified. This is two steps with evms,
# because two things need to be checked, the volume and the object.
#
# Check whether the EVMS volume already exists, abort unless '--force' is specified.
my $evms_volume_disk = "/dev/evms/$CONFIG{'hostname'}-disk";
if ( -e $evms_volume_disk )
{
# Delete if forcing
if ( $CONFIG{'force'} )
{
logprint( "Removing $evms_volume_disk - since we're forcing the install\n" );
runCommand( "echo Delete : $evms_volume_disk | evms" );
}
else
{
logprint( "The EVMS volume $evms_volume_disk already exists. Aborting.\n" );
logprint( "Specify '--force' to delete and recreate\n" );
exit;
}
}
#
# Check whether the EVMS object exists, abort unless '--force'
# is specified.
#
# Note: $evms_object_disk is not specified directly as a device
#
my $evms_object_disk = "$CONFIG{'evms'}/$CONFIG{'hostname'}-disk";
if ( -e $evms_object_disk )
{
# Delete if forcing
if ( $CONFIG{'force'} )
{
logprint( "Removing $evms_object_disk - since we're forcing the install\n" );
runCommand( "echo Delete : $evms_object_disk | evms" );
}
else
{
logprint( "The EVMS object $evms_object_disk already exists. Aborting.\n" );
logprint( "Specify '--force' to delete and recreate\n" );
exit;
}
}
#
# Check whether the swap object and EVMS volume exists already, and
# if so abort unless '--force' is specified.
#
#
# Check whether the EVMS volume for swap already exists, abort
# unless '--force' is specified.
#
my $evms_volume_swap = "/dev/evms/$CONFIG{'hostname'}-swap";
if ( -e $evms_volume_swap )
{
# Delete if forcing
if ( $CONFIG{'force'} )
{
logprint( "Removing $evms_volume_swap - since we're forcing the install\n" );
runCommand( "echo Delete : $evms_volume_swap | evms" );
}
else
{
logprint( "The EVMS volume $evms_volume_swap image already exists. Aborting.\n" );
logprint( "Specify '--force' to delete and recreate\n" );
exit;
}
}
# Check whether the evms object for swap exists, abort unless '--force' is specified.
# note that $evms_object_swap is not specified directly as a device
my $evms_object_swap = "$CONFIG{'evms'}/$CONFIG{'hostname'}-swap";
if ( -e $evms_object_swap )
{
# Delete if forcing
if ( $CONFIG{'force'} )
{
logprint( "Removing $evms_object_swap - since we're forcing the install\n" );
runCommand( "echo Delete : $evms_object_swap | evms" );
}
else
{
logprint( "The EVMS object $evms_object_swap image already exists. Aborting.\n" );
logprint( "Specify '--force' to delete and recreate\n" );
exit;
}
}
#
# Modify the sizes to something reasonable
#
my $disk_size = $CONFIG{'size'};
my $swap_size = $CONFIG{'swap'};
#
# Convert Gb -> Mb for the disk image size, and swap size.
#
if ( $disk_size =~ /^(\d+)Gb*$/i )
{
$disk_size = $1 * 1024 . "M";
}
if ( $swap_size =~ /^(\d+)Gb*$/i )
{
$swap_size = $1 * 1024 . "M";
}
#
# Final adjustments to sizing.
#
$disk_size =~ s/Mb*$/k/i;
if ( $swap_size =~ /^(\d+)Mb*$/i )
{
$swap_size = $1;
}
#
# The commands to create the objects and volumes.
#
#create the object
my $disk_cmd_object = "echo allocate : $CONFIG{'evms'}/Freespace, size=$CONFIG{'size'}, name=$disk | evms";
# these will be piped to evms, but gotta check it first
## /sbin/lvcreate $CONFIG{'evms'} -L $CONFIG{'size'}M -n $disk";
#create the EVMS volume
my $disk_cmd_volume = "echo create : Volume, $CONFIG{'evms'}/$disk, name=$disk | evms";
##/sbin/lvcreate $CONFIG{'evms'} -L $CONFIG{'swap'} -n $swap";
#repeat the same steps for the swap partition
my $swap_cmd_object = "echo allocate : $CONFIG{'evms'}/Freespace, size=$CONFIG{'swap'}, name=$swap | evms";
# these will be piped to evms, but gotta check it first
## /sbin/lvcreate $CONFIG{'evms'} -L $CONFIG{'size'}M -n $disk";
#create the EVMS volume
my $swap_cmd_volume = "echo create : Volume, $CONFIG{'evms'}/$swap, name=$swap | evms";
##/sbin/lvcreate $CONFIG{'evms'} -L $CONFIG{'swap'} -n $swap";
#
# Create the volumes
#
runCommand( $disk_cmd_object );
runCommand( $disk_cmd_volume );
runCommand( $swap_cmd_object ) unless( $CONFIG{'noswap'} );
runCommand( $swap_cmd_volume ) unless( $CONFIG{'noswap'} );
#
# Initialise the partitions with the relevant filesystem.
#
createFilesystem( "/dev/evms/$CONFIG{'hostname'}-disk" );
createSwap( "/dev/evms/$CONFIG{'hostname'}-swap" ) unless ( $CONFIG{'noswap'} );
}
=begin doc
Format the given image in the users choice of filesystem.
@@ -1755,6 +2001,10 @@ sub mountImage
{
$image = "/dev/" . $CONFIG{'lvm'} . "/" . $CONFIG{'hostname'} . '-disk';
}
elsif ( $CONFIG{'evms'} )
{
$image = "/dev/evms/" . $CONFIG{'hostname'} . '-disk';
}
elsif ( $CONFIG{'dir'} )
{
$image = $CONFIG{'dir'} . '/domains/' . $CONFIG{'hostname'} . "/disk.img" ;
@@ -1762,7 +2012,7 @@ sub mountImage
else
{
logprint( "I don't know what to mount!\n" );
logprint( "Please specify '--dir' or '--lvm'\n" );
logprint( "Please specify '--dir' or '--lvm' or '--evms'\n" );
exit;
}
@@ -1785,6 +2035,10 @@ sub mountImage
{
$mount_cmd = "mount $mount_type $image $MOUNT_POINT";
}
elsif ( $CONFIG{'evms'} )
{
$mount_cmd = "mount $mount_type $image $MOUNT_POINT";
}
else
{
$mount_cmd = "mount $mount_type -o loop $image $MOUNT_POINT";

View File

@@ -17,6 +17,7 @@ xen-delete-image - Delete previously created Xen instances.
General options:
--dir Specify the output directory where images were previously saved.
--lvm Specify the LVM volume to use.
--evms Specify the EVMS container to use.
Testing options:
--test Don't complain if we're not invoked by root.
@@ -46,6 +47,9 @@ Show the version number and exit.
=item B<--lvm>
Specify the LVM volume group where images were previously saved.
=item B<--evms>
Specify the EVMS container where images were previously saved.
=back
=cut
@@ -57,7 +61,7 @@ Specify the LVM volume group where images were previously saved.
Xen instances which have previously been created by xen-create-image.
You must be root to run this script as it removes the Xen configuration
file from /etc/xen and potentially removes LVM volumes.
file from /etc/xen and potentially removes LVM and EVMS volumes.
(When invoked with the '--test' flag the script will continue running,
but will fail to remove anything which the user does not have permission
@@ -96,13 +100,31 @@ Specify the LVM volume group where images were previously saved.
=cut
=head1 EVMS EXAMPLE
Assuming that you have the container 'mycontainer' containing three
Xen instances 'foo', 'bar', and 'baz' the first two may be deleted via:
xen-delete-image --evms=lvm2/mycontainer foo bar
This will remove the volumes 'foo-disk', 'foo-swap', 'bar-disk',
and 'bar-swap'.
Note that if the images were created with "--noswap" then the swap
volumes will not be present, so will not need to be deleted.
The Xen configuration files will also be removed.
=cut
=head1 AUTHOR
Steve
--
http://www.steve.org.uk/
$Id: xen-delete-image,v 1.18 2006-09-11 15:57:57 steve Exp $
$Id: xen-delete-image,v 1.19 2006-10-11 16:40:54 steve Exp $
=cut
@@ -278,6 +300,7 @@ sub parseCommandLineArguments
GetOptions(
"dir=s", \$CONFIG{'dir'},
"lvm=s", \$CONFIG{'lvm'},
"evms=s", \$CONFIG{'evms'},
"test", \$CONFIG{'test'},
"verbose", \$CONFIG{'verbose'},
"help", \$HELP,
@@ -291,7 +314,7 @@ sub parseCommandLineArguments
if ( $VERSION )
{
my $REVISION = '$Revision: 1.18 $';
my $REVISION = '$Revision: 1.19 $';
if ( $REVISION =~ /1.([0-9.]+) / )
{
@@ -322,14 +345,15 @@ sub checkArguments
if ( $CONFIG{'test'} )
{
$CONFIG{'lvm'} = undef;
$CONFIG{'evms'} = undef;
}
#
# Make sure we have either a volume, or a root.
#
if ( $CONFIG{'lvm'} && $CONFIG{'dir'} )
if ( ( $CONFIG{'lvm'} && $CONFIG{'dir'} ) || ( $CONFIG{'lvm'} && $CONFIG{'evms'} ) || ( $CONFIG{'evms'} && $CONFIG{'dir'} ) )
{
print "Please only use a volume group or a directory name - not both\n";
print "Please use only one of: a volume group, an EVMS container, or a directory name\n";
exit;
}
@@ -337,9 +361,9 @@ sub checkArguments
#
# Make sure we have at least one of the lvm or root specified.
#
if ( (!defined( $CONFIG{'dir'} ) ) && ( !defined( $CONFIG{'lvm'} ) ) )
if ( (!defined( $CONFIG{'dir'} ) ) && ( !defined( $CONFIG{'lvm'} ) ) && ( !defined( $CONFIG{'evms'} ) ) )
{
print "Please specify either a directory root, or an LVM volume group\n";
print "Please specify either a directory root, an LVM volume group, or an EVMS container\n";
exit;
}
@@ -446,10 +470,34 @@ sub deleteXenImage
runCommand( "lvremove /dev/$CONFIG{'lvm'}/$hostname-disk --force" );
}
}
elsif ( defined( $CONFIG{'evms'} ) )
{
#
# EVMS volumes
#
#
# TODO: Check we're not mounted.
#
if ( -e "/dev/evms/$hostname-swap" )
{
$CONFIG{'verbose'} && print "Removing EVMS swap volume\n";
runCommand( "echo Delete : /dev/evms/$hostname-swap | evms" );
runCommand( "echo Delete : $CONFIG{'evms'}/$hostname-swap | evms" );
}
if ( -e "/dev/evms/$hostname-disk" )
{
$CONFIG{'verbose'} && print "Removing EVMS disk volume\n";
runCommand( "echo Delete : /dev/evms/$hostname-disk | evms" );
runCommand( "echo Delete : $CONFIG{'evms'}/$hostname-disk | evms" );
}
}
else
{
print "Error - neither --dir nor --lvm.\n";
print "Error - neither --dir nor --evms nor --lvm.\n";
print "Can't happen\n";
print "Hostname : $hostname\n";
exit;

View File

@@ -16,6 +16,7 @@ xen-update-image - Update the software installed upon offline Xen images.
General Options:
--dir Specify the directory which contains the image(s).
--lvm Specify the LVM volume group which contains the image(s).
--evms Specify the EVMS container which contains the image(s).
=cut
@@ -40,6 +41,9 @@ Show the version number and exit.
=item B<--lvm>
Specify the LVM volume group which contains the image(s).
=item B<--evms>
Specify the EVMS container which contains the image(s).
=back
=cut
@@ -82,7 +86,7 @@ Specify the LVM volume group which contains the image(s).
--
http://www.steve.org.uk/
$Id: xen-update-image,v 1.12 2006-09-11 15:57:57 steve Exp $
$Id: xen-update-image,v 1.13 2006-10-11 16:40:54 steve Exp $
=cut
@@ -223,6 +227,30 @@ sub updateXenImage
return;
}
}
elsif ( $CONFIG{'evms'} )
{
# The EVMS volume -- note, unlike LVM, you don't need the $CONFIG{'evms'}
# to see it and mount the volume. $CONFIG{'evms'} is only used for manipulating
# the underlying object. Still, I don't want to mess with the parse code and
# make it confusing - otherwise --evms takes an argument everywhere but here,
# which will confuse users. The better solution is to make it so that --evms can
# take a following container, but doesn't require it. For the moment, it is
# better to leave it as it is, take a container, and then ignore it.
# The best way to do it is to just read it out of the configuration file,
# tell the user what you got and where you got it from, and not bother the user
# with picking --dir or --lvm or --evms at all, but infer it from the config
# file's disk = parameter. xen-delete-image might work the same way, but
# it could be *slightly* more dangerous in the context of deleting.
$img = "/dev/evms/$name-disk";
# make sure it exists.
if ( ! -e $img )
{
print "EVMS volume '$img' for host '$name' not found\n";
return;
}
}
else
{
die "Can't happen?\n";
@@ -344,6 +372,7 @@ sub parseCommandLineArguments
GetOptions(
"dir=s", \$CONFIG{'dir'},
"lvm=s", \$CONFIG{'lvm'},
"evms=s", \$CONFIG{'evms'},
"help", \$HELP,
"manual", \$MANUAL,
"version", \$VERSION
@@ -354,7 +383,7 @@ sub parseCommandLineArguments
if ( $VERSION )
{
my $REVISION = '$Revision: 1.12 $';
my $REVISION = '$Revision: 1.13 $';
if ( $REVISION =~ /1.([0-9.]+) / )
{
@@ -383,9 +412,9 @@ sub checkArguments
#
# Make sure we have either a volume, or a root.
#
if ( $CONFIG{'lvm'} && $CONFIG{'dir'} )
if ( ( $CONFIG{'lvm'} && $CONFIG{'dir'} ) || ( $CONFIG{'lvm'} && $CONFIG{'evms'} ) || ( $CONFIG{'evms'} && $CONFIG{'dir'} ) )
{
print "Please only specify a volume group or a directory name - not both\n";
print "Please use only one of: a volume group, an EVMS container, or a directory name\n";
exit;
}
@@ -393,9 +422,9 @@ sub checkArguments
#
# Make sure we have at least one of the lvm or root specified.
#
if ( (!defined( $CONFIG{'dir'} ) ) && ( !defined( $CONFIG{'lvm'} ) ) )
if ( (!defined( $CONFIG{'dir'} ) ) && ( !defined( $CONFIG{'lvm'} ) ) && ( !defined( $CONFIG{'evms'} ) ) )
{
print "Please specify either a directory root, or an LVM volume group\n";
print "Please specify either a directory root, an LVM volume group, or an EVMS container\n";
exit;
}
}

View File

@@ -96,7 +96,7 @@ xt-create-config - Create a Xen configuration file for a new guest
--
http://www.steve.org.uk/
$Id: xt-create-xen-config,v 1.20 2006-09-11 15:57:57 steve Exp $
$Id: xt-create-xen-config,v 1.21 2006-10-11 16:40:54 steve Exp $
=cut
@@ -203,7 +203,7 @@ sub parseCommandLineArguments
if ( $VERSION )
{
my $REVISION = '$Revision: 1.20 $';
my $REVISION = '$Revision: 1.21 $';
if ( $REVISION =~ /1.([0-9.]+) / )
{
$REVISION = $1;
@@ -321,6 +321,11 @@ sub createXenConfig
$image_vbd = "phy:$ENV{'lvm'}/$ENV{'hostname'}-disk";
$swap_vbd = "phy:$ENV{'lvm'}/$ENV{'hostname'}-swap";
}
elsif ( $ENV{'evms'} )
{
$image_vbd = "phy:/dev/evms/$ENV{'hostname'}-disk";
$swap_vbd = "phy:/dev/evms/$ENV{'hostname'}-swap";
}
else
{
$image_vbd = "file:$ENV{'dir'}/domains/$ENV{'hostname'}/disk.img";