1
0
mirror of synced 2026-04-29 05:25:12 +00:00

2005-12-22 23:32:52 by steve

Apply Radu's latest patch, with some small tweaks.
This commit is contained in:
steve
2005-12-22 23:32:52 +00:00
parent 0a0708560d
commit d52aba9199
3 changed files with 124 additions and 80 deletions

View File

@@ -11,7 +11,7 @@
# --fs=ext3 becomes 'fs = ext3'.
#
#
# $Id: xen-tools.conf,v 1.7 2005-12-19 18:26:48 steve Exp $
# $Id: xen-tools.conf,v 1.8 2005-12-22 23:32:52 steve Exp $
#
@@ -31,6 +31,16 @@ swap = 128Mb # Swap size
filesystem = ext3 # use EXT3 filesystems
dist = sarge # Default distribution to install.
#
# Default kernel for the virtual servers
#
kernel = /boot/vmlinuz-2.6.12-xen
#
# Default mirror for debootstrap
#
mirror = http://ftp.us.debian.org/debian/
##
# Static addressing.
@@ -42,8 +52,6 @@ dist = sarge # Default distribution to install.
#
# gateway = 192.168.1.1
# netmask = 255.255.255.0
# network = 192.168.1.0
# broadcast = 192.168.1.255
#
# [Adjust the ranges to match your network setup.]

View File

@@ -23,12 +23,13 @@ xen-create-image - Create a new Xen instance of Debian Sarge.
--memory Setup the amount of memory allocated to the instance.
--size Set the size of the primary disk image.
--swap Set the size of the swap partition.
--kernel Set the path to the kernel to use for domU
Networking options:
--dhcp Setup the image to get an IP address via DHCP
--network Setup the network the host is upon.
--gateway Setup the iamge's network gateway.
--broadcast Setup the image's network broadcast address.
--ip Setup the ip
--netmask Setup the netmask
--mirror Setup the mirror to use when installing Sarge.
Mandatory options:
@@ -46,9 +47,6 @@ xen-create-image - Create a new Xen instance of Debian Sarge.
=item B<--boot>
Start the new virtual instance as soon as the installation has finished.
=item B<--broadcast>
Specify the broadcast address for the virtual image, only useful if DHCP is not used.
=item B<--debug>
Show the commands this script executes as an aid to debugging.
@@ -56,7 +54,7 @@ Show the commands this script executes as an aid to debugging.
Anything specified after this will be passed onto the debootstrap command executed.
=item B<--dhcp>
Specify that the virtual image should use DHCP to obtain its networking information.
Specify that the virtual image should use DHCP to obtain its networking information. Conflicts with B<--ip>.
=item B<--dir>
Specify the root directory beneath which the image should be saved. Subdirectories will be created for each virtual image.
@@ -77,6 +75,12 @@ Show the brief help information.
=item B<--hostname>
Set the hostname of the new instance.
=item B<--ip>
Set the IP address for the virtual image. Conflicts with B<--dhcp>
=item B<--kernel>
Set the path to the kernel to use for the image.
=item B<--manual>
Read the manual, with examples.
@@ -90,9 +94,6 @@ Specify the mirror to use to the installation of Sarge, defaults to http://ftp.u
=item B<--netmask>
Set the netmask the virtual image should use.
=item B<--network>
Specify the network the virtual image is living upon. Only useful if DHCP is not used.
=item B<--size>
Specify the size of the virtual images primary drive. The size may be
suffixed with either Mb, or Gb.
@@ -121,7 +122,7 @@ Show the version number and exit.
IP address 192.168.1.200, with the gateway address of 192.168.1.1
xen-create-image --size=2Gb --swap=128Mb \
--ip=192.168.1.200 --netmask=255.255.255.0 --network=192.168.1.0 \
--ip=192.168.1.200 --netmask=255.255.255.0
--gateway=192.168.1.1 \
--dir=/home/xen --hostname=vm02
@@ -189,16 +190,16 @@ Show the version number and exit.
#
# Images
#
fs = ext3 # We like EXT3
swap = 128mb # 128Mb of swap.
size = 2Gb # 2Gb images.
fs = ext3 # We like EXT3
swap = 128mb # 128Mb of swap.
size = 2Gb # 2Gb images.
kernel = /boot/vmlinuz-2.6.12-xenU # domU kernl
#
# Networking options.
#
network = 192.168.1.0
gateway = 192.168.1.1
broadcast = 255.255.255.0
netmask = 255.255.255.0
=for example end
@@ -248,7 +249,7 @@ Show the version number and exit.
--
http://www.steve.org.uk/
$Id: xen-create-image,v 1.51 2005-12-21 19:30:01 steve Exp $
$Id: xen-create-image,v 1.52 2005-12-22 23:32:52 steve Exp $
=cut
@@ -340,13 +341,16 @@ $FILESYSTEM_MOUNT{'reiserfs'} = '-t reiserfs';
# These may be overriden by one of the configuration files, or by the
# command line arguments.
#
$CONFIG{'memory'} = '96Mb';
$CONFIG{'size'} = '2000Mb';
$CONFIG{'swap'} = '128M';
$CONFIG{'fs'} = 'ext3';
$CONFIG{'mirror'} = 'http://ftp.us.debian.org/debian';
$CONFIG{'dist'} = 'sarge';
$CONFIG{'xm'} = '/usr/sbin/xm';
$CONFIG{'memory'} = '96Mb';
$CONFIG{'size'} = '2000Mb';
$CONFIG{'swap'} = '128M';
$CONFIG{'fs'} = 'ext3';
$CONFIG{'mirror'} = 'http://ftp.us.debian.org/debian';
$CONFIG{'dist'} = 'sarge';
$CONFIG{'xm'} = '/usr/sbin/xm';
$CONFIG{'kernel'} = '/boot/vmlinuz-2.6.12-xenU';
$CONFIG{'debootstrap'} = '';
#
# Read configuration file(s) if they exist.
@@ -400,15 +404,14 @@ print "----------------\n";
print "Image size : $CONFIG{'size'}\n";
print "Swap size : $CONFIG{'swap'}\n";
print "Memory size : $CONFIG{'memory'}\n";
print "Kernel Path : $CONFIG{'kernel'}\n";
print "\nNetworking Information\n";
print "----------------------\n";
$CONFIG{'ip'} && print "IP Address : $CONFIG{'ip'}\n";
$CONFIG{'dhcp'} && print "IP Address : DHCP\n";
$CONFIG{'network'} && print "Network : $CONFIG{'network'}\n";
$CONFIG{'netmask'} && print "Netmask : $CONFIG{'netmask'}\n";
$CONFIG{'broadcast'} && print "Broadcast : $CONFIG{'broadcast'}\n";
$CONFIG{'gateway'} && print "Gateway : $CONFIG{'gateway'}\n";
print "\n\n";
@@ -624,9 +627,24 @@ if ( -d $dir . "/lib/tls" )
# Now setup the fstab
#
print "\n\nSetting up /etc/fstab\n";
#
# XFS requires different options for the fstab file. *sigh*.
#
my $options;
if ( $CONFIG{'fs'} eq "xfs" )
{
$options = "defaults";
}
else
{
$options = "errors=remount-ro";
}
open( TAB, ">", $dir . "/etc/fstab" );
print TAB<<E_O_TAB;
/dev/sda1 / $CONFIG{'fs'} errors=remount-ro 0 1
/dev/sda1 / $CONFIG{'fs'} $options 0 1
/dev/sda2 none swap sw 0 0
proc /proc proc defaults 0 0
E_O_TAB
@@ -646,7 +664,7 @@ print "Done\n";
#
# Install OpenSSH
#
installOpenSSH( $dir );
installImagePackages( $dir );
#
@@ -671,7 +689,7 @@ runCommand( "umount $dir" );
print "\n\nCreating Xen configuration file in /etc/xen .. ";
open( XEN, ">", "/etc/xen/$CONFIG{'hostname'}.cfg" );
print XEN<<E_O_XEN;
kernel = "/boot/vmlinuz-2.6.12-xenU"
kernel = "$CONFIG{'kernel'}"
memory = $CONFIG{'memory'}
name = "$CONFIG{'hostname'}"
disk = [ 'file:$image,sda1,w','file:$swap,sda2,w' ]
@@ -840,26 +858,25 @@ sub parseCommandLineArguments
# Parse options.
#
GetOptions(
"hostname=s", \$CONFIG{'hostname'},
"ip=s", \$CONFIG{'ip'},
"gateway=s", \$CONFIG{'gateway'},
"netmask=s", \$CONFIG{'netmask'},
"broadcast=s",\$CONFIG{'broadcast'},
"network=s", \$CONFIG{'network'},
"dir=s", \$CONFIG{'dir'},
"dhcp", \$CONFIG{'dhcp'},
"mirror=s", \$CONFIG{'mirror'},
"size=s", \$CONFIG{'size'},
"swap=s", \$CONFIG{'swap'},
"memory=s", \$CONFIG{'memory'},
"fs=s", \$CONFIG{'fs'},
"boot", \$CONFIG{'boot'},
"dist=s", \$CONFIG{'dist'},
"hostname=s", \$CONFIG{'hostname'},
"ip=s", \$CONFIG{'ip'},
"gateway=s", \$CONFIG{'gateway'},
"netmask=s", \$CONFIG{'netmask'},
"dir=s", \$CONFIG{'dir'},
"dhcp", \$CONFIG{'dhcp'},
"mirror=s", \$CONFIG{'mirror'},
"size=s", \$CONFIG{'size'},
"swap=s", \$CONFIG{'swap'},
"memory=s", \$CONFIG{'memory'},
"fs=s", \$CONFIG{'fs'},
"boot", \$CONFIG{'boot'},
"dist=s", \$CONFIG{'dist'},
"debootstrap=s",\$CONFIG{'debootstrap'},
"debug" , \$CONFIG{'debug'},
"help", \$HELP,
"manual", \$MANUAL,
"version", \$VERSION
"debug" , \$CONFIG{'debug'},
"kernel=s", \$CONFIG{'kernel'}
"help", \$HELP,
"manual", \$MANUAL,
"version", \$VERSION
);
pod2usage(1) if $HELP;
@@ -868,7 +885,7 @@ sub parseCommandLineArguments
if ( $VERSION )
{
my $REVISION = '$Id: xen-create-image,v 1.51 2005-12-21 19:30:01 steve Exp $';
my $REVISION = '$Id: xen-create-image,v 1.52 2005-12-22 23:32:52 steve Exp $';
$VERSION = join (' ', (split (' ', $REVISION))[2]);
$VERSION =~ s/,v\b//;
$VERSION =~ s/(\S+)$/$1/;
@@ -1001,7 +1018,6 @@ EOF
{
$CONFIG{'gateway'} = '';
$CONFIG{'netmask'} = '';
$CONFIG{'broadcast'} = '';
$CONFIG{'ip'} = '';
}
@@ -1076,8 +1092,6 @@ iface eth0 inet static
address $CONFIG{'ip'}
gateway $CONFIG{'gateway'}
netmask $CONFIG{'netmask'}
network $CONFIG{'network'}
broadcast $CONFIG{'broadcast'}
E_O_STATIC_IP
}
@@ -1087,21 +1101,51 @@ E_O_STATIC_IP
=head2 installOpenSSH
=head2 installImagePackages
Install OpenSSH upon the virtual instance via apt-get.
Install some basic packages upon the new image. This will always
include OpenSSH. For specific filesystem images we will install
different packages:
xfs filesystem -> Install xfsprogs
reiser filesystem -> Install reiserfsprogs
=cut
sub installOpenSSH
sub installImagePackages
{
my ( $prefix ) = ( @_ );
print "\n\nInstalling OpenSSH\n";
print "\n\nInstalling OpenSSH into new system\n";
runCommand( "chroot $prefix /usr/bin/apt-get update" );
runCommand( "DEBIAN_FRONTEND=noninteractive chroot $prefix /usr/bin/apt-get --yes --force-yes install ssh" );
runCommand( "chroot $prefix /etc/init.d/ssh stop" );
print "Done\n";
#
# Extra packages to install.
#
my $extra = "";
if ( $CONFIG{'fs'} eq "xfs" )
{
$extra = "xfsprogs";
}
elsif ( $CONFIG{'fs'} eq "reiserfs" )
{
$extra = "reiserfsprogs";
}
#
# Install whatever we're supposed to.
#
if ( length( $extra ) )
{
print "\n\nInstalling package into new system: $extra\n";
runCommand( "DEBIAN_FRONTEND=noninteractive chroot $prefix /usr/bin/apt-get --yes --force-yes install $extra" );
print "Done\n";
}
}

View File

@@ -17,11 +17,11 @@ xen-duplicate-image - Duplicate an existing Xen instance.
--dir Specify where the output images should go.
Networking options:
--dhcp Setup the image to get an IP address via DHCP
--network Setup the network the host is upon.
--dhcp Setup the image to get its networking details via DHCP
--gateway Setup the gateway for the image.
--ip Setup the IP address for the image.
--netmask Setup the netmask the host should use.
--gateway Setup the iamge's network gateway.
--broadcast Setup the image's network broadcast address.
Mandatory options:
@@ -39,11 +39,8 @@ xen-duplicate-image - Duplicate an existing Xen instance.
=item B<--boot>
Boot the new instance immediately after creating it.
=item B<--broadcast>
Specify the broadcast address for the virtual image, only useful if DHCP is not used.
=item B<--dhcp>
Specify that the virtual image should use DHCP to obtain its networking information.
Specify that the virtual image should use DHCP to obtain its networking information. Conflicts with B<--ip>.
=item B<--gateway>
Specify the gateway address for the virtual image, only useful if DHCP is not used.
@@ -51,15 +48,15 @@ Specify the gateway address for the virtual image, only useful if DHCP is not us
=item B<--help>
Show the brief help information.
=item B<--ip>
Specify the IP address for the virtual image. Conflicts with B<--dhcp>.
=item B<--manual>
Read the manual, with examples.
=item B<--netmask>
Setup the netmask the host should use.
=item B<--network>
Specify the network the virtual image is living upon. Only useful if DHCP is not used.
=item B<--from>
Specify the virtual instance that we should copy.
@@ -110,7 +107,7 @@ Show the version number and exit.
--
http://www.steve.org.uk/
$Id: xen-duplicate-image,v 1.8 2005-12-21 22:46:36 steve Exp $
$Id: xen-duplicate-image,v 1.9 2005-12-22 23:32:52 steve Exp $
=cut
@@ -205,9 +202,8 @@ if ( $CONFIG{'dhcp'} )
else
{
$CONFIG{'ip'} && print "IP : $CONFIG{'ip'}\n";
$CONFIG{'network'} && print "Network : $CONFIG{'network'}\n";
$CONFIG{'broadcast'} && print "Broadcast: $CONFIG{'broadcast'}\n";
$CONFIG{'gateway'} && print "Gateway : $CONFIG{'gateway'}\n";
$CONFIG{'netmask'} && print "Gateway : $CONFIG{'netmask'}\n";
}
print "---\n";
@@ -295,7 +291,7 @@ setupNetworking( $dir );
print "Setting up Xen configuration file .. ";
open( XEN, ">", "/etc/xen/$CONFIG{'hostname'}.cfg" );
print XEN<<E_O_XEN;
kernel = "/boot/vmlinuz-2.6.12-xenU"
kernel = "$CONFIG{'kernel'}"
memory = $CONFIG{'memory'}
name = "$CONFIG{'hostname'}"
disk = [ 'file:$image_out,sda1,w','file:$swap_out,sda2,w' ]
@@ -418,10 +414,9 @@ sub parseCommandLineArguments
"from=s", \$CONFIG{'from'},
"ip=s", \$CONFIG{'ip'},
"gateway=s", \$CONFIG{'gateway'},
"mask=s", \$CONFIG{'netmask'},
"broadcast=s",\$CONFIG{'broadcast'},
"network=s", \$CONFIG{'network'},
"netmask=s", \$CONFIG{'netmask'},
"dir=s", \$CONFIG{'dir'},
"kernel=s", \$CONFIG{'kernel'},
"dhcp", \$CONFIG{'dhcp'},
"help", \$HELP,
"manual", \$MANUAL,
@@ -434,7 +429,7 @@ sub parseCommandLineArguments
if ( $VERSION )
{
my $REVISION = '$Id: xen-duplicate-image,v 1.8 2005-12-21 22:46:36 steve Exp $';
my $REVISION = '$Id: xen-duplicate-image,v 1.9 2005-12-22 23:32:52 steve Exp $';
$VERSION = join (' ', (split (' ', $REVISION))[2]);
$VERSION =~ s/,v\b//;
$VERSION =~ s/(\S+)$/$1/;
@@ -556,7 +551,6 @@ EOF
{
$CONFIG{'gateway'} = '';
$CONFIG{'netmask'} = '';
$CONFIG{'broadcast'} = '';
$CONFIG{'ip'} = '';
}
}
@@ -610,8 +604,6 @@ iface eth0 inet static
address $CONFIG{'ip'}
gateway $CONFIG{'gateway'}
netmask $CONFIG{'netmask'}
network $CONFIG{'network'}
broadcast $CONFIG{'broadcast'}
E_O_STATIC_IP
}