/
xen-create-image
executable file
·3598 lines (2724 loc) · 84.2 KB
/
xen-create-image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
=head1 NAME
xen-create-image - Easily create new Xen instances with networking and OpenSSH.
=cut
=head1 SYNOPSIS
Help Options:
--help Show the help information for this script.
--manual Read the manual, and examples, for this script.
--verbose Show useful debugging information.
--version Show the version number and exit.
Size / General options:
--accounts Copy all non-system accounts to the guest image
--admins Specify that some administrators should be created for
this image, using xen-shell.
--boot Boot the new instance after creating it.
--cache Cache .deb files on the host when installing the new guest
with the debootstrap tool.
--config Read the specified file in addition to the global
configuration file.
--copy-cmd NOP: Ignored.
--debootstrap-cmd NOP: Ignored.
--force Force overwriting existing images.
This will remove existing images or LVM volumes which match
those which are liable to be used by the new invocation.
--fs Specify the filesystem type to use for the new guest.
Valid choices are 'ext2', 'ext3', 'reiserfs', or 'xfs'.
--image Specify whether to create "sparse" or "full" disk images.
Full images are mandatory when using LVM, so this setting
is ignored in that case.
--image-dev Specify a physical/logical volume for the disk image.
--initrd Specify the initial ramdisk
If an image is specified it must exist.
--keep Don't delete our images if installation fails.
--kernel Set the path to the kernel to use for domU.
If a kernel is specified it must exist.
--memory Setup the amount of memory allocated to the new instance.
--modules Set the path to the kernel modules to use for domU.
If modules are specified they must exist.
--output Specify the output directory to create the xen configuratoin
file within.
--install Specify whether to install the guest system or not.
--hooks Specify whether to run hooks after the image is created.
--partitions Use a specific partition layout configuration file.
Not supported with the image-dev and swap-dev options.
Parameters fs, size, swap and noswap are ignored when
using this option.
--passwd Ask for a root password during setup.
NOTE: This is done interactively.
--role Run the specified role script(s) post-install.
Role scripts are discussed later in this manpage.
--role-args Pass the named string literally to any role script.
This is useful for site-specific roles.
--roledir Specify the directory which contains the role scripts.
This defaults to /etc/xen-tools/role.d/
--size Set the size of the primary disk image.
--tar-cmd NOP: Ignored.
--extension Specify the suffix to give the Xen configuration file.
--swap Set the size of the swap partition.
--swap-dev Specify a physical/logical volume for swap usage.
--noswap Do not create a swap partition.
When this option is used the system will not have a swap
entry added to its /etc/fstab file either.
--ide Use IDE names for virtual devices (i.e. hda not sda)
Installation options:
--arch Pass the given architecture to debootstrap, rinse,
or rpmstrap when installing the system. This argument
is ignored for other install methods.
--dist Specify the distribution you wish to install.
--install-method Specify the installation method to use.
--install-source Specify the source path to use when installing via
a copy or tarball installation.
--mirror Setup the mirror to use when installing via debootstrap.
--template Specify which template file to use when creating the
Xen configuration file.
Networking options:
--dhcp The guest will be configured to fetch its networking
details via DHCP.
--gateway Setup the network gateway for the new instance.
--ip Setup the IP address of the machine, multiple IPs
are allowed. When specifying more than one IP the
first one is setup as the "system" IP, and the additional
ones are added as aliases.
Note that Xen 3.x supports a maximum of three vif statements
per guest.
This option conflicts with --dhcp.
--mac Specify the MAC address to use for a given interface.
This is only valid for the first IP address specified, or
for DHCP usage. (ie. you can add multiple --ip flags,
but the specific MAC address will only be used for the
first interface.)
--netmask Setup the netmask for the new instance.
--broadcast Setup the broadcast address for the new instance.
Mandatory options:
--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
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 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
of the hook scripts will expect to be able to parse
a domain name out of it for various purposes.
=cut
=head1 NOTES
This script is a wrapper around three distinct external tools which
complete various aspects of the new system installation.
=over 8
=item B<xt-install-image>
Install a new distribution.
=item B<xt-customize-image>
Run a collection of hook scripts to customise the freshly installed system.
=item B<xt-create-xen-config>
Create a Xen configuration file in so that xm can start the new domain.
=back
The result of invoking these three scripts, and some minor glue between
them, is a simple means of creating new Xen guest domains.
=cut
=head1 DESCRIPTION
xen-create-image is a simple script which allows you to create new
Xen instances easily. The new image will be given two volumes. These
volumes will be stored upon the host as either loopback files, or
LVM logical volumes:
1. An image for the systems root disk.
2. An image for the systems swap device.
The new virtual installations will be configured with networking,
have OpenSSH installed upon it, and have most of its basic files
setup correctly.
If you wish you can configure arbitary partitioning schemes, rather
than being restricted to just the two standard volumes. For more
details on this please see the later section in this manual "PARTITIONING".
=cut
=head1 CONFIGURATION
To reduce the length of the command line each of the supported options
may be specified inside a configuration file.
The global configuration file read for options is:
/etc/xen-tools/xen-tools.conf
The configuration file may contain comments which begin with the
hash '#' character. Otherwise the format is 'key = value'.
A sample configuration file would look like this:
=for example begin
#
# Output directory. Images are stored beneath this directory, one
# subdirectory per hostname.
#
dir = /home/xen
#
# LVM users should disable the 'dir' setting above, and instead
# specify the name of the volume group to use.
#
# 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.
#
size = 2Gb # Disk image size.
image = full # Allocate the full disk size immediately.
memory = 128Mb # Memory size
swap = 128Mb # Swap size
fs = ext3 # use EXT3 filesystems
dist = sarge # Default distribution to install.
#
# Kernel options.
#
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
#
# Networking options.
#
gateway = 192.168.1.1
broadcast = 192.168.1.255
netmask = 255.255.255.0
#
# Installation method:
# One of "copy", "debootstrap", "rinse", "rpmstrap", or "tar".
#
install-method = debootstrap
=for example end
Using this configuration file a new image may be created with the
following command:
xen-create-image --hostname=vm03.my.flat --ip=192.168.1.201
This makes use of loopback images stored beneath /home/xen and
will be installed via the debootstrap command.
=cut
=head1 NETWORKING AUTO-SETUP
We've already seen how the "gateway" and "netmask" options can
be used to specify the networking options of the freshly created
Xen guests.
One other useful shortcut is the use of an automatic IP address.
You can specify '--ip=auto' and the system will choose and use
an IP address from those listed in /etc/xen-tools/ips.txt.
For example if you wished to have Xen guests automatically
take an address from the range 192.168.1.100-192.168.1.200 you
would first prepare the system by running this:
=for example start
rm /etc/xen-tools/ips.txt
for i in $(seq 100 200) ; do echo 192.168.1.$i >> /etc/xen-tools/ips.txt ; done
=for example end
Now you can create a guest with the command:
=for example start
xen-create-image --ip=auto --hostname=blah [--dist=...]
=for example end
The first time this ran the machine would recieve an IP address
from the pool which we've created. This IP would be marked as used,
and would no longer be available. If all the IP addresses are taken
then the system will fail.
=cut
=head1 PARTITIONING
By default all new guests are created with two "volumes", one
for the root filesystem and one for the new system's swap.
If you wish you may specify an alternative partitioning scheme.
Simply create a file inside the directory /etc/xen-tools/partitions.d/
specifying your partition layout. (Use the existing file "sample-server"
as a template).
Now when you create a new image specify the name of this file with as
an argument to the --partition option.
=cut
=head1 XEN CONFIGURATION FILE
Once a new image has been created an appropriate configuration file
for Xen will be saved in the directory /etc/xen by default. However
you may change the output directory with the --output flag.
The configuration file is built up using the template file
/etc/xen-tools/xm.tmpl - which is a file processed via
the Text::Template perl module.
If you wish to modify the files which are generated please make your
changes to that input file.
Alternatively you can create multiple configuration files and
specify the one to use with the --template option.
=cut
=head1 LOOPBACK EXAMPLES
The following will create a 2Gb disk image, along with a 128Mb
swap file with Debian Sarge setup and running via DHCP.
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--dir=/home/xen --hostname=vm01.my.flat
This next example sets up a host which has the name 'vm02.my.flat' and
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
--gateway=192.168.1.1 \
--dir=/home/xen --hostname=vm02.my.flat
The directory specified for the output will be used to store the volumes
which are produced. To avoid clutter each host will have its images
stored beneath the specified directory, named after the hostname.
For example the images created above will be stored as:
$dir/domains/vm01.my.flat/
$dir/domains/vm01.my.flat/disk.img
$dir/domains/vm01.my.flat/swap.img
$dir/domains/vm02.my.flat/
$dir/domains/vm02.my.flat/disk.img
$dir/domains/vm02.my.flat/swap.img
The '/domains/' subdirectory will be created if necessary.
=cut
=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
specify one.
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--lvm=myvolumegroup --hostname=vm01.my.flat
The given volume group will have two new logical 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/myvolumegroup/vm01.my.flat-disk /mnt/foo
=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
The new guest images may be installed in several different ways:
1. Using the debootstrap command, which must be installed and present.
2. Using the rpmstrap command, which must be installed and present.
3. using the rinse command, which must be installed and present.
4. By copying an existing installation.
5. By untarring a file containing a previous installation.
These different methods can be selected by either the command line
arguments, or settings in the configuration file. Only one installation
method may be specified at a time; they are mutually-exclusive.
=cut
=head1 INSTALLATION SPEEDUPS
After performing your first installation you can customize it, or
use it untouched, as a new installation source. By doing this you'll
achieve a significant speedup, even above using the debootstrap caching
support.
There are two different ways you can use the initial image as source
for a new image:
1. By tarring it up and using the tar-file as an installation source.
2. By mounting the disk image of the first system and doing a literal copy.
Tarring up a pristine, or customised, image will allow you to install
with a command such as:
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--lvm=myvolumegroup --hostname=vm01.my.flat \
--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
to create a new image using the old one as source:
xen-create-image --size=2Gb --swap=128Mb --dhcp \
--lvm=myvolumegroup --hostname=vm01.my.flat \
--install-method=copy --install-source=/path/to/copy/from
=cut
=head1 DEBOOTSTRAP CACHING
When installing new systems with the debootstrap tool there is
a fair amount of network overhead.
To minimize this the .deb files which are downloaded into the
new instance are cached by default upon the host, in the directory
/var/cache/apt/archives.
When a new image is created these packages are copied into the new
image - before the debootstrap process runs - this should help avoid
expensive network reading.
If you wish to clean the cache upon the host you may do so with
apt-get, as you'd expect:
apt-get clean
(This feature can be disabled with the command line flag --cache=no,
or by the matching setting in the configuration file.)
=cut
=head1 ROLES
Currently there are some roles scripts included which work for
the Debian Sarge and Etch distrubtions only. They are included
primarily as examples of the kind of things you could accomplish.
The supplied scripts are:
=over 8
=item builder
Setup the new virtual images with commonly used packages for rebuilding
Debian packages from their source.
=item gdm
Install an X11 server, using VNC and GDM
=item minimal
Customise the generated images to remove some packages.
=item xdm
Install an X11 server, using VNC and XDM
=back
If you'd like to include your own role scripts you'll need to
create a file in /etc/xen-tools/role.d, and then specify the
name of that file with "--role=filename". Additionally you
may pass options to your role-script with the --role-args
flag.
For example the script /etc/xen-tools/role.d/gdm would be used
by executing with "--role=gdm".
Role scripts are invoked with the directory containing the
installed system as their first argument, and anything passed
as a role-arg will be passed allong as additional arguments.
NOTE: Multiple role scripts may be invoked if you separate their
names with commas.
=cut
=head1 THE SKELETON DIRECTORY
Any files present in the directory /etc/xen-tools/skel will be copied
across to each new guest image. The role of this directory is analogous
to the /etc/skel directory.
A typical use for this would be to copy a public key across to each
new system. You could do this by running:
=for example start
mkdir -p /etc/xen-tools/skel/root/.ssh
chmod -R 700 /etc/xen-tools/skel/root
cp /root/.ssh/id_rsa.pub /etc/xen-tools/skel/root/.ssh/authorized_keys2
chmod 644 /etc/xen-tools/skel/root/.ssh/authorized_keys2
=for example cut
=head1 AUTHOR
Steve
--
http://www.steve.org.uk/
=cut
=head1 LICENSE
Copyright (c) 2005-2007 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 Digest::MD5 qw/ md5_hex /;
use Env;
use File::Path qw/ mkpath /;
use File::Temp qw/ tempdir /;
use Getopt::Long;
use Pod::Usage;
#
# Configuration values read initially from the global configuration
# file, then optionally overridden by the command line.
#
my %CONFIG;
#
# Partition layout information values read from the partitions file,
# or constructed automatically if no partitions file is specified.
#
my @PARTITIONS = undef;
#
# Global variable containing the temporary file where our image
# is mounted for installation purposes.
#
# Why is this here?
#
# Well it makes sure that the magic "END" section can unmount it
# if there are errors.
#
#
my $MOUNT_POINT = undef;
#
# This flag is set upon failure, after images have been created.
#
# It is used so that we can automatically "rollback" upon failure.
#
my $FAIL = 0;
#
# Release number.
#
my $RELEASE = '3.9';
#
# Setup default options.
#
setupDefaultOptions();
#
# Read the global configuration file.
#
readConfigurationFile( "/etc/xen-tools/xen-tools.conf" );
#
# Parse the command line arguments.
#
parseCommandLineArguments();
#
# If we received an additional configuration file then read it.
#
if ( $CONFIG{'config'} )
{
my $path = $CONFIG{'config'};
# If not fully-qualified then read from /etc/xen-tools.
if ( $path !~ /^[\/]/ )
{
$path = "/etc/xen-tools/" . $path;
}
# Read the file, if it exists.
if ( -e $path )
{
readConfigurationFile( $path );
}
else
{
logprint( "The specified configuration file does not exist: '$path'\n",
"Aborting\n\n"
);
exit 127;
}
}
#
# Process --debug
#
if ( $CONFIG{'debug'} )
{
foreach my $key ( sort keys %CONFIG )
{
print $key;
print " : " . $CONFIG{$key} if ( $CONFIG{$key} );
print "\n";
}
exit 127;
}
#
# Check the environment - after parsing arguments.
#
# This is required so that the "--help" flag will work even if our support
# scripts are not installed, etc.
#
checkSystem();
#
# Ensure we're started by root at this point. This is required
# to make sure we can create new LVM volumes, mount loopback images, or
# carry out other privileged actions.
#
testRootUser();
#
# Check our arguments were sane and complete.
#
checkArguments();
#
# Make sure we have a log directory
#
setupLogFile();
#
# Check we have binaries installed which we expect to use.
#
checkBinariesPresent();
#
# Setup default partitioning scheme if we don't have one.
#
# NOTE: This must be done before we call "showSummary".
#
if ( !$#PARTITIONS )
{
populatePartitionsData() if ( ( $CONFIG{'dir'} ) ||
( $CONFIG{'evms'} ) ||
( $CONFIG{'lvm'} ) );
}
#
# Show a summary of what we're going to do.
#
showSummary();
#
# Create and format the images if we're using loopback filesystems.
#
if ( $CONFIG{'dir'} )
{
#
# Test to see if "loop" module is loaded. This is probably
# not required, except for paranoia.
#
testLoopbackModule();
#
# Create disk + swap images.
#
createLoopbackImages();
}
elsif ( $CONFIG{'lvm'} )
{
#
# Create our LVM partitions.
#
createLVMBits();
}
elsif ( $CONFIG{'evms'} )
{
#
# Create our EVMS partitions.
#
createEVMSBits();
}
elsif ( $CONFIG{'image-dev'} )
{
#
# Use physical disc
#
usePhysicalDevice();
}
else
{
# Can't happen we didn't get an installation type.
logprint( "Error: No recognised installation type.\n",
"Please specify a directory, lvm, or evms volume to use.\n"
);
$FAIL = 1;
exit 127;
}
#
# Mount the image.
#
mountImage();
#
# Export our environment for the hooks/role script we might be
# running later.
#
# Do this unconditionally now, so that we're all setup to run
# a hook even if we're not installing a system.
#
exportEnvironment();
#
# If we're installing then do so, and test that it worked with
# a binary name that is reasonably likely to exist under any
# distribution of GNU/Linux.
#
if ( $CONFIG{'install'} )
{
#
# Install the system.
#
installSystem();
#
# Did that work?
#
if ( ! -x $MOUNT_POINT . "/bin/ls" )
{
logprint( "System installation failed. Aborting\n");
$FAIL = 1;
exit 127;
}
#
# Now customize the installation - setting up networking, etc.
#
if( $CONFIG{'hooks'} )
{
runCustomisationHooks();
}
}
#
# Run any specified role scripts.
#
runRoleScripts( $CONFIG{'role'} );
#
# Create the Xen configuration file.
#
runXenConfigCreation();
#
# Setup the password if the user wanted that.
#
setupRootPassword() if ( $CONFIG{'passwd'} );
#
# Report success.
#
logprint( "All done\n");
#
# If we're supposed to start the new instance do so - note here we
# have to unmount the image first.
#
if ( $CONFIG{'boot'} )
{
#
# Unmount the image and any subsequent mounts.
#
unMountImage( $MOUNT_POINT );
#
# Mark us as unmounted.
#
$MOUNT_POINT = undef;
#
# If there is an /etc/xen/auto directory then link
# in the domain so that it will automatically restart, if it isn't
# already present.
#
# (Will be present if this is overwriting a previous image, for example.)
#
if ( -d "/etc/xen/auto" )
{
my $cfg = $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'};
if ( ! -e $cfg )
{
logprint( "Creating auto-start symlink to: $cfg\n" );
my $link = "ln -s $cfg /etc/xen/auto/";
runCommand( $link );
}
}
#
#
# Start the image
#
$CONFIG{'pid'} = fork();
if ( $CONFIG{'pid'} )
{
# Parent.
exit;
}
else
{
# Config file.
my $cfg = $CONFIG{'output'} . "/" . $CONFIG{'hostname'} . $CONFIG{'extension'};
# Child.
system( "$CONFIG{'xm'} create $cfg >/dev/null 2>/dev/null" );
logprint( "Started new Xen guest: $CONFIG{'hostname'} [$cfg]\n" );
}
}
#
# Finished.
#
exit 0;
=begin doc
Test that this system is fully setup for the new xen-create-image
script.
This means that the the companion scripts xt-* are present on the
host and executable.
=end doc
=cut
sub checkSystem
{
my @required = qw ( / xt-customize-image xt-install-image xt-create-xen-config / );
foreach my $bin ( @required )
{
if ( ! defined( findBinary( $bin ) ) )
{
logprint("The script '$bin' was not found.\n",
"Aborting\n\n"
);
exit 127;