Speeding up Solaris zone creation with cloning


One really neat feature that was recently added to Solaris is the ability to clone zones. Cloning allows you to create a new zone from an existing zone, which can reduce provisioning time, and ensure that all zones are created consistently (e.g., all zones that will act as web servers can be cloned from a zone that was setup to act as a web server). If the zone you are cloning from resides on a UFS or VxFS file system, the clone operation will copy all of the files from the source zone to the new zone. If the zone that you are cloning from lives on a ZFS file system, the clone operation will create a writeable ZFS snapshot, and use that as the backing store for the new zone. When zones are cloned with the ZFS method, the new zone is created almost instantaneously (it typically takes .5 seconds), and little to no storage is required to initially provision the zone.

To show you how this works, I created a Linux branded zone named “centostemplate.” The zone centostemplate lives on it’s own ZFS file system, as you can see from the output of the “zoneadm” and “zfs” utilities:

$ /usr/sbin/zoneadm list -vc

ID NAME STATUS PATH BRAND
0 global running / native
- centostemplate installed /app/zones/centostemplate lx

$ zfs list

NAME USED AVAIL REFER MOUNTPOINT
app 3.05G 8.67G 27.5K /app
app/zones 1.05G 8.67G 26.5K /app/zones
app/zones/centostemplate 1.05G 8.67G 1.05G /app/zones/centostemplate

To create a new zone named centos_37_1 from a clone of the zone named centostemplate, the zone cetos_37_1 first needs to be configured in the zone configuration shell:

$ zonecfg -z centos_37_1

centos_37_1: No such zone configured
Use 'create' to begin configuring a new zone.
zonecfg:centos_37_1> create
zonecfg:centos_37_1> set zonepath=/app/zones/centos_37_1
zonecfg:centos_37_1> commit
zonecfg:centos_37_1> exit

Once the new zone is configured the way you want it, the zoneadm utilily can be run with the “-z” option, the name of the new zone, the “clone” command, and the name of the zone you would like use as the source of the clone operation (in the following example, the centostemplate zone is the source for the clone operation):

$ timex zoneadm -z centos_37_1 clone centostemplate

Cloning snapshot app/zones/centostemplate@SUNWzone1
Instead of copying, a ZFS clone has been created for this zone.

real 0.63
user 0.07
sys 0.10

As you can see from the output, it look just over .5 seconds to create a brand spanking new zone! Nice! If I run the zoneadm and zfs utilities again, you can see that a writeable snapshot was created to act as the backing store for the zone named centos_37_1:

$ /usr/sbin/zoneadm list -vc

ID NAME STATUS PATH BRAND
0 global running / native
- centostemplate installed /app/zones/centostemplate lx
- centos_37_1 installed /app/zones/centos_37_1 lx

$ zfs list

NAME USED AVAIL REFER MOUNTPOINT
app 3.05G 8.67G 27.5K /app
app/zones 1.05G 8.67G 27.5K /app/zones
app/zones/centos_37_1 0 8.67G 1.05G /app/zones/centos_37_1
app/zones/centostemplate 1.05G 8.67G 1.05G /app/zones/centostemplate
app/zones/centostemplate@SUNWzone1 87.5K - 1.05G -

This is some amazingly cool stuff, and Sun keeps adding more and more nifty stuff to Solaris!

This article was posted by Matty on 2006-10-19 22:28:00 -0400 -0400