Oracle Blog

fintanr's weblog

Jumpstart and Zone Creation

One of the many cool features available in Solaris is Zones. As Sean
has already blogged automation is the name of the game, and part
of this is creating required zones when we jumpstart a machine.

The example here is quite striped down, and creates three very simple zones
once a machine is jumpstarted, with very limited configuration - but using
zonecfg(1M) and the various resource management utilities you can modify this
to suit your needs. This example was tested on the latest Solaris Express.

Anyway, enough talk, you can download the script here, and for your
persual...

#!/bin/sh
#
# create (very) simple zones after a jumpstart
#
# this finish script gives an example of how you can create
# some zones post jumpstart. You need to know the name(s) of
# the zones you wish to create, their ip addresses and the
# network interface you wish to use. It is assumed that netmasks
# have been set up correctly during your install
#
# In the example here we create three zones on a 192.1.1 subnet
# each using bge0 as their interface.
#
# The script runs as follows
#
# Section 1 - As a jumpstart finish script
# -------------------------------------------------
# 1. append details on the zone to your hosts file
# where applicable
# 2. create the initial directory for the zone(s)
# 3. create the zonecfg input file
# 4. Create the rc3.d script we will use after reboot
#
# Section 2 - After initial reboot
# -------------------------------------------------
# 1. create and install zone(s)
# 2. set zone state to ready
# 3. boot zone
#
#
# Each zone is based on a very simple spare root zone, for further
# details on Zones and the various configuration options consult the
# manpages for zones(5), zoneadm(1M) and zonecfg(1M)
#
# Additional documentation on zones along with tips and articles
# can be found in the Zones section of BigAdmin at
# http://www.sun.com/bigadmin/content/zones/
#
# ZONE_DETAILS - colon seperated listed of zones, containing
# zone-name:ip address:interface to use
#
ZONE_DETAILS="test-js-zone-1:192.1.1.1:bge0
test-js-zone-2:192.1.1.2:bge0
test-jes-zone-3:192.1.1.3:bge0"
# ZONE_BASE - root directory for your zones to be created in
#
ZONE_BASE="/export/zones"
appendToHostFile() {
LZONE_NAME=$1
LZONE_IP=$2
if [ ! -f $MOUNT_PREFIX/etc/hosts.prezone ]
then
cp $MOUNT_PREFIX/etc/hosts $MOUNT_PREFIX/etc/hosts.prezone
fi
grep -v $LZONE_NAME $MOUNT_PREFIX/etc/hosts > /tmp/hosts
echo "$LZONE_IP $LZONE_NAME" >> /tmp/hosts
mv /tmp/hosts $MOUNT_PREFIX/etc/hosts
}
createZoneCfg() {
LZONE_NAME=$1
LZONE_IP=$2
LZONE_INTERFACE=$3
cat >$MOUNT_PREFIX/$ZONE_BASE/zonecfg/$LZONE_NAME.zcf $MOUNT_PREFIX/etc/rc3.d/S99zonejumpstartexample > $MOUNT_PREFIX/etc/rc3.d/S99zonejumpstartexample > $MOUNT_PREFIX/etc/rc3.d/S99zonejumpstartexample