For this year's Software Freedom Day event I wanted to give everyone who attented a zone to play with (mainly for the Glassfish hands-on lab). For that, I needed to install a lot of zones, and I wanted to automate the process.

You're going to need a template zone. Just simply create it, install it, but do not boot it up.

Then you need two config files: a zone template (for zonecfg) and a sysidcfg file, so you don't neet to configure anything when you boot it up.

zoneTEMPLATE file:

create -b
set zonepath=/zones/NAME
set brand=ipkg
set autoboot=true
set ip-type=exclusive
add inherit-pkg-dir
set dir=/lib
end
add inherit-pkg-dir
set dir=/platform
end
add inherit-pkg-dir
set dir=/sbin
end
add inherit-pkg-dir
set dir=/usr
end
add inherit-pkg-dir
set dir=/opt
end
add net
set physical=NICXXX
end


The sysidcfg template file:

system_locale=en_US.UTF-8
terminal=vt100
network_interface=PRIMARY {
hostname=NAME
ip_address=192.168.1.101
netmask=255.255.255.0
protocol_ipv6=no
default_route=192.168.1.254}
root_password=KzYq2RZu85OCM
timezone=Europe/Budapest
timeserver=time.kfki.hu
security_policy=none
nfs4_domain=dynamic
name_service=DNS
{domain_name=sfd2009.local.sun.hu
name_server=192.168.1.254
search=sfd2009.local.sun.hu}


The root password is "almafa". You can now use my install script to create a zone by simply doing ./install.sh X, where X is the zone's id.

install.sh:

#!/bin/bash
cat zoneTEMPLATE | sed -e "s/NAME/zone$1/g" | sed -e "s/NICXXX/vnic$1/g" > zone$1.cfg
cat sysidcfgTEMPLATE | sed -e "s/NAME/zone$1/g" | sed -e "s/192\.168\.1\.101/192.168.1.10$1/g" > zone$1.sysidcfg
zonecfg -z zone$1 -f zone$1.cfg
zoneadm -z zone$1 clone template
zoneadm -z zone$1 ready
cp zone$1.sysidcfg /zones/zone$1/root/etc/sysidcfg
zoneadm -z zone$1 boot





More...