Cloning Solaris 10 Zones within the Same Machine
Introduction
I wrote these instructions back in Feb 2008 and just dumped this from my old Google Sites wiki.
Solaris 10 provides support for cloning zones from build 33 onwards.
For previous builds you have hack it taking a Manual Cloning approach.
Here is the sample scenario,
Source Zone = [sourceZoneName] (192.168.0.10) with server name = kryptonw1
Target Zone = [targetZoneName] (192.168.0.12) with server name = deathstarw1
Halt the Source Zone
SSH into the source zone and properly shutdown any services and then gracefully shutdown the machine. At this point the zone should be halted.
Log into the global zone and verify the status of the zone (the status should be "installed" and not "running") by using
su - root
zoneadm list -cvIf you need to forcefully halt a zone, from the global zone,
zoneadm -z [sourceZoneName] halt
Clone the Zone (All on the Same Machine)
Take a look at the details of the zone you want to clone,
cat /etc/zones/[sourceZone].xml
...[some xml header info]...
<zone name="template" zonepath="/var/zones/template" autoboot="false">
<inherited-pkg-dir directory="/lib"/>
<inherited-pkg-dir directory="/platform"/>
<inherited-pkg-dir directory="/sbin"/>
<inherited-pkg-dir directory="/usr"/>
<network address="192.168.0.11" physical="eri0"/>
</zone>Note the ip address, zone name and physical network card.
Generally for the new zone you will only want a different zone name and ip address. This can be accomplished as follow,
Take the configuration details from the original zone
Passes to sed (or edit manually) to replace the zone name and ip address
Stores the result in newzone.cfg
Here is a sample line where the newzone.cfg will have a new zone name and the ip address (from .11 to .15).
cd /var/tmp
zonecfg -z [sourceZoneName] export|sed -e 's/[sourceZoneName]/[targetZoneName]/'|sed -e 's/192.168.0.11/192.168.0.15/' > [targetZoneName].cfgFor new machines you might want to make sure you are using the right physical network card using ifconfig -a
Note you can also use the zone tools to make these same changes as outlined at Zone-Basics, Change a Zones IP Address and Interface, but this is faster and helps you understand that it’s all just in a configuration file.
Two more lines and we are done,
cd /var/tmp
zonecfg -z [targetZoneName] -f ./newzone.cfg {loads the zone configuration from file}
zoneadm -z [targetZoneName] clone [sourceZoneName] {clones the zone}
As of March 14th after updating to the new zone package, we noticed this error message which we think we can ignore. Dickson, Harry and Tin are confirming. Finally, you can verify that yoru zone was created.
zoneadm list -cv {lists all the available zones}If there are special zone requirements that are not in the template you can make changes in the newzone.cfg file or use the zone administration tool just before actually running the clone command. Keep in mind though that before the clone the file systems such as inherited directories should be the same.
Boot and Configure
As explained in Zone Basics - Boot and Verify the Zone boot both the source and new target zones while being connected via a console to ensure the systems boot correctly.
Upon the initial boot of [sourceZoneName] you will be given the opportunity to change the following. Here is what I generally use,
Whate type of terminal are you using? 2
Host name: [targetZoneName]
Kerberos Security: No
Name Service: Name
The remaining questions are straightforward.