Creating (and deleting) a lot of zones

As promised, here's a sample zone cloning session using the zone-clone and delete-cloned-zones script as described in my previous blog. I used a 400 MHz UltraSPARC-IIi 512 MB Ultra 5 with Solaris Nevada build 80.

Please don't forget to download and use zonemgr for general purpose zone handling. The zone-clone script described here might be used for creating a lot of clones in one step, or you might just use some of the algorithms for automatically setting parameters in scripts that are calling zonemgr.

This is a list of the zones before the script was started:

# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   - source-zone      installed  /p1/source-zone                native   shared

Then, I started the script. It displays some important data for verification if all the parameters are set appropriately:

  • The status of the retrieval of the password for the root user of the new zones (from the global zone's /etc/shadow file entry for the user specified as parameter USER_FOR_ROOT_PASSWD)
  • The status of the source zone (the zone that is to be cloned)
  • The contents of the zone config file for the first zone
  • The contents of the sysidcfg file for the first zone
  • The highest IP address

# time ./zone-clone 10
Successfully retrieved password for the root user, from /etc/shadow entry for
user adm.
Check:
------
Source zone:
   - source-zone      installed  /p1/source-zone                native   shared
/p1/source-zone
------
Content of first zone config file:
create
set zonepath=/p1/scotty-z-01
add net
set address=192.162.0.5/19
set physical=hme0
end
verify
commit
exit
------
Content of first sysidcfg file:
system_locale=en_US.ISO8859-15
timezone=Europe/Berlin
terminal=xterms
keyboard=German
security_policy=NONE
root_password=Zfcnvzy8TtKVY
timeserver=localhost
name_service=none
network_interface=primary {hostname=scotty-z-01
   ip_address=192.162.0.5
   netmask=255.255.224.0
   protocol_ipv6=yes
   default_route=192.162.0.1
}
nfs4_domain=dynamic
------

Highest IP address will be 192.162.0.14, for zone scotty-z-10 .

Press RETURN to start creating 10 zones.

After pressing RETURN, all zones are created:

scotty-z-01 with zonepath=/p1/scotty-z-01 and ip addr=192.162.0.5 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:36:30 2008
sys-unconfig completed Tue Jan 15 18:36:31 2008
... done.
scotty-z-02 with zonepath=/p1/scotty-z-02 and ip addr=192.162.0.6 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:36:48 2008
sys-unconfig completed Tue Jan 15 18:36:49 2008
... done.

(screen output omitted)

scotty-z-08 with zonepath=/p1/scotty-z-08 and ip addr=192.162.0.12 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:38:28 2008
sys-unconfig completed Tue Jan 15 18:38:29 2008
... done.
scotty-z-09 with zonepath=/p1/scotty-z-09 and ip addr=192.162.0.13 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:38:46 2008
sys-unconfig completed Tue Jan 15 18:38:46 2008
... done.
scotty-z-10 with zonepath=/p1/scotty-z-10 and ip addr=192.162.0.14 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:39:03 2008
sys-unconfig completed Tue Jan 15 18:39:03 2008
... done.

real    3m22.44s
user    2m6.01s
sys     0m19.57s
That's about 20 seconds for each zone.

The zfs list looks as follows:

# zfs list
NAME                       USED  AVAIL  REFER  MOUNTPOINT
p1                         670M  15.5G  16.5K  /p1
p1/scotty-z-01             134K  15.5G   664M  /p1/scotty-z-01
p1/scotty-z-02             134K  15.5G   664M  /p1/scotty-z-02
p1/scotty-z-03             134K  15.5G   664M  /p1/scotty-z-03
p1/scotty-z-04             134K  15.5G   664M  /p1/scotty-z-04
p1/scotty-z-05             134K  15.5G   664M  /p1/scotty-z-05
p1/scotty-z-06             134K  15.5G   664M  /p1/scotty-z-06
p1/scotty-z-07             135K  15.5G   664M  /p1/scotty-z-07
p1/scotty-z-08             134K  15.5G   664M  /p1/scotty-z-08
p1/scotty-z-09             134K  15.5G   664M  /p1/scotty-z-09
p1/scotty-z-10             134K  15.5G   664M  /p1/scotty-z-10
p1/source-zone             668M  15.5G   667M  /p1/source-zone
p1/source-zone@SUNWzone1  1.41M      -   664M  -

And the list of zones is:

# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   2 scotty-z-01      ready      /p1/scotty-z-01                native   shared
   4 scotty-z-02      ready      /p1/scotty-z-02                native   shared
   6 scotty-z-03      ready      /p1/scotty-z-03                native   shared
   8 scotty-z-04      ready      /p1/scotty-z-04                native   shared
  10 scotty-z-05      ready      /p1/scotty-z-05                native   shared
  12 scotty-z-06      ready      /p1/scotty-z-06                native   shared
  14 scotty-z-07      ready      /p1/scotty-z-07                native   shared
  16 scotty-z-08      ready      /p1/scotty-z-08                native   shared
  18 scotty-z-09      ready      /p1/scotty-z-09                native   shared
  20 scotty-z-10      ready      /p1/scotty-z-10                native   shared
   - source-zone      installed  /p1/source-zone                native   shared

Let's boot a zone, and login:

# time zoneadm -z scotty-z-05 boot

real    0m0.38s
user    0m0.14s
sys     0m0.05s

# zlogin scotty-z-05
[Connected to zone 'scotty-z-05' pts/2]
Last login: Mon Jan  7 19:33:29 on console
Sun Microsystems Inc.   SunOS 5.11      snv_80  January 2008

Now, let's delete all the zones again:

# time ./delete-cloned-zones
Press RETURN to delete the following zones and their zfs file systems:
   2 scotty-z-01      ready      /p1/scotty-z-01                native   shared
   4 scotty-z-02      ready      /p1/scotty-z-02                native   shared
   6 scotty-z-03      ready      /p1/scotty-z-03                native   shared
   8 scotty-z-04      ready      /p1/scotty-z-04                native   shared
  10 scotty-z-05      running    /p1/scotty-z-05                native   shared
  12 scotty-z-06      ready      /p1/scotty-z-06                native   shared
  14 scotty-z-07      ready      /p1/scotty-z-07                native   shared
  16 scotty-z-08      ready      /p1/scotty-z-08                native   shared
  18 scotty-z-09      ready      /p1/scotty-z-09                native   shared
  20 scotty-z-10      ready      /p1/scotty-z-10                native   shared

You may now delete lines from file /var/tmp/zones-to-delete-7349.txt
  (in case you would like to keep some of the zones).
Press RETURN to halt all zones in file /var/tmp/zones-to-delete-7349.txt.

Trying to halt all zones in file /var/tmp/zones-to-delete-7349.txt:
zone scotty-z-01 halted.
zone scotty-z-02 halted.
zone scotty-z-03 halted.
zone scotty-z-04 halted.
zone scotty-z-05 halted.
zone scotty-z-06 halted.
zone scotty-z-07 halted.
zone scotty-z-08 halted.
zone scotty-z-09 halted.
zone scotty-z-10 halted.
Finished halting all zones in file /var/tmp/zones-to-delete-7349.txt.

Last chance: Press RETURN to stop deleting the zones, or
  type in yes, followed by RETURN, to continue.

yes
Trying to delete all zones in file /var/tmp/zones-to-delete-7349.txt:
zone scotty-z-01 deleted.
zone scotty-z-02 deleted.
zone scotty-z-03 deleted.
zone scotty-z-04 deleted.
zone scotty-z-05 deleted.
zone scotty-z-06 deleted.
zone scotty-z-07 deleted.
zone scotty-z-08 deleted.
zone scotty-z-09 deleted.
zone scotty-z-10 deleted.

Trying to destroy all zone zfs file systems:
zfs filesystem p1/scotty-z-01 destroyed.
zfs filesystem p1/scotty-z-02 destroyed.
zfs filesystem p1/scotty-z-03 destroyed.
zfs filesystem p1/scotty-z-04 destroyed.
zfs filesystem p1/scotty-z-05 destroyed.
zfs filesystem p1/scotty-z-06 destroyed.
zfs filesystem p1/scotty-z-07 destroyed.
zfs filesystem p1/scotty-z-08 destroyed.
zfs filesystem p1/scotty-z-09 destroyed.
zfs filesystem p1/scotty-z-10 destroyed.

Press RETURN to delete temporary file /var/tmp/zones-to-delete-7349.txt,
<ctrl>c to keep it.

real    0m28.88s
user    0m3.17s
sys     0m4.22s
I have tested this several times, with different parameters, with 100 and more zones, on SPARC and x86. Works fine! I hope you find some useful cases for these scripts in your environment, or get some ideas for writing your own zone creation scripts.

Comments:

Thanks..

Posted by sohbet on January 15, 2008 at 12:28 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

blogfinger

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today