From Summerseas
#!/usr/bin/perl -w
$ZoneDir = '/zones';
# @Containers format is hostname:zonename:ip_addr:NIC:[sparse|whole
@Containers = qw(
ldom1-z1:zone1:192.168.100.71:e1000g0:sparse
ldom1-z2:zone2:192.168.100.72:e1000g0:whole
ldom1-z3:zone3:192.168.100.73:e1000g0:sparse
ldom1-z4:zone4:192.168.100.74:e1000g0:sparse
ldom1-z5:zone5:192.168.100.75:e1000g0:whole
);
if ( defined $ARGV[0] ) {
if ( $ARGV[0] =~ /destroy/ ) {
&_destroy;
exit;
}
}
sub _destroy {
my($hostname,$zonename,$ip,$nic,$root,$container);
foreach $container (@Containers) {
($hostname,$zonename,$ip,$nic,$root) = split(/:/,$container);
system("zoneadm -z $zonename halt");
system("zoneadm -z $zonename uninstall -F");
}
system("rm /etc/zones/zone*");
system("cp /u/engle/zones/scripts/Files/index /etc/zones/index");
}
foreach $container (@Containers) {
($hostname,$zonename,$ip,$nic,$root) = split(/:/,$container);
# First create a template for the current zone
&_create_template($hostname,$zonename,$ip,$nic,$root);
# Next create the zone and boot
system("zonecfg -z $zonename -f /tmp/zone_template");
system("zoneadm -z $zonename install");
# Customize the zone's environment a bit
system("cp /.profile $ZoneDir/$zonename/root/");
# Drop in a service profile for the zone
system("cp /u/engle/zones/scripts/Files/generic.xml.profile $ZoneDir/$zonename/root/var/svc/profile/generic.xml");
system("cp /.bashrc $ZoneDir/$zonename/root/");
system("cp /etc/default/login $ZoneDir/$zonename/root/etc/default/");
system("cp /etc/resolv.conf $ZoneDir/$zonename/root/etc/");
system("echo \"+ +\" > $ZoneDir/$zonename/root/.rhosts");
# Now create a sysidcfg file zo the zone doesn't need interaction during boot.
&_create_sysidcfg($hostname,$zonename,$ip,$nic,$root);
# We're now ready to boot the zone
system("zoneadm -z $zonename boot");
}
exit;
sleep(600);
# And finally let's start any desired services
foreach $container (@Containers) {
($hostname,$zonename,$ip,$nic,$root) = split(/:/,$container);
system("zlogin $zonename \"svcadm enable svc:/network/login:rlogin\"");
system("zlogin $zonename \"svcadm enable svc:/network/http:apache2\"");
}
sub _create_sysidcfg {
my ($hostname,$zonename,$ip,$nic,$root) = @_;
open(SYSIDCFG,">$ZoneDir/$zonename/root/etc/sysidcfg") or die "$!";
print SYSIDCFG "system_locale=en_US\n";
print SYSIDCFG "timezone=US/Eastern\n";
print SYSIDCFG "timeserver=localhost\n";
print SYSIDCFG "terminal=vt100\n";
print SYSIDCFG "name_service=NONE\n";
print SYSIDCFG "service_profile=OPEN\n";
print SYSIDCFG "security_policy=NONE\n";
print SYSIDCFG "root_password=7zXogXCDGmOLs\n";
print SYSIDCFG "nfs4_domain=dynamic\n";
print SYSIDCFG "network_interface=primary{\n";
print SYSIDCFG " netmask=255.255.255.0\n";
print SYSIDCFG " protocol_ipv6=no\n";
print SYSIDCFG " default_route=192.168.192.20\n";
print SYSIDCFG " hostname=$hostname\n";
print SYSIDCFG "}\n";
close(SYSIDCFG);
}
sub _create_template {
my ($hostname,$zonename,$ip,$nic,$root) = @_;
open(TEMPLATE,">/tmp/zone_template") or die "$!";
# Create -b creates a whole root zone. Just drop the
# -b for a sparse root zone. A sparse root zone will
# save space by r/o mounting /usr /lib /platform and /sbin
# from the global zone. Use the whole root model if the zone
# needs write access to those filesystems; for example
# the zone may want to nfs mount /usr/local or Oracle may
# want to update /usr/local/bin/oraenv.
print TEMPLATE "create -b\n" if (lc $root eq 'whole');
print TEMPLATE "create\n" if (lc $root ne 'whole');
print TEMPLATE "set zonepath=$ZoneDir/$zonename\n";
print TEMPLATE "set autoboot=true\n";
print TEMPLATE "add net\n";
print TEMPLATE "set address=$ip\n";
print TEMPLATE "set physical=$nic\n";
print TEMPLATE "end\n";
print TEMPLATE "commit\n";
close(TEMPLATE);
}