Sun Microsystems 10 User Manual

Page of 121
Version 3.1-en
  Solaris 10 Container Guide - 3.1   5. Cookbooks 
Effective: 30/11/2009
5.3.8. Duplicating zones with zoneadm detach/attach and zfs clone
[ug] First, the zone "test" is moved to its own ZFS file system. The file system must only be available 
from root otherwise an error message will appear.
global# zfs create container/ztest 
global# ls -ld /container/ztest 
drwxr-xr-x   2 root     root           2 Feb 19 16:00 /container/ztest 
global# chmod og-rwx /container/ztest 
global# ls -ld /container/ztest 
drwx------   2 root     root           2 Feb 19 16:00 /container/ztest 
Next, the zone is moved to the separate ZFS file system. The configuration is adjusted automatically; 
to do so, it must of course be shut down.
global# zoneadm -z test move /container/ztest 
Moving across file-systems; copying zonepath /container/test... 
Cleaning up zonepath /container/test... 
The zone is detached, and the current status of the file system is recorded with zfs snapshot as a 
read-only version (the gold standard). The original zone can then be activated again.
global# zoneadm -z test detach 
global# zfs snapshot container/ztest@gold 
global# zoneadm -z test attach 
global# zoneadm -z test boot 
A copy of the zone is created by generating a writable version of the zone file system with  zfs 
clone.
global# zfs clone container/ztest@gold container/ztest2 
global# zfs list 
NAME                   USED  AVAIL  REFER  MOUNTPOINT 
container              181M   803M  88.7M  /container 
container/ztest       91.8M   803M  88.7M  /container/ztest 
container/ztest@gold  3.07M      -  90.4M  - 
container/ztest2          0   803M  90.4M  /container/ztest2 
In  order  to   activate  the  zone  copy,   it   must   be  configured,  and  the  zone  path  must   be  adjusted. 
Subsequently, it is sufficient to use zoneadm attach and the zone can be started up.
global# zonecfg -z test export | zonecfg -z test2 
test2: No such zone configured 
Use 'create' to begin configuring a new zone. 
global# zonecfg -z test2 set zonepath=/container/ztest2 
global# zoneadm -z test2 attach  
global# zoneadm -z test2 boot
In the zone, the name of the OS instance is still the same of course since the file /etc/nodename 
has not yet been changed. Furthermore, it makes sense to adapt the network addresses as well, just 
like the zonepath adaptation performed here.
Additional zones with the same OS content can now be created very quick by repeating the steps 
zfs clone / zonecfg / zoneadm attach.
In   the   same   way,   zones   can   also   be   moved   to   other   systems   with  zoneadm   detach   / 
attach
. A prerequisite is that the same package and patch status is present on the target system. 
By using the option  zoneadm   attach   -u,  a zone can be moved to a system with a newer 
status, however, downgrading of patches must not occur.
Since   Solaris   10   5/09,  zfs   clone  is   used   automatically   with   the   command  
zoneadm -z zone clone if the zone is located on a ZFS file system. This facilitates the quick 
creation of zones even more.
101