Cloning Solaris 10 Zones Manually

Cloning Solaris 10 Zones Manually

Introduction

As of release build 33, Sun did not yet have an official feature for cloning zones. We developed this technique which has proven to work in production since ~2006.

  1. Source Zone = [sourceZoneName] (10.248.142.23) with server name = foo

  2. Target Zone = [targetZoneName] (10.248.142.26) with server name = bar

Halt the Source Zone

Log into the Source Zone and gracefully shutdown. At this point the zone should be halted. If you want need to forcefully halt a zone,

zoneadm -z [sourceZoneName] halt

Create and Configure the New Zone

See Zone Basics to create a new zone as per this example called [targetZoneName] with IP Address 10.248.142.26.

Warning: Do not start the zone yet.

In this example, creating the zone resulted in the folder mkdir /var/zones/[targetZoneName] with permissions of 700 on directory [targetZoneName].

Manually Clone Over Zone From Source to Target

Single Machine

We use tar as it caries over permissions nicely,

cd /var/zones/[sourceZoneName] tar cvf - ./* |(cd ../[targetZoneName]; tar xvf -)

Hey? How come not - in front of the cvf or xvf? [Dickson or Tin will get from Tony full explanation on the above line.]

cf - means that the file created is stdout, which is then piped into the tar reading from stdin xf - [Garth]

Machine to Machine

To package for sending to another machine.

cd /var/zones tar -cvf [sourceZoneName].tar ./[sourceZoneName]/ {tar up with proper permissions} zip -9 [zipFileName] ./[sourceZoneName].tar {zip up the tar file maximum compression}

There may be a more efficient ways of doing this but they have not been production tested or approved,

tar -cvf - /[sourceZoneName] | gzip - > [sourceZoneName].tar.gz {still to be tested and approved}

To untar to target machine,

mkdir temp mv ./[sourceZoneName].tar ./temp/ cd ./temp tar -xvf ./[sourceZoneName].tar cd ./[sourceZoneName] tar -cvf - ./* |(cd ../[targetZoneName]; tar xvf -) {this is important because just copying will mess up your permissions}

Adjust Special Files

Basically we are looking for all lines containing, [sourceZoneName], duplicating the lines and adjusting to [targetZoneName] with the new ip address.

The following files need to be edited. Continue editing from the master zone. In some cases, when using vi, even as root you will need to use explicit write w!.

  1. /var/zones/[targetZone]/root/etc/hosts

  2. /var/zones/[targetZone]/root/etc/inet/ipnodes

    1. Adjust the host entry that defines the system from 10.248.142.23 [sourceZoneName] to 10.248.142.26 [targetZoneName].

  3. /var/zones/[targetZone]/root/etc/nodename

  4. /etc/zones/index

    1. Find a line similar to, zoneclone:configured:/zfszones/zoneclone:0000003c-ffbf-f825-ffbf-f80001000000

    2. Change the word configured to installed. Often I found it was already changed.

  5. ...

Boot and Confirm

As explained in Zone Basics boot both the source and new target zones while being connected via a console to ensure the systems boot correctly.