Friday, August 10, 2012

Clone Solaris 11 Zone

I have come to a point where creating a Solaris 11 zone from scratch is no longer time efficient. This is a note about the method I employed to quickly clone a zone (either new zone or an existing zone).

If you have not created a zone before, here is a summary of the steps.

1) Login as root (or su - to root)

Create a zone ("stem" zone),

2) zonecfg -z originalzone "create; set zonepath=/zones/originalzone;set autoboot=true;exit"

if you already have an existing zone with other applications installed, and you just want to clone it lock, stock and barrel, do this

2.1) zonecfg -z clonedzone01 "create -t originalzone; set zonepath=/zones/clonedzone01;set autoboot=true;exit"

Before installing the zone, make sure you have the IPS repository configured. I use the "sol-11-1111-repo-full.iso", mount it and set the publisher to this repository.

3) pkg set-publisher -G "*" -g file:///media/SOL11REPO_FULL/repo/ solaris
4) pkg rebuild-index

Install the zone

4) zoneadm -z  originalzone install

Boot up the zone and login to the console at the same time

5) zoneadm -z  originalzone  boot; zlogin -C originalzone

If this is a new zone, once the zone booted up, and finished configuring the services, hit F9 to exit.

Run (or re-run if you have just finished configuring the a new zone) "sysconfig create-profile -o /tmp/sc_profile.xml". As you are now in the local zone, make sure you have access to the sc_profile.xml from the global zone and copy it into the global zone before you shutdown the originalzone. /tmp in the local zone maps to /zone/originalzone/root/tmp in the global zone.

Note that if you run the sysconfig utility in a fully configured zone, you will be prohibited from reusing the same user id and the computer name. I just enter a placeholder USERID for user name and COMPNAME for computer name fields. I have also used a bogus IP address during the configuration. Once the sc_profile.xml is generated, just repalce the tokens with valid values before feeding it to the zoneadm to clone the zone.

6) Shutdown the zone: zoneadm -z  originalzone halt

6.5) Replace the placeholders in the sc_profile.xml with meaningful values

# sed -e 's/USERNAME/admin/g' sc_profile.xml > sc_profile.xml.tmp && mv sc_profile.xml.tmp sc_profile.xml
# sed -e 's/COMPNAME/clonedzone/g' sc_profile.xml > sc_profile.xml.tmp && mv sc_profile.xml.tmp sc_profile.xml
# sed -e 's/55\.55\.55\.55/192\.168\.56\.62/g' sc_profile.xml > sc_profile.xml.tmp && mv sc_profile.xml.tmp sc_profile.xml

7) Clone the zone (the content of the zone).

# zoneadm -z clonedzone clone -c ~/sc_profile.xml originalzone

Progress being logged to /var/log/zones/zoneadm.20120811T004223Z.clonedzone.clone
Log saved in non-global zone as /zones/clonedzone/root/var/log/zones/zoneadm.20120811T004223Z. clonedzone.clone

If you want to find out what was done by the zoneadm util, have a look at the log file, you should notice that the tool actually performed a cloning of the originalzone zfs fs.

This also means that the size of the cloned zone starts with zero, as you make changes to the clonedzone, the size of the zfs fs will grow. Check this out

# zfs list | grep [original,cloned]zone$
NAME                                                       USED  AVAIL  REFER  MOUNTPOINT
rpool/zones/originalzone                              393M  93.4G    33K  /zones/originalzone
rpool/zones/clonedzone                               37.0M  93.4G    35K  /zones/clonedzone

Now boot the clonedzone and you will find that you do not need to perform the configuration and all local users, apps you created in the originalzone are still there.

Happy cloning!


  1. Is there a way we can do cloning on 2 different systems.

  2. Thanks a lot for all your valuable article! We are really happy about the your...
    hadoop Training in Chennai

  3. This post is really nice and informative. The explanation given is really comprehensive and informative..
    ios Training in Chennai

  4. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your.
    Digital Marketing Company in India
    Seo Company in India

  5. These ways are very simple and very much useful, as a beginner level these helped me a lot thanks fore sharing these kinds of useful and knowledgeable information.
    Android App Development Company

  6. Nice it seems to be good post... It will get readers engagement on the article since readers engagement plays an vital role in every blog.i am expecting more updated posts from your hands.
    iOS App Development Company
    iOS App Development Company

  7. Pretty article! I found some useful information in your blog, it was awesome to read, thanks for sharing this great content to my vision, keep sharing..
    Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text
    Mobile Marketing Services
    mobile marketing companies
    Sms API