I found a way to automatically clone a zone. Her is a shell script which I 
created for that purpose :

---------- snip 
------------------------------------------------------------------------------------------

#!/bin/sh
#
# Shell script for automatically cloning a zone
#
#
#####################################################

#
# Different parameters for the zone configuration
#
#####################################################

BASE_ZONE="YOU_BASE_ZONE"
ZONE_ROOT="YOUR_ZONE_ROOT"
AUTOBOOT="false"
NIC="YOUR_NIC"
MEM_USAGE="512m"
SWAP="1g"
LOCKED="10m"
DOMAINNAME="YOUR_DOMAIN_NAME"
DNS="YOUR_DNS"
INTERACTIVE=0

#
# Arg1=zonename Arg2=ip address Arg3=-i for interactive
#
#####################################################

if [ $# -lt 2 ]
then
        echo "Usage: $0 zonename ipaddress [-i]"
        exit
fi

ZONENAME=$1
ZONE_PATH="$ZONE_ROOT/$ZONENAME"
IP_ADDRESS=$2

if [ $# == 3 ] && [ $3 == "-i" ]
then
        INTERACTIVE=1
fi

#
# Check if zone exists
#
#####################################################

zoneadm list -c| grep $ZONENAME >/dev/null 2>&1

if [ $? == 0 ]
then
        echo "Cannot create zone. Zone '$1' already exists !"
        exit
fi

echo "Configuring $ZONENAME"
if [ $INTERACTIVE == 1 ]
then
        echo "[RETURN to continue] CTRL-C to cancel"
        read
fi

#
# Configure new zone
#
#####################################################

zonecfg -z $ZONENAME "
        create;
        set autoboot=$AUTOBOOT;
        set zonepath=$ZONE_PATH;
        add net;
                set address=$IP_ADDRESS;
                set physical=$NIC;
        end;
        add capped-memory;
                set physical=$MEM_USAGE;
                set swap=$SWAP;
                set locked=$LOCKED;
        end;
        verify;
        commit;
exit;"

zoneadm list -cv 

echo "Done."

echo "Cloning $ZONENAME"
if [ $INTERACTIVE == 1 ]
then
        echo "[RETURN to continue] CTRL-C to cancel"
        read
fi

#
# Clone zone from $BASE_ZONE
#
#####################################################

zoneadm -z $ZONENAME clone $BASE_ZONE

zoneadm list -cv 

echo "Done."


echo "Saving sysidcfg to $ZONENAME"
if [ $INTERACTIVE == 1 ]
then
        echo "[RETURN to continue] CTRL-C to cancel"
        read
fi

#
# Detach the zones zonepath so that you can create
# the sysidcfg file in $ZONE_PATH/root/etc/sysidcfg.
# The crypted root password is root. I created this
# with the following C-Program :
#
# #include <stdio.h>
# #include <crypt.h>
# 
# main(){
#     printf("%s\n",crypt("root","XY"));
# }
# 
# A copy of a password from /etc/shadow seams to long
#
#####################################################

zoneadm -z $ZONENAME detach

echo "
system_locale=C
terminal=xterms
timezone=Europe/Berlin
timeserver=localhost
network_interface=primary {
        hostname=$ZONENAME
}
nfs4_domain=dynamic
security_policy=NONE
name_service=DNS
{domain_name=$DOMAINNAME
name_server=$DNS
}
timeserver=localhost
root_password=XY.U7yGgfWQlI" > $ZONE_PATH/root/etc/sysidcfg


#
# Attach the zones zonepath.
#
#####################################################

zoneadm -z $ZONENAME attach

echo "Booting $ZONENAME"
if [ $INTERACTIVE == 1 ]
then
        echo "[RETURN to continue] CTRL-C to cancel"
        read
fi

#
# Booting into the new zone.
#
#####################################################

(zoneadm -z $ZONENAME boot &) ; zlogin -C $ZONENAME

---- snap 
-------------------------------------------------------------------------------------------

Perhaps someone finds it useful.;)

If you have any questions/suggestions let me know.

Have fun,

Rudy
-- 
This message posted from opensolaris.org
_______________________________________________
zones-discuss mailing list
zones-discuss@opensolaris.org

Reply via email to