Automatic Zone Installation Part 1
In this article I will tell you about how to create a script to install a Solaris zone with one simple command. Zones is this really amazing features of Solaris 10. It is basically a virtual instance of Solaris running on top of the same kernel. You can have as many zones as you like on a system (as long as you have memory and diskspace). The zone will have its own IP address and own configuration files. As far as a normal user is concerned it really looks like a standard Solaris install. Once you learned to use zones you will start to find places for them everywhere.
The standard tools you use to install a zone is zonecfg(1M) and zoneadm(1M). At the time you are installing a zone the only question you really have to think about is if you want to make a full or a sparse zone. A full zone has a full set of binaries and configuration files whereas a sparse zone shares most of the binaries with the global zone (the initial install of Solaris is called the global zone). A sparse zone saves a lot of diskspace and is much faster to install but some third-party applications may not run since they won’thave write access to /usr.
To create a basic sparse zone you first need to invoke zonecfg. You do that by running the following command as root:
# zonecfg -z testzone
testzone: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg will respond with a message that no such zone exists. You then need to issue the create statement and then we will set the zonepath (the directory where the zone will be installed) as well as make it boot when the system starts up.
zonecfg:testzone> create
zonecfg:testzone> set zonepath=/zones/testzone
zonecfg:testzone> set autoboot=true
I usually have a separate hierarchy for all zones, under /zones. This is just my convention and it makes it easier to find them.
The next thing we need to setup is a network interface for this zone.
zonecfg:testzone> add net
zonecfg:testzone:net> set physical=rtls0
zonecfg:testzone:net> set address=192.168.127.9
zonecfg:testzone:net> end
I bind it to my physical interface rtls0 (you can find the name of your interfaces by doing a ifconfig -a) and then I set the address for this zone to 192.168.127.9. I’m now ready to save this configuration and move on to the next step.
zonecfg:testzone> commit
zonecfg:testzone> exit
This saves the zone setup. You can find the files in /etc/zones/testzone.xml.
Before we can install this zone you need to create the zone path.
# make /zones/testzone
# chown root:root /zones/testzone
# chmod 0700 /zones/testzone
The zone path needs to be owned by root and may not be readable or writable by anyone else. This is of course a safety precaution.
To install the zone we need to issue a zoneadm command
# zoneadm -z testzone install
Preparing to install zone
Creating list of files to copy from the global zone.
Copying <25397> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <1063> packages on the zone.
Initialized <1063> packages on zone.
Zone
The file
The exact package count may vary. I have quite a lot of packages installed on my server and it takes a bit longer. Once the zone is installed we can start it. Time to visit our friend zoneadm again
# zoneadm -z testzone boot
#
This returns the command prompt almost directly and everything looks fine.If you query zoneadm again
# zoneadm list -vc
ID NAME STATUS PATH
0 global running /
1 testzone running /zones/testzone
As you can see you now have two running zones, the global one which is the physical machine and our newly installed zone. Unfortunately it doesn’t end here. We need to provide the zone with some additional information. To be able to give this information we need to login on the zones console. We do this with the zlogin(1M) command
# zlogin -e\# -C testzone
The -e option sets the # character as the escape character. To get out of console mode you simply type #. The standard sequence is ~.
You may have to press Enter to get some output on the screen. The zone will require you to answer the following questions.
- What type of terminal are you using. X Terminal Emulator is always a good choice.
- Hostname. The default testzone is good. Press Escape-2 to continue.
- Kerberos Security. Select No and press Escape-2 to continue.
- Name Service. Select None and press Escape-2 to continue.
- Country and Region. Select you own and Press Escape-2 to continue.
- Root password. Set a root password for the zone and press Escape-2 to continue.
- NFS Version 4 question. Select No and press Enter.
The zone will then reboot and a few seconds later you will be presented with a “testzone console login:” prompt. You can now login as root and with the root password you provided. Once you want to disconnect from the session you press #..
As you can see there are a lot of steps when you install a zone. In Part 2 I will show you a script where you should be able to issue a command like this
# ./createzone testzone rtls0 192.168.127.9
and then it will setup everything for you and boot the zone. But to be able to understand the script you need to understand the manual steps.
In the meantime I recommend that you read the man pages for zonecfg(1M), zoneadm(1M) and zlogin(1M).
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.


[...] AspiringSysadmin.com How to build an infrastructure based on UNIX « Automatic Zone Installation Part 1 [...]
[...] last two entries has been about automatic zone installation, part 1 and part 2. With the provided script you can create as many zones as your platform can allow. But [...]
[...] take your time and read my other posts about zones, Automatic Zone Installation Part 1 and Part 2. If you like what you are reading please consider subscribing to the RSS feed. If you [...]
[...] it also won’t affect the other. This feature is only available in E2900 and upwards. 2. Zones This feature was introduced with Solaris 10 and it allows you to run multiple instances of the [...]
87vazc9rsk8o7wed