Added missing commmand line arguments. Added summery of the action we're going to conduct.
429 lines
7.5 KiB
Perl
Executable File
429 lines
7.5 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
|
|
=head1 NAME
|
|
|
|
xen-create-image - Create a new Xen instance
|
|
|
|
=cut
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
xen-create-image [options]
|
|
|
|
Help Options:
|
|
--help Show this scripts help information.
|
|
--manual Read this scripts manual.
|
|
--version Show the version number and exit.
|
|
|
|
Debugging Options:
|
|
--verbose Be verbose in our execution.
|
|
|
|
=cut
|
|
|
|
=head1 NOTES
|
|
|
|
=cut
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
Steve
|
|
--
|
|
http://www.steve.org.uk/
|
|
|
|
$Id: xen-create-image,v 1.5 2006-06-09 14:55:08 steve Exp $
|
|
|
|
=cut
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
Copyright (c) 2005-2006 by Steve Kemp. All rights reserved.
|
|
|
|
This module is free software;
|
|
you can redistribute it and/or modify it under
|
|
the same terms as Perl itself.
|
|
The LICENSE file contains the full text of the license.
|
|
|
|
=cut
|
|
|
|
|
|
use strict;
|
|
use English;
|
|
use Env;
|
|
use Getopt::Long;
|
|
use Pod::Usage;
|
|
|
|
|
|
#
|
|
# Configuration values read initially from the global configuration
|
|
# file, then optionally overridden by the command line.
|
|
#
|
|
my %CONFIG;
|
|
|
|
|
|
#
|
|
# Release number.
|
|
#
|
|
my $RELEASE = '2.0';
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
# Check the environment
|
|
#
|
|
checkSystem();
|
|
|
|
|
|
#
|
|
# Setup default options.
|
|
#
|
|
setupDefaultOptions();
|
|
|
|
|
|
#
|
|
# Parse the command line arguments.
|
|
#
|
|
parseCommandLineArguments();
|
|
|
|
|
|
#
|
|
# Ensure we're started by root at this point. This is required
|
|
# to make sure we can create new LVM volumes, or mount loopback images.
|
|
#
|
|
testRootUser();
|
|
|
|
|
|
#
|
|
# Check our arguments
|
|
#
|
|
checkArguments();
|
|
|
|
|
|
#
|
|
# Show a summery of what we're going to do.
|
|
#
|
|
showSummery();
|
|
|
|
|
|
|
|
#
|
|
# Create and mount the images if we're using loopback filesystems.
|
|
#
|
|
if ( $CONFIG{'dir'} )
|
|
{
|
|
}
|
|
|
|
#
|
|
# Create the LVM partitions if we're using LVM.
|
|
#
|
|
if ( $CONFIG{'loopback'} )
|
|
{
|
|
}
|
|
|
|
|
|
#
|
|
# Mount the image.
|
|
#
|
|
|
|
#
|
|
# Call xt-install-image to do the install.
|
|
#
|
|
|
|
|
|
#
|
|
# If that worked call xt-customise-image to setup networking, and
|
|
# run distro-specific hooks.
|
|
#
|
|
|
|
|
|
#
|
|
# Unmount the disk image, and remove the temporary directory.
|
|
#
|
|
|
|
|
|
#
|
|
# Create xen configuration file.
|
|
#
|
|
|
|
|
|
#
|
|
# Report success.
|
|
#
|
|
|
|
|
|
|
|
|
|
=head2 checkSystem
|
|
|
|
Test that this system is fully setup for the new xen-create-image
|
|
script.
|
|
|
|
This means that the two binaries xt-install-image and xt-customize-image
|
|
are present.
|
|
|
|
=cut
|
|
|
|
sub checkSystem
|
|
{
|
|
if ( ! -x "/usr/bin/xt-customize-image" )
|
|
{
|
|
print "The script 'xt-customize-image' was not found.";
|
|
print "\nAborting\n\n";
|
|
}
|
|
if ( ! -x "/usr/bin/xt-install-image" )
|
|
{
|
|
print "The script 'xt-install-image' was not found.";
|
|
print "\nAborting\n\n";
|
|
}
|
|
}
|
|
|
|
|
|
|
|
=head2 setupDefaultOptions
|
|
|
|
Setup the default options we'd expect into our global CONFIG hash.
|
|
|
|
=cut
|
|
|
|
sub setupDefaultOptions
|
|
{
|
|
|
|
#
|
|
# Paths and files.
|
|
#
|
|
$CONFIG{'dir'} = '';
|
|
$CONFIG{'xm'} = '/usr/sbin/xm';
|
|
$CONFIG{'kernel'} = '/boot/vmlinuz-2.6.16-1-xen-686';
|
|
$CONFIG{'initrd'} = '/boot/initrd.img-2.6.16-1-xen-686';
|
|
|
|
#
|
|
# Sizing options.
|
|
#
|
|
$CONFIG{'memory'} = '96Mb';
|
|
$CONFIG{'size'} = '2000Mb';
|
|
$CONFIG{'swap'} = '128M';
|
|
$CONFIG{'cache'} = 'yes';
|
|
|
|
#
|
|
# Misc. options.
|
|
#
|
|
$CONFIG{'mirror'} = 'http://ftp.us.debian.org/debian';
|
|
$CONFIG{'dist'} = 'sarge';
|
|
$CONFIG{'fs'} = 'ext3';
|
|
$CONFIG{'force'} = 0;
|
|
|
|
#
|
|
# Installation methods
|
|
#
|
|
$CONFIG{'rpmstrap'} = 0;
|
|
$CONFIG{'debootstrap'} = 0;
|
|
$CONFIG{'copy'} = '';
|
|
$CONFIG{'tar'} = '';
|
|
}
|
|
|
|
|
|
|
|
=head2 parseCommandLineArguments
|
|
|
|
Parse the command line arguments this script was given.
|
|
|
|
=cut
|
|
|
|
sub parseCommandLineArguments
|
|
{
|
|
my $HELP = 0;
|
|
my $MANUAL = 0;
|
|
my $VERSION = 0;
|
|
|
|
#
|
|
# Parse options.
|
|
#
|
|
GetOptions(
|
|
# Mandatory
|
|
"dist=s", \$CONFIG{'dist'},
|
|
|
|
# Locations
|
|
"dir=s", \$CONFIG{'dir'},
|
|
"kernel=s", \$CONFIG{'kernel'},
|
|
"initrd=s", \$CONFIG{'initrd'},
|
|
"lvm=s", \$CONFIG{'lvm'},
|
|
|
|
# Networking options
|
|
"dhcp", \$CONFIG{'dhcp'},
|
|
"gateway=s", \$CONFIG{'gateway'},
|
|
"hostname=s", \$CONFIG{'hostname'},
|
|
"ip=s@", \$CONFIG{'ip'},
|
|
"netmask=s", \$CONFIG{'netmask'},
|
|
|
|
# Exclusive
|
|
"copy=s", \$CONFIG{'rpmstrap'},
|
|
"debootstrap", \$CONFIG{'debootstrap'},
|
|
"rpmstrap", \$CONFIG{'rpmstrap'},
|
|
"tar=s", \$CONFIG{'tar'},
|
|
|
|
# Misc. options
|
|
"boot", \$CONFIG{'boot'},
|
|
"cache=s", \$CONFIG{'cache'},
|
|
"ide", \$CONFIG{'ide'},
|
|
"passwd", \$CONFIG{'passwd'},
|
|
|
|
# Help options
|
|
"debug", \$CONFIG{'verbose'},
|
|
"help", \$HELP,
|
|
"manual", \$MANUAL,
|
|
"verbose", \$CONFIG{'verbose'},
|
|
"version", \$VERSION
|
|
);
|
|
|
|
pod2usage(1) if $HELP;
|
|
pod2usage(-verbose => 2 ) if $MANUAL;
|
|
|
|
|
|
if ( $VERSION )
|
|
{
|
|
my $REVISION = '$Revision: 1.5 $';
|
|
|
|
if ( $REVISION =~ /1.([0-9.]+) / )
|
|
{
|
|
$REVISION = $1;
|
|
}
|
|
|
|
print "xen-create-image release $RELEASE - CVS: $REVISION\n";
|
|
exit;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
=head2 testRootUser
|
|
|
|
Make sure this script is being run by a user with UID 0.
|
|
|
|
=cut
|
|
|
|
sub testRootUser
|
|
{
|
|
if ( $EFFECTIVE_USER_ID != 0 )
|
|
{
|
|
print <<E_O_ROOT;
|
|
|
|
In order to use this script you must be running with root privileges.
|
|
|
|
(This is necessary to mount the disk images which are created.)
|
|
|
|
E_O_ROOT
|
|
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
=head2 checkArguments
|
|
|
|
Test that the command line arguments we were given make sense.
|
|
|
|
=cut
|
|
|
|
sub checkArguments
|
|
{
|
|
#
|
|
# We require a distribution name.
|
|
#
|
|
if ( ! defined( $CONFIG{'dist'} ) )
|
|
{
|
|
print "The '--dist' argument is mandatory\n";
|
|
exit 1;
|
|
}
|
|
|
|
#
|
|
# Cheat and remap distributions names.
|
|
#
|
|
# TODO: Alternative create symlinks in the hook.d
|
|
if ( ( $CONFIG{'dist'} =~ /^sarge$/i ) ||
|
|
( $CONFIG{'dist'} =~ /^etch$/i ) ||
|
|
( $CONFIG{'dist'} =~ /^sid$/i ) )
|
|
{
|
|
$CONFIG{'dist'} = 'debian';
|
|
}
|
|
|
|
|
|
#
|
|
#
|
|
# Test that the distribution name we've been given
|
|
# to configure has a collection of hook scripts.
|
|
#
|
|
# If there are no scripts then we clearly cannot
|
|
# customise it!
|
|
#
|
|
my $dir = "/usr/lib/xen-tools/" . $CONFIG{'dist'} . ".d";
|
|
|
|
if ( ! -d $dir )
|
|
{
|
|
print <<E_OR;
|
|
|
|
We're trying to configure an installation of $CONFIG{'dist'} in
|
|
$CONFIG{'dir'} - but there is no hook directory for us to use.
|
|
|
|
This means we don't know how to configure this installation.
|
|
|
|
We'd expect the hook directory to be : $dir
|
|
|
|
Aborting.
|
|
E_OR
|
|
exit 1;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
=head2 showSummery
|
|
|
|
Show the user a summery of what is going to be created for them
|
|
|
|
=cut
|
|
|
|
sub showSummery
|
|
{
|
|
#
|
|
# Show the user what to expect.
|
|
#
|
|
print "\nGeneral Infomation\n";
|
|
print "--------------------\n";
|
|
print "Hostname : $CONFIG{'hostname'}\n";
|
|
print "Distribution : $CONFIG{'dist'}\n";
|
|
print "Fileystem Type : $CONFIG{'fs'}\n";
|
|
|
|
print "\nSize Information\n";
|
|
print "----------------\n";
|
|
print "Image size : $CONFIG{'size'}\n";
|
|
print "Swap size : $CONFIG{'swap'}\n" unless ( $CONFIG{'no-swap' } );
|
|
print "Memory size : $CONFIG{'memory'}\n";
|
|
print "Kernel path : $CONFIG{'kernel'}\n";
|
|
print "initrd path : $CONFIG{'initrd'}\n";
|
|
|
|
print "\nNetworking Information\n";
|
|
print "----------------------\n";
|
|
|
|
#
|
|
# Show each IP address added.
|
|
#
|
|
my $ips = $CONFIG{'ip'};
|
|
my $count = 1;
|
|
|
|
foreach my $i ( @$ips )
|
|
{
|
|
print "IP Address $count : $i\n";
|
|
$count += 1;
|
|
}
|
|
|
|
$CONFIG{'dhcp'} && print "IP Address : DHCP\n";
|
|
$CONFIG{'netmask'} && print "Netmask : $CONFIG{'netmask'}\n";
|
|
$CONFIG{'gateway'} && print "Gateway : $CONFIG{'gateway'}\n";
|
|
print "\n";
|
|
|
|
}
|