Skip to content

Instantly share code, notes, and snippets.

/add

Created December 23, 2012 17:57
Show Gist options
  • Save anonymous/4364861 to your computer and use it in GitHub Desktop.
Save anonymous/4364861 to your computer and use it in GitHub Desktop.
Scripts Cloning Solaris 11 Zones. To be installed under /opt/custom. Assume `dispadm -d FSS; reboot` done, `zonecfg -z global set cpu-shares=1`, and `zonecfg -z origin "create; set zonepath=/zones/origin"`. Run /opt/custom/reset once, then /opt/custom/add for each new zone. Note that /opt/custom/reset destroys all the zones from 10.10.10 through…
#!/usr/xpg4/bin/sh
set -Cex
export PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin
MIN=10
MAX=99
POOL=busy
ROOT=/opt/custom
. $ROOT/config
cd $ROOT
mkdir -p vacant
for p in $(ls vacant); do
test -d vacant/$p
if echo $$ >vacant/$p/lock; then
POOL=$p
trap 'rm -f vacant/$POOL/lock' INT TERM EXIT
break
fi
done
test "$POOL" != busy
test "$POOL" -ge "$MIN"
test "$POOL" -le "$MAX"
read ZONE <vacant/$POOL/next
test "$ZONE" -ge "$MIN"
test "$ZONE" -le "$MAX"
ZONENAME=$NETWORK.$POOL.$ZONE
ZONEPATH=/zones/clones/$NETWORK/$POOL/$ZONE
zoneadm list -ip | grep -F :origin:installed:/zones/origin:
! zoneadm list -cp | grep -F :$ZONENAME:
zonecfg -z $ZONENAME <<-COMMIT
create
set zonepath=$ZONEPATH
select anet linkname=net0
set defrouter=$DEFROUTER
set allowed-address=10.$ZONENAME
end
set cpu-shares=1
COMMIT
zoneadm list -cp | grep -F :$ZONENAME:configured:$ZONEPATH:
zoneadm -z $ZONENAME clone origin
zoneadm list -ip | grep -F :$ZONENAME:installed:$ZONEPATH:
NEXT=$(($ZONE + 1))
if [ "$NEXT" -le "$MAX" ]; then
echo $NEXT >|vacant/$POOL/next
rm -f vacant/$POOL/lock
else
mkdir -p full
test ! -e full/$POOL
mv vacant/$POOL full
fi
trap - INT TERM EXIT
DEFROUTER=10.0.2.2
NETWORK=17
#!/usr/xpg4/bin/sh
set -Cex
export PATH=/usr/xpg6/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin
FORMAT='^[1-9][0-9]\.[1-9][0-9]\.[1-9][0-9]$'
MIN=10
MAX=99
ROOT=/opt/custom
. $ROOT/config
cd $ROOT
for z in $(zoneadm list -c | grep $FORMAT); do
if zoneadm list -p | grep -F :$z:running:; then
zoneadm -z $z halt
fi
zoneadm list -ip | grep -F :$z:installed:
zoneadm -z $z uninstall -F
zoneadm list -cp | grep -F :$z:configured:
zonecfg -z $z delete -F
! zoneadm list -cp | grep -F :$z:
done
rm -fr vacant full
p=$MIN
while [ "$p" -le "$MAX" ]; do
mkdir -p full/$p
echo $MIN >full/$p/next
p=$(($p + 1))
done
mv full vacant
@codedot
Copy link

codedot commented Dec 23, 2012

Before adding clones, install origin by typing zoneadm -z origin install.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment