« Simply Refreshing | Main | Niagara II, anyone?? »

20051207 Wednesday December 07, 2005

Zone creation with ZFS in 10 seconds (or less)

It's me. The zone guy. I've just cheated, and I don't feel guilty. I can create and boot a zone in roughly 10 seconds (or less). Yes, only 10 seconds (or less). First, the background.

I'm a bit low on disk space, so I purchased a 40GB USB drive to install zones on. In particular I want to install JES in a zone, and in different zones I want to be able to have different JES configurations. The basic idea is to leverage zfs snapshots and clones in zone "creation" to completely avoid the "zoneadm -z zonename install" step.

The first step was to use Artem's blog to mount my USB drive under zfs. Artem, great blog entry. I only have one drive, so I don't get the fancy mirroring and striping. Well, not unless I want to follow Ben's lead, but that is outside the scope of what I want to do (for now).

Now that the USB drive under zfs control (mounted to /zones), the second step was to create a whole zone. Here is my zone template:



create -b set zonepath=/zones/jes set autoboot=false add net set address=192.168.200.2 set physical=e1000g0 end verify commit exit


And the zone creation:


# zonecfg -z jes -f jes.template


After creating the zone (which takes a while on the USB drive), I was ready to go.

The third step was to create a clean/unmodified zfs snapshot of the zone before booting it.

# zfs snapshot usbpool/zones@clean


Note, after this I went ahead and installed JES in the zone.

Next, I utilized the "clone" feature of zfs. A clone allowed me to essentially create a read-write snapshot. Just like a snapshot, it's copy-on-write:

# zfs clone usbpool/zones@clean usbpool/jesclone
## I decided to change the mountpoint of the zone ...
#  zfs set mountpoint=/zones2 usbpool/jesclone

The next step is to create another zone using the same zone template as above. Note that the only two things I changed were the IP address and the zonepath to the newly mounted /zones2/jes:

# zonecfg -z jes2 -f zone2.template


OK, now comes a complete hack. What I do here may break in future releases of Solaris because I am completely avoiding the solaris CLI. Edit /etc/zones/index, and change the state of jes2 from "configured" to "installed". Yeah, yeah, whip me with a USB mouse cord (although I prefer wireless mouse).

Last, but not least boot your new zone. Voila! OK, how do we do this in 10 seconds or less? Script it. For full disclosure, I not only cheated (per above), but I also lied. I haven't created the script. Left as an exercise to the reader. If you get to it before I do, let me know :) But I have a gut feel the zone creation would actually take (much) less than 10 seconds.

I haven't sat back and thought much about the implications of inheriting a zone from a snapshot. My gut feel is that this is a bad idea in production (major hacks aside). This is completely unsupported, of course. But you have to admit this is pretty neat. If you can think of a way to simplify this, clean it up, or improve the hackish nature, please comment.

(2005-12-07 07:23:31.0) Permalink Comments [1]

Trackback URL: http://blogs.sun.com/jclingan/entry/zone_creation_with_zfs_in
Comments:

Nice hack, I wondered when someone was going to do it.

One thing you can do, is enable compression on the ZFS filesystem. Not only will it use less space ( down to 48MB from 90MB) on my tests. It should be faster because of the decreased IO.

Posted by James Dickens on December 07, 2005 at 09:33 AM PST #

Post a Comment:

Name:
E-Mail:
URL:

Your Comment:

HTML Syntax: NOT allowed