Cloning Solaris Container
There are two way to create a new container: create one from scratch, which takes a little while or you can clone an existing container. Cloning is quite faster than the actual creation so it is handy to have a “gold” master container which is used for cloning. Another reason for having a “gold” master container is the fact that the container from which you are making a clone has to be halted during cloning. I did this on Solaris 10 8/07 release. Cloning consists of the following:
- Export configuration of an existing container or create a new configuration from scratch
- Customize the exported configuration for the new container
- Import the new container configuration
- Clone the “gold” master container
- Configure the new container
First you need configuration for the new container. You can either make one from scratch or export one from existing container and customize it. The following command will export the configuration from “gold” master container and save it into /tmp/mx1.cfg file:
bash-3.00# zonecfg -z gold export -f /tmp/mx1.cfg
Now you can edit the configuration. Word of caution, importing seems to be a little flaky. For example, if an existing container has bootargs variable set, you will need to put quotes around them in the config file. So, if my bootargs are set to -m verbose, the string will have to be enclosed in "”. Otherwise the new container configuration will not be imported properly.
Once you have the configuration ready you can import it:
bash-3.00# zonecfg -z mx1 -f /tmp/mx1.cfg
Now you can perform actual clone operation:
bash-3.00# zoneadm -z mx1 clone -m copy gold
Cloning zonepath /export/home/zones/gold...
This should not take very long. Once the operation is done you can see that the new container has been installed:
bash-3.00# zoneadm list -cv
ID NAME STATUS PATH BRAND IP
0 global running / native shared
- mx1 installed /export/home/zones/mx1 native shared
- gold installed /export/home/zones/gold native shared
At this point you can boot the new container. You will be taken through initial configuration of the container. This initial container configuration can be pain if you are rolling out a lot of containers. You can simplify the process by creating a sysidcfg file and putting it into /etc directory of the container before performing the first boot.
In my case I would put the following sysidcfg into /export/home/zones/mx1/root/etc:
system_locale=C
terminal=vt100
network_interface=primary {
hostname=mx1
}
security_policy=NONE
name_service=DNS {
domain_name=example.com
name_server=192.168.1.1
search=example.com
}
nfs4_domain=dynamic
timezone=US/Central
root_password=n2GSHfh
The nice thing about cloning is the fact that it’s fairly quick. So if you hose up a container, you can simply run
bash-3.00# zoneadm -z mx1 uninstall
Are you sure you want to uninstall zone mx1 (y/[n])? y
followed by
bash-3.00# zonecfg -z mx1 delete
Are you sure you want to delete zone mx1 (y/[n])? y
and start all over again.