Build zone creation script
#!/bin/bash
TYPE_ZONE=$1
IP=$2
SER=$3
cat > ${HOME}/${TYPE_ZONE}.cmd <<EOT
create
set zonename=${TYPE_ZONE}
set zonepath=/zones/${TYPE_ZONE}
set autoboot=false
set ip-type=exclusive
add net
set physical=iz${SER}
set global-nic=vsw0
add property (name=ip,value="${IP}.${SER}")
add property (name=gateway,value="${IP}.254")
add property (name=netmask,value="255.255.255.0")
add property (name=primary,value="true")
end
add attr
set name=resolvers
set type=string
set value=8.8.8.8
end
add fs
set dir="/export/home/admin"
set special="/export/home/admin"
set type="lofs"
end
add fs
set dir="/export/builds"
set special="/export/builds"
set type="lofs"
end
add fs
set dir="/data/repo"
set special="/data/repo"
set type="lofs"
end
verify
commit
exit
EOT
zonecfg -z ${TYPE_ZONE} -f ${HOME}/${TYPE_ZONE}.cmd 2>&1 | /usr/bin/tee -a /var/tmp/${TYPE_ZONE}-bts.log
zoneadm -z ${TYPE_ZONE} install 2>&1 | /usr/bin/tee -a /var/tmp/${TYPE_ZONE}-bts.log
zoneadm -z ${TYPE_ZONE} boot 2>&1 | /usr/bin/tee -a /var/tmp/${TYPE_ZONE}-bts.log
res=$(grep -e 'WARNING:' -e 'warning:' -e 'W:' -e 'error:' -e 'E:' -e 'cannot' /var/tmp/${TYPE_ZONE}-bts.log | sort -u)
if [[ "$res" == "" ]]; then
echo " =========== Zone ${TYPE_ZONE} is successfully created and ready to use ============="
else
echo " =========== Zone ${TYPE_ZONE} creation log ============="
echo "$res"
echo "$res" | sed '/W: --force-yes is deprecated/d; /\/man\//d'
if [[ "$res" != "" ]]; then
echo " ========================================================"
echo "Please stop and report about zone bootstrap errors!"
fi
fi