Solaris zone creation in less than 5 seconds with ZFS clones
Solaris 10 update 7 hit the download site earlier this week and I just gave zone cloning a spin. Zone cloning has been out for quite a while, but the new twist is that you can finally use ZFS snapshots/clones as an underlying mechanism for zone creation. With this feature you can make additional zones really quickly and with very little overhead, even for full root zones.
Here is what I did:
create a ZFS file system mounted at /zones
# zfs create -o mountpoint=/zones -o compression=on -o atime=off data/zones
create a zone ‘goldenzone’ that I will use as a target for cloning. If I wanted to add certain software or other setup (like security hardening) to all zones I would do that here.
# zonecfg -z goldenzone
goldenzone: No such zone configured
Use ‘create’ to begin configuring a new zone.
zonecfg:goldenzone> create -b
zonecfg:goldenzone> set zonepath=/zones/goldenzone
zonecfg:goldenzone> exit
# zoneadm -z goldenzone install
Creating list of files to copy from the global zone.
Copying <130143> files to the zone …
# zoneadm -z goldenzone boot (so we get the SMF importing out of the way)
# zlogin -C goldenzone (verify the SMF import finishes and answer sysid questions)
This is also a good time to do any customization steps that you would like done everywhere, such as disabling services, changing root’s shell to /bin/bash, using a custom apache configuration, etc.
# zoneadm -z goldenzone halt
Now we will create a new full-root zone ‘zone1′ that we will clone from goldenzone
# zonecfg -z zone1
zonecfg:zone1> create -b
zonecfg:zone1> set zonepath=/zones/zone1
zonecfg:zone1> add net
zonecfg:zone1:net> set physical=e1000g0
zonecfg:zone1:net> set address=zone1/24
zonecfg:zone1:net> end
zonecfg:zone1:> exit
Now that we have finished the main configuration, lets see how long it takes to make the new zone:
time zoneadm -z zone1 clone goldenzone
Cloning snapshot data/zones/goldenzone@SUNWzone1
Instead of copying, a ZFS clone has been created for this zone.
grep: can’t open /a/etc/dumpadm.conf
real 0m4.088s
user 0m0.439s
sys 0m0.187s
We will also take a look at the space used. The goldenzone took 1.7GB (ZFS compression was on) and we can see that the snapshot & clone used for zone1 took us less than a meg of extra space. Sweet!
NAME USED AVAIL REFER MOUNTPOINT
data/zones 1.70G 263G 42.0K /zones
data/zones/goldenzone 1.70G 263G 1.70G /zones/goldenzone
data/zones/goldenzone@SUNWzone1 405K - 1.70G -
data/zones/zone1 285K 263G 1.70G /zones/zone1