Automatic Zone Installation Part 2
As I promised in my previous entry about zone installs I will now provide you with a script that will simplify those many steps into one simple concise command.
Why would you need to script such a thing? It was not that difficult to do it manually. But when you have a script you can do the same work over and over and you will have the same result. This is especially important for basic infrastructure like a zone. If you are going to use them for all your applications you will be deploying a lot of zones. And you should, they are great :-).
First of all, you can download the script here.
It is very easy to script the zonecfg command. In my script I simply just have this
cat << EOF | zonecfg -z $1
create
set autoboot=true
set zonepath=$ZONEDIR/$1
add net
set physical=$2
set address=$3
end
commit
exit
EOF
This just sets the basic properties. It is very easy to extend to fit your environment.
If you are familiar with Sun Jumpstart technology then you are probably aware of the sysidcfg file. They provide the same thing for zones and it allows you to provide the answers for the questions asked during the first boot of the zone. My sysidcfg file is a very standard looking one:
system_locale=C
terminal=xterm
network_interface=primary {
hostname=$1
}
security_policy=NONE
name_service=NONE
timezone=UTC
root_password=fto/dU8MKwQRI
nfs4_domain=dynamic
If you want to know what kind of values you can give have a look at the sysidcfg(4) man page.
Now when you run the script you can just run it the following way
# ./create_zone.sh testzone rtls0 192.168.127.11
and you will see some output and then the zone will boot. If you want to follow what is happening after the zone is booted just run zlogin
# zlogin -C -e\# testzone
Thats it. Much shorter than stepping through all the manual steps. You need to of course modify the script according to your own needs but it is a good template. There are other more advanced scripts out there if you use google a bit but sometimes simplicity is better.
If you want to read more about zones then the OpenSolaris page about zones is a good start.
Do you need system administration assistance? If you like what you are reading please consider subscribing to the RSS feed. If you have feedback or if you find the article useful please leave a comment below.


Great little script, thanks. But in order to use your defined variable ZONEDIR later in the script, you need to replace the “/zones/” in the sysidcfg area with “/$ZONEDIR/” and also again in the touch command.
Hi Steve,
Nice catch :-). I’ve updated the script. It has never been a problem for me since I always put my zones in /zones.
cheers,
Nickus