How to create a lot of zones (and delete them afterwards)
By blogfinger on Jan 15, 2008
Sometimes, e.g. in educational contexts, or for testing purposes, you might want to create a number of zones in one step and delete them later. In this entry, I am describing one possible way of doing this. Other tools are already well-known (e.g. zonemgr), but with a different focus.
The basic steps are as follows:
- Create a zone that you want to clone.
- Boot that zone so that the SMF manifests are imported.
- Customize that zone as you like.
- Set some basic parameters in the CUSTOMIZE section of the script.
- Start the script and wait for its completion. The creation of one zone can take about 15 to 30 seconds, depending on the server you are using.
- The IP address and the zone name and zone root path are determined.
- The zone configuration file is created.
- The sysidcfg file is created.
- The zone root path of the source zone is determined
- If that zone root path and the destination root path are both on a ZFS file system, zone cloning is performed using ZFS snapshots.
- Using the zonecfg command and the zone configuration file, the zone is configured.
- Then, the zone is cloned, using the zoneadm command.
- The sysidcfg file is copied to the etc directory of the zone, and the .UNCONFIGURED file is deleted from that directory.
- The zone is then left in the installed state, brought to the ready state, or booted. Bringing it to the ready state will configure the zone's IP interface and reduce the boot time of the zone.
Click here to download the zone cloning script. Another script, delete-cloned-zones, can then be used to delete these zones. It searches the list of zones for a certain pattern, halts and deletes each zone and then destroys each of these zone's zfs file systems. Be sure to test this script carefully!
I'll post a sample zone cloning and deleting session in my next blog entry.