AZSAGE and Sun Microsystems is providing you this Solaris Zones script as a complimentary utility. Please use this script at your own risk and test on a QA environment first.'
#!/bin/ksh # # CHANGE HISTORY # 11/04/05: changed interface from command line w/ operands to edit-the-script # with parameters. # 04/13/08: New and improved, revamped for zone cloning # 04/13/08: Change sysidcfg section to "here" document # # # Edit the variables below with config parameters and run. # Note: zone to be used as base for cloning must be halted... # zone_to_be_cloned=myweb2 # Base Zone used for cloning. nzones=3 # number of zones to clone prefix=azsage # zone prefix name postfix_zone_num=1 # zone number to start with that will be appended to $prefix zonepath=/zones # zonepath device=e1000g0 # Interface to use netip=192.168.3 # network address for zones (to be combined with "clone_ip") clone_ip=1 # Host IP Address to Start with for these cloned zones netmask=/24 # Bits for netmask zone_root_pw="39rKBRgUaipiA" # zone root password if [[ ! -d $zonepath ]]; then echo "$zonepath is not a directory" exit 1 fi # Create Zone Configuration file from template, "zonecfg" it and commit it. i=1 while [ $i -le $nzones ]; do ZONENAME=$prefix`expr $postfix_zone_num - 1 + $i` zoneadm -z $ZONENAME list > /dev/null 2>&1 if [ $? != 0 ]; then echo configuring $ZONENAME F=/var/tmp/$ZONENAME.config rm -f $F echo "create -t $zone_to_be_cloned" > $F echo "set zonepath=$zonepath/$ZONENAME" >> $F CLONE_IP=`expr $clone_ip + $i - 1` CLONE_FULL_IP=$netip.$CLONE_IP >> $F # get zone to be cloned's IP to change... TEMPLATE_IP=`zonecfg -z myweb2 info | grep address | sed 's/address://'` echo "select net address=$TEMPLATE_IP ; set address=$CLONE_FULL_IP${netmask} ; end" >> $F echo "set cpu-shares=10" >> $F echo "verify" >> $F echo "commit" >> $F echo "exit" >> $F zonecfg -z $ZONENAME -f /var/tmp/$ZONENAME.config 2>&1 | sed 's/^/ /g' else echo "skipping $ZONENAME, already configured" fi i=`expr $i + 1` done # Perform the "zoneadm zone_name clone" i=1 while [ $i -le $nzones ]; do ZONENAME=$prefix`expr $postfix_zone_num - 1 + $i` if [ `zoneadm -z $ZONENAME list -p | \ cut -d':' -f 3` != "configured" ]; then echo "skipping $ZONENAME, already installed" else echo cloning $zone_to_be_cloned to $ZONENAME mkdir -pm 0700 $zonepath/$ZONENAME chmod 700 $zonepath/$ZONENAME zoneadm -z $ZONENAME clone $zone_to_be_cloned > /dev/null 2>&1 & fi i=`expr $i + 1` wait done # Create the sysidcfg file and place it in zone_name/root/etc i=1 while [ $i -le $nzones ]; do ZONENAME=$prefix`expr $postfix_zone_num - 1 + $i` cat > /zones/$ZONENAME/root/etc/sysidcfg <$zonepath/$ZONENAME/root/etc/default/login # Uncomment to Allow root ssh # mv -f $zonepath/$ZONENAME/root/etc/ssh/sshd_config $zonepath/$ZONENAME/root/etc/ssh/sshd_config.ORIG #sed -e 's/PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config > $zonepath/$ZONENAME/root/etc/ssh/sshd_config i=`expr $i + 1` done # Boot the zones... i=1 while [ $i -le $nzones ]; do ZONENAME=$prefix`expr $postfix_zone_num - 1 + $i` echo booting $ZONENAME zoneadm -z $ZONENAME boot zoneadm -z $ZONENAME list -v i=`expr $i + 1` wait done # Some post-boot zone commands i=1 while [ $i -le $nzones ]; do ZONENAME=$prefix`expr $postfix_zone_num - 1 + $i` zlogin $ZONENAME svcadm disable sendmail zlogin $ZONENAME usermod -s /usr/bin/bash root i=`expr $i + 1` wait done