In my presentation at Oracle Openworld, I showed a demo of how to easily clone a zone to make a copy for development or testing purposes. These were the steps, given that the zone oow01 was already set up and running.
zonecfg -z oow01 export > oow43.cfg -- dump the existing config to a file # edit the file oow43 for a new ip address and a new zonepath zonecfg -z oow43 -f oow43.cfg -- import the new config zoneadm -z oow01 halt -- this is neccessary for the 'clone' command zoneadm -z oow43 clone oow01 -- this will take care of the rest
One of the questions I received from the audience after the presentation was: “Is it possible to clone a running zone?”. Sure, this is possible, but unfortunately not with the zoneadm command, so you will have to do some manual work. I did not have time to do it right there but promised to follow-up on my blog. But first a word of caution: Though I have done this with running zones multiple times with success, this does not mean it is guaranteed to work. You freeze the ZFS filesystem with a running zone midflight which is similar to turning off the power off an on and hoping that your computer works fine afterwards. From my experience, it does work fine almost all the time (and Oracle itself should be protected by instance recovery), just don’t count on it or blame me if the clone won’t start up or behave unexpectedly.
So basically, what ‘zoneadm clone’ will do for you is create a ZFS clone from the source zone’s filesystem and then modify a text file while ignoring a ‘DO NOT EDIT THIS FILE’-hint.
# the first two steps are exactly the same as above zonecfg -z oow01 export > oow43.cfg -- dump the existing config to a file # edit the file oow43 for a new ip address and a new zonepath zonecfg -z oow43 -f oow43.cfg -- import the new config zfs snapshot rpool/zones/oow42@clone_oow43 -- snapshot running zone zfs clone rpool/zones/oow42@clone_oow43 rpool/zones/oow43 -- make a clone # now, edit the file /etc/zones/index # change the status of your zone from configured to installed # and set a unique id
When I choose a new id for the zone, I just copy an existing one and modify a few digits. I don’t know if this is the ‘right’ way to do it but it works for me. Now, you can boot up this newly cloned zone and that is it. The hostname inside the zone is still the same as the original, but I usually don’t care or simply correct this.