Home

create_zone.sh




Purpose

create_zone.sh is a shell script for unattended zone creation in Solaris 10.

Using this script you can create zones without user interaction for example in a jumpstart environment. You can configure

You can also define a profile for the zone.

In addition you can define a finish script for the zone which runs after the zone is created and configured but before the zone is booted in the global zone.

And you can define a customize script for the zone. The customize scripts runs while first rebooting the zone. The script can be in one of the milestones single-user, multi-user, or multi-user-server.

A site specific SMF profile is also supported.

One or more template directories with additional files that should be copied to the zone are also supported.

Zone installation can be done via installation or via cloning an existing zone.


Like all of my scripts based on scriptt.sh create_zone.sh also supports a configuration file in which you can define mostly all values to be used for the zone configuration.




Back to top

License


# CDDL HEADER START
#
# The contents of this file and the script are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END



Back to top

History


Version
Releasedate
         Description
v1.1.10
29.03.2009
##    29.03.2009 v1.1.10 /bs
##      added the parameter -R (--readonlydir) to configure add. read-only directories for the
##      zone
v1.1.9
28.02.2009
##    28.02.2009 v1.1.9 /bs
##      the default for the zone template directories (parameter -t) is now
##        "${DEFAULT_ZONE_PATH}/template_dir"
##     if that directory exist
##     create_zones.sh now creates a correct sysidcfg file if USE_EXISTING_NAMESERVER_CONFIG
##     is set to y

v1.1.8
25.02.2009
##    25.02.2009 v1.1.8 /bs
##      added support for new dladm options
##      added the parameter -t (--templatedir)
##      added the config options zone_netmask for zones with exclusive IP stack
##      create_zone.sh did not create a complete sysidcfg for zones with exclusive IP. Fixed.
##      removed the call of prtdiag; __MACHINE_SUBTYPE is now always empty

v1.1.7
18.02.2009
##    18.02.2009 v1.1.7 /bs
##      added support for other global config entries
##      added suport for devices for the zone
v1.1.6
15.02.2009
##    15.02.2009 v1.1.6 /bs
##      added support for ZFS datasets (parameter -Z)
##      added support for cloning a zone (parameter -N)
v1.1.5
08.02.2009
##    08.02.2009 v1.1.5 /bs
##    added support for the defrouter configuration for zones in Solaris U6 and newer
##      The list of file that are copied to a zone with exclusive IP stack can now be
##      configured in the config file; see the variable EXCLUSIVE_IP_STACK_CONFIG_FILES
v1.1.4
16.05.2008
##    15.05.2008 v1.1.4 /bs
##      added workaround for the "GLDv3 support" for the ce adapter
##         see: http://sunsolve.sun.com/search/document.do?assetkey=1-61-234401-1
##      added the config options zone_gldv3_check
v1.1.3
18.03.2008
##   18.03.2008 v1.1.3 /bs
##      added the config option zone_writabledir  and the option -w (writabledir)
##      improved the error handling
v1.1.2
17.03.2008
##   17.03.2008 v1.1.2 /bs
##      added the option -e (edit)
##      added the config option zone_inherited_dir and the option -d
##      added the syntax xx.xx.xx.xx/yy for the IP address (use /yy to specify the netmask)
v1.1.1
15.03.2008
##   15.03.2008 v1.1.1 /bs
##      added the config options zone_memory_limit, zone_swap_limit, zone_cpu_count, and zone_cpu_shares
v1.1.0
12.03.2008
##   12.03.2008 v1.1.0 /bs
##      added support for IP instances
##      use a newer version of the script template
v1.0.0
12.06.2006
initial public release
v0.9.0
07.06.2006 initial release; some tests were missing






Back to top

Operating system


Solaris 10 and newer



Back to top

Language / type


Kornshell Script



Back to top

Prerequisites

zones support must be installed



Back to top

Usage


The only mandatory parameter for create_zone.sh are the parameter for the name of the zone (-z <zone_name> or -x zone_name=<zone_name>, the IP address of the zone (-i <zone_ip_address or -x zone_ip_address=<zone_ip_address>), and the path for the zone (-p <zone_path> or -x zone_path=<zone_path>) if it is not the default value (/zones).

All other parameter are optional.

Note: A "big" zone is a "whole root zone"; a "small" zone is a "sparse root zone".



$ /var/develop/sol9/scripts/create_zone.sh -h -v
[29.03.2009 18:09:08] create_zone.sh v1.1.10 started on Sun Mar 29 18:09:08 CEST 2009 
[29.03.2009 18:09:08] Reading the config file "/etc/create_zone.conf" ...
  create_zone.sh v1.1.10 - create zones unattended

  Usage: create_zone.sh [-v|+v] [-q|+q] [-h] [-l logfile|+l] [-y|+y] [-n|+n]
                    [-D|+D] [-a|+a] [-O|+O] [-f|+f] [-C] [-H] [-S n] [-V] [-T]

                    -z zone_name -i zone_ip_address [-p zone_path] [-r zone_def_router] [-I|+I]
                    [-A zone_network_adapter] [-b|+b] [-s freespace] [-x key=value] [-t templatedir]
                    [-e] [-d dir_to_inherit] [-w zonedir:globaldir] [-R zonedir:globaldir] [-Z dataset]
                    [-N sourcezone]

  Known keys for -x :
    zone_name zone_ip_address zone_network_interface zone_mode zone_ip_stack zone_netmask zone_default_router
    zone_root_password zone_tz zone_locale zone_terminal zone_timeserver zone_gldv3_check zone_path
    zone_customize_script_source zone_customize_script_target zone_finish_script
    zone_autboot boot_the_zone_now free_space_for_the_zone zone_profile
    use_existing_nameserver_config
    zone_memory_limit zone_swap_limit zone_cpu_count zone_cpu_shares
    zone_inherited_dir zone_writabledir zone_readonly_dir zone_dataset    
    zone_clone_source zone_device zone_global_option zone_template_dir

 

 Note: Use -{switch} or --{longswitch} to turn an option on;
       use +{switch} or ++{longswitch} to turn an option off

       The long format of the parameter (--parameter/++parameter) is not supported by all ksh implementations
      
      
    Parameter:

      -v|+v - turn verbose mode on/off; current value: y
              Long format: --verbose / ++verbose
      -q|+q - turn quiet mode on/off; current value: n
              Long format: --quiet / ++quiet
      -h    - show usage
              Long format: --help
      -l    - set the logfile
              current value: /var/tmp/create_zone.LOG
              Long format: --logfile     
      +l    - do not write a logfile
              Long format: ++logfile
      -y|+y - assume yes to all questions or not
              Long format: --yes / ++yes
      -n|+n - assume no to all questions or not
              Long format: --no /++no
      -D|+D - run main in single step mode (and turn colors on); current value: n
              Long format: --debug / ++debug
      -a|+a - turn colors on/off; current value: n
              Long format: --color / ++color
      -O|+O - overwrite existing files or not; current value: n
              Long format: --overwrite / ++overwrite
      -f|+f - force; do it anyway; current value: n
              Long format: --force / ++force
      -C    - write a default config file in the current directory and exit
              Long format: --writeconfigfile
      -H    - write extended usage to STDERR and exit
              Long format: --doc
      -S n  - print error/warning summaries:
              n = 0 no summariess, 1 = print error msgs,
              2 = print warning msgs, 3 = print error and warning mgs
              Current value: 0
              Long format: --summaries
      -V    - write version number to STDOUT and exit
              Long format: --version
      -T    - append STDOUT and STDERR to the file "/var/tmp/create_zone.sh.23414.tee.log"
              Long format: --tee

      -z    - zone name, mandatory, no default
              Current value:
              Long format: --zone_name
      -i    - zone ip address, mandatory, no default
              Current value:      
              use xx.xx.xx.xx/yy to specifiy a netmask
              Long format: --zone_ip_address
      -r      default router for the zone;
              current value 192.168.1.1
              use none to unset the default router
              Long format: --zone_default_router
      -I/+I - use a exclusive IP stack (-I) or a shared IP stack (+I);
              current value EXCLUSIVE
              Long format: --zone_ip_stack / ++zone_ip_stack
      -p    - zone path;
              current value: /zones
              Long format: --zone_path
      -N    - create the zone by cloning another zone
              Current value: zone_template
              Long format: --clone
      +N    - create the zone by installing the zone
              Long format: ++clone
      -A    - zone network adapter
              Current value:
              Long format: --zone_network_interface
      -b    - create a big zone
              Current value: small
              Long format: --big
      +b    - create a small zone
              Long format:  ++big
      -s    - freespace in KB necessary for the zone
              Current value:
              Use 0 to suppress the free space check
              Long format: --free_space
      -e|+e - edit the zone configuration before creating the zone
              current value: n
              If this parameter is found, the script calls the standard editor
               (environment variable EDITOR or vi if not set) for the zone
              configuration before creating the zone
              Long format: --edit
      -d    - directory to inherit by the zone (*)
              Current Value:
              Directory names with spaces or tabs are NOT supported
              Long format: --inherit
      +d    - remove all additional inherited directories and add the new
              directory to the list of directories to inherit
              (use none to delete the complete list)
              This parameter will undo all previous found -d parameter
              and also delete the default values from the config file
              Long format: ++inherit
      -R    - directory to mount readonly in the zone (*)
              Current value: /tools:/tools
              Format of the entry: zone_dir:global_dir
              Directory names with spaces or tabs are NOT supported
              If the directories global_dir or zone_dir do not exist
              they will be created.
              Long format: --readonlydir
      +R    - reset the list of readonly directories and add the new
              directory to the list of readonly directories
              (use none to delete the complete list)             
              Format of the entry: zone_dir:global_dir
              If the directories global_dir or zone_dir do not exist in
              the global zone they will be created.
              This parameter will undo all previous found -R parameter
              and also delete the default values from the config file
              Long format: ++readonlydir
      -w    - directory to mount writable in the zone (*)
              Current value:
              Format of the entry: zone_dir:global_dir
              Directory names with spaces or tabs are NOT supported
              If the directories global_dir or zone_dir do not exist
              they will be created.
              Long format: --writabledir
      +w    - reset the list of writable directories and add the new
              directory to the list of writable directories
              (use none to delete the complete list)             
              Format of the entry: zone_dir:global_dir
              If the directories global_dir or zone_dir do not exist in
              the global zone they will be created.
              This parameter will undo all previous found -w parameter
              and also delete the default values from the config file
              Long format: ++writabledir
      -t    - template directory for the zone (*)
              Current value: /zones/template_dir
              All files and directories in this directory will be
              copied to the root fs of the zone after the zone
              is created.
              Directory names with spaces or tabs are NOT supported
              Long format: --templatedir
      +t    - reset the list of template dirs and add a new directory
              directory to the list of template directories
              (use none to delete the complete list)             
              This parameter will undo all previous found -t parameter
              and also delete the default values from the config file
              Long format: ++templatedir
      -Z    - ZFS dataset for the zone (*)
              Current Value:
              Long format: --dataset
      +Z    - reset the list of ZFS datasets for the zone and add the new
              ZFS dataset to the zone
              (use none to delete the complete list)             
              This parameter will undo all previous found -Z parameter
              and also delete the default values from the config file
              Long format: ++dataset
      -x key=value (*)
            - define various config parameter for the zone (see below)
              Long format: --config

    The parameter marked with (*) can be used multiple times.


    Known key/value pairs for the parameter -x are
    (keys marked with (*) can be used more than once):

      zone_name=name_of_the_zone
        current value:
        no default
        shortcut: -z

      zone_clone_source=name_of_the_zone_to_clone
        current value: zone_template
        no default
        shortcut: -N

      zone_memory_limit
        current value:
        memory limit for the zone; no default

      zone_swap_limit
        current value:
        swap limit for the zone; no default

      zone_cpu_shares
        current value:
        no of CPU shares for the zone, no default

      zone_cpu_count
        current value:
        no. of cpus for the zone; no default

      address=ip_address_for_the_zone
    or
      zone_ip_address=ip_address_for_the_zone
        current value:
        speficy the IP address for the zone; use xx.xx.xx.xx/yy to specify a netmask also
        no default
        shortcut: -i

      zone_network_interface=network_interface_for_the_zone
    or
      physical=network_interface_for_the_zone
        current value:
        the default depends on the IP address choosen for the zone
        When configuring a zone with exclusive IP stack (-I) there is no
        default for this parameter and therefore this parameter is mandatory
        shortcut: -A

      zone_default_router=ip_address_of_the_default_router
        current value: 192.168.1.1
        The default router for the zone;
        use none to unset the default router; no default

      zone_netmask=netmask-for_the_zone
        current value: 255.255.255.0
        This is the netmask for zones with exclusive IP stack
        no default
       
      zone_ip_stack={shared|exclusive}
        current value: EXCLUSIVE
        this is the type of the IP stack for the zone;
        shortcut: -I

      zone_gldv3_check={yes|no}
        current value: yes
        if this key is set to no, the script will not check if the network adapter
        for the zone uses a GLDv3 driver

      zone_mode=[small|big]
        current value: small
        shortcut: -b|+b

      zonepath=path_for_the_zone
    or
      zone_path=path_for_the_zone
        current value: /zones
        shortcut: -p
      The zone will be created in the directory [zone_path]/[zone_name]

      zone_root_password=encrypted_password_for_root
        current value: IZjwKPpkGN.66
        The default is the passwort from the root user in the global zone
        Use none for no root user password
       
      zone_tz=timezone_for_the_zone
        current value: Europe/Berlin
        The default is the current TIMEZONE of the global zone

      zone_locale=locale_for_the_zone
        current value: C
        The default is the current locale

      zone_terminal=terminal_type_for_the_zone
        current value: vt100
        The default is the value of the variable TERM
        or vt100 if the variable TERM is not set

      zone_timeserver=timeserver_for_the_zone
        current value: localhost

      zone_finish_script=finish_script_for_the_zone
        current value:

        The finish script runs in the global zone after the zone is
        created and configured but before it is booted. The parameter for
        the finish_script is the directory used for the zone
        Use none for no finish script
       
      zone_customize_script_source=customize_script_for_the_zone
        current value: builtin
        The customization script runs inside the new zone
        while first booting the zone.

        Use builtin for the builtin customize script; use none for
        no customize script
       
        The builtin customize script is:

        # --- built in script starts

  echo "Customization of the zone is running ..."

  echo "Disabling sendmail ..."
  svcadm disable sendmail

  echo " ... customization done. Removing the customize script"
  rm $0

        # --- built in script ends

        (defined in the variable DEFAULT_ZONE_CUSTOMIZE_SCRIPT_CONTENTS
          in the config file)

      zone_customize_script_target=fqn_of_the_customize_script_inside_the_zone
        current value: /etc/rc3.d/S99customize_script

      zone_profile=smf_profile_for_the_zone
        current value:

      use_existing_nameserver_config=[yes|no]
        current value: y
        If this variable is true the files


/etc/resolv.conf
/etc/nsswitch.conf


        from the global zone are copied to the new zone
        (the list of files is defined in the variable NAME_SERVER_CONFIG_FILES
         in the config file)
        
      zone_autoboot=[yes|no]
    or
      autoboot=[yes|no]
        current value: n
     
      boot_the_zone_now=[yes|no]
        current value: n
        if yes, the zone will be booted automatically if configured and
        created without errors.

      free_space_for_the_zone=freespace_necessary_in_kb
        The defaults are
          for big zones: 3500000 kb
          for small zones: 200000 kb
        Use 0 to suppress the free space check
        shortcut: -s

      zone_inherited_dir=dir_name  (*)
        current value:
        Directory which should be inherited by the zone.
        The default is only to inherit the default directories
        Directories with space or tabs in the name are NOT supported!
        shortcut: -d

      zone_readonly_dir=zone_dir:global_dir  (*)
        current value: /tools:/tools
        Directory which should be mounted readonly in the zone.
        Directories with space or tabs in the name are NOT supported!
        If the directory in the global zone does not exist it will be created.
        shortcut: -R

      zone_writable_dir=zone_dir:global_dir  (*)
        current value:
        Directory which should be mounted writable in the zone.
        Directories with space or tabs in the name are NOT supported!
        If the directory in the global zone does not exist it will be created.
        shortcut: -w

      zone_template_dir=dir_name  (*)
        current value: /zones/template_dir
        All files and directories in this directory wil be copied to the
        root filesystem of the zone
        Directories with space or tabs in the name are NOT supported!
        shortcut: -t

      zone_dataset (*)
        current value:
        ZFS dataset for the zone
        shortcut: -Z

      zone_device (*)
        current value:
        device for the zone

      zone_global_option (*)
        current value:
        Add. global options (like bootargs, pool, limitpriv, etc) can be
        defined using this keyword. These entries are NOT checked by the script!

Please note that you need Solaris 10 8/07 or newer for the configuration options
  zone_memory_limit, zone_swap_limit, zone_cpu_count, and zone_cpu_shares

Please not that you need Solaris 10 6/08 or newer for the configuration options
  zone_default_router (shortcut -r)
 

[29.03.2009 18:09:08] The log file used was "/tmp/create_zone.sh.23414.TEMP" 
[29.03.2009 18:09:08] create_zone.sh v1.1.10 ended on Sun Mar 29 18:09:08 CEST 2009.
[29.03.2009 18:09:08] The RC is 1.

 
 



Examples


Example 1:  creating a zone with create_zone.sh v1.1.8 with only the mandatory parameter

$ create_zone.sh -z testzone13 -i 192.168.1.77
[26.02.2009 23:17:49] create_zone.sh v1.1.8 started on Thu Feb 26 23:17:49 CET 2009 
[26.02.2009 23:17:49] Reading the config file "./create_zone.conf" ...
[26.02.2009 23:17:49] Using the log file "/var/tmp/create_zone.LOG" 
 
[26.02.2009 23:17:49] Creating the zone "testzone13"
[26.02.2009 23:17:49] No memory limit configured for the zone
[26.02.2009 23:17:49] No swap limit configured for the zone
[26.02.2009 23:17:49] No dedicated cpus configured for the zone
[26.02.2009 23:17:49] No CPU shares configured for the zone
[26.02.2009 23:17:49] No additional directories to be inherited by the zone
[26.02.2009 23:17:49] The path for the zone is "/zones/testzone13" 
[26.02.2009 23:17:49] The mode for the zone is "small" 
[26.02.2009 23:17:49] The IP address of the zone is "192.168.1.77"
[26.02.2009 23:17:49] The zone uses a(n) "SHARED" IP stack
[26.02.2009 23:17:50] No default router configured for the zone.
[26.02.2009 23:17:50] Check the GLDv3 driver: "yes" 
[26.02.2009 23:17:50] The zone uses the network interface "ipmp0"
[26.02.2009 23:17:50] The locale for the zone is "C" 
[26.02.2009 23:17:50] The timezone for the zone is "Europe/Berlin" 
[26.02.2009 23:17:50] The encrypted root password for the zone is "5ZtCsAEwWfHIg"
[26.02.2009 23:17:50] The terminal type for the zone is "vt100"
[26.02.2009 23:17:50] The timeserver for the zone is "localhost"
[26.02.2009 23:17:50] The finish script for the zone is ""
[26.02.2009 23:17:50] The customize script for the zone is "builtin" 
[26.02.2009 23:17:50] The customize script inside the zone is "/etc/rc3.d/S99customize_script"
[26.02.2009 23:17:50] The SMF profile for the zone is ""
[26.02.2009 23:17:50] Use the existing name server configuration: y
[26.02.2009 23:17:50] Set autoboot to enable for the zone: n
[26.02.2009 23:17:50] Boot the zone after installation: n
[26.02.2009 23:17:50] Free space in KB necessary for creating the zone is: 200000
[26.02.2009 23:17:50] 
[26.02.2009 23:17:50] Edit the zone config before creating the zone: n
 
Create the zone (y/N)?  y
[26.02.2009 23:18:06] Checking the zone configuration ...
[26.02.2009 23:18:07] The zone configuration seems to be okay 
[26.02.2009 23:18:07] Configuring the zone "testzone13" ...
[26.02.2009 23:18:07] Installing the zone "testzone13" ...
A ZFS file system has been created for this zone.
Preparing to install zone <testzone13>.
Creating list of files to copy from the global zone.
Copying <9658> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <1596> packages on the zone.
Initialized <1596> packages on zone.                                
Zone <testzone13> is initialized.
Installation of <1> packages was skipped.
The file </zones/testzone13/root/var/sadm/system/logs/install_log> contains a log of the zone installation.
[26.02.2009 23:35:56] Preparing the zone "testzone13" for running applications ...
[26.02.2009 23:35:58] Post configuring the zone "testzone13"  ...
[26.02.2009 23:35:58] Changing the nameserver configuration of the zone "testzone13" ...
[26.02.2009 23:35:58] Processing the file "/etc/resolv.conf" ...
[26.02.2009 23:35:58] Processing the file "/etc/nsswitch.conf" ...
[26.02.2009 23:35:58] Installing the customize script "/etc/rc3.d/S99customize_script" in the zone "testzone13" ...
[26.02.2009 23:35:58]  ... done. zone "testzone13" installed and configured
[26.02.2009 23:35:58] The log file used was "/var/tmp/create_zone.LOG" 
[26.02.2009 23:35:58] create_zone.sh v1.1.8 ended on Thu Feb 26 23:35:58 CET 2009.
[26.02.2009 23:35:58] The RC is 0.



Example 2 : creating a zone with create_zone.sh v1.1.8 using the zoneadm clone features

$ create_zone.sh -z testzone14 -i 192.168.1.78 -N template
[26.02.2009 23:49:34] create_zone.sh v1.1.8 started on Thu Feb 26 23:49:34 CET 2009 
[26.02.2009 23:49:34] Reading the config file "./create_zone.conf" ...
[26.02.2009 23:49:34] Using the log file "/var/tmp/create_zone.LOG" 
 
[26.02.2009 23:49:34] Creating the zone "testzone14"
[26.02.2009 23:49:34] The zone will be created by cloning the zone "template" 
[26.02.2009 23:49:34] No memory limit configured for the zone
[26.02.2009 23:49:34] No swap limit configured for the zone
[26.02.2009 23:49:34] No dedicated cpus configured for the zone
[26.02.2009 23:49:34] No CPU shares configured for the zone
[26.02.2009 23:49:34] No additional directories to be inherited by the zone
[26.02.2009 23:49:35] The path for the zone is "/zones/testzone14" 
[26.02.2009 23:49:35] The mode for the zone is "small" 
[26.02.2009 23:49:35] The IP address of the zone is "192.168.1.78"
[26.02.2009 23:49:35] The zone uses a(n) "SHARED" IP stack
[26.02.2009 23:49:35] No default router configured for the zone.
[26.02.2009 23:49:35] Check the GLDv3 driver: "yes" 
[26.02.2009 23:49:35] The zone uses the network interface "ipmp0"
[26.02.2009 23:49:35] The locale for the zone is "C" 
[26.02.2009 23:49:35] The timezone for the zone is "Europe/Berlin" 
[26.02.2009 23:49:35] The encrypted root password for the zone is "5ZtCsAEwWfHIg"
[26.02.2009 23:49:35] The terminal type for the zone is "vt100"
[26.02.2009 23:49:35] The timeserver for the zone is "localhost"
[26.02.2009 23:49:35] The finish script for the zone is ""
[26.02.2009 23:49:35] The customize script for the zone is "builtin" 
[26.02.2009 23:49:35] The customize script inside the zone is "/etc/rc3.d/S99customize_script"
[26.02.2009 23:49:35] The SMF profile for the zone is ""
[26.02.2009 23:49:35] Use the existing name server configuration: y
[26.02.2009 23:49:35] Set autoboot to enable for the zone: n
[26.02.2009 23:49:35] Boot the zone after installation: n
[26.02.2009 23:49:35] Free space in KB necessary for creating the zone is: 200000
[26.02.2009 23:49:35] 
[26.02.2009 23:49:35] Edit the zone config before creating the zone: n
 
Create the zone (y/N)?  y
[26.02.2009 23:49:40] Checking the zone configuration ...
[26.02.2009 23:49:42] The zone configuration seems to be okay 
[26.02.2009 23:49:42] Configuring the zone "testzone14" ...
[26.02.2009 23:49:42] Installing the zone "testzone14" by cloning the zone "template"...
Cloning snapshot rpool/zones/template@SUNWzone7
Instead of copying, a ZFS clone has been created for this zone.
sys-unconfig started Thu Feb 26 23:49:48 2009
rm: /a/etc/vfstab.sys-u: No such file or directory
sys-unconfig completed Thu Feb 26 23:49:49 2009
[26.02.2009 23:49:52] Preparing the zone "testzone14" for running applications ...
[26.02.2009 23:50:00] Post configuring the zone "testzone14"  ...
[26.02.2009 23:50:00] Changing the nameserver configuration of the zone "testzone14" ...
[26.02.2009 23:50:00] Processing the file "/etc/resolv.conf" ...
[26.02.2009 23:50:00] Processing the file "/etc/nsswitch.conf" ...
[26.02.2009 23:50:00] Installing the customize script "/etc/rc3.d/S99customize_script" in the zone "testzone14" ...
[26.02.2009 23:50:00]  ... done. zone "testzone14" installed and configured
[26.02.2009 23:50:01] The log file used was "/var/tmp/create_zone.LOG" 
[26.02.2009 23:50:01] create_zone.sh v1.1.8 ended on Thu Feb 26 23:50:01 CET 2009.
[26.02.2009 23:50:01] The RC is 0.




Example 3 :  Creating a zone with create_zone.sh v1.1.3 using some more parameter


[Tue Mar 18 18:22:15 root@sol9 /]
# EDITOR=cat ; /var/tmp/create_zone.sh --zone_name testzone3 --zone_ip_address 10.1.2.5/24  --zone_path /export \
--zone_network_interface hme0  --config zone_locale=de -x inherited_dir=/bootcd --config inherited_dir=/sol10ramfs \
 -x inherited_dir=/sol9ramfs  -w /tftpboot:/var/zones/testzone3/tftpboot -w /usr/local:/var/zones/testzone3/usr/local \
-e -O
[18.03.2008 18:22:19] create_zone.sh v1.1.3 started on Tue Mar 18 18:22:19 MET 2008 
[18.03.2008 18:22:19] Reading the config file "./create_zone.conf" ...
[18.03.2008 18:22:20] Using the log file "/var/tmp/create_zone.LOG" 
 
[18.03.2008 18:22:20] Creating the zone "testzone3"
[18.03.2008 18:22:20] No memory limit configured for the zone
[18.03.2008 18:22:20] No swap limit configured for the zone
[18.03.2008 18:22:20] No dedicated cpus configured for the zone
[18.03.2008 18:22:20] No CPU shares configured for the zone
[18.03.2008 18:22:20] Additional directories inherited by the zone are:
[18.03.2008 18:22:20]     /bootcd
[18.03.2008 18:22:20]     /sol10ramfs
[18.03.2008 18:22:21]     /sol9ramfs
[18.03.2008 18:22:21] Writable directories in the zone are:
[18.03.2008 18:22:21]     (zone) /tftpboot = (global) /var/zones/testzone3/tftpboot
[18.03.2008 18:22:21]     (zone) /usr/local = (global) /var/zones/testzone3/usr/local
[18.03.2008 18:22:21] The path for the zone is "/export/testzone3" 
[18.03.2008 18:22:21] The mode for the zone is "small" 
[18.03.2008 18:22:21] The IP address of the zone is "10.1.2.5/24"
[18.03.2008 18:22:21] The zone uses a(n) "SHARED" IP stack
[18.03.2008 18:22:21] The zone uses the network interface "hme0"
[18.03.2008 18:22:21] The locale for the zone is "de" 
[18.03.2008 18:22:21] The timezone for the zone is "MET" 
[18.03.2008 18:22:21] The encrypted root password for the zone is "4l/EjawSj1b7."
[18.03.2008 18:22:21] The terminal type for the zone is "ansi"
[18.03.2008 18:22:21] The timeserver for the zone is "localhost"
[18.03.2008 18:22:21] The finish script for the zone is ""
[18.03.2008 18:22:21] The customize script for the zone is "builtin" 
[18.03.2008 18:22:21] The customize script inside the zone is "/etc/rc3.d/S99customize_script"
[18.03.2008 18:22:21] The SMF profile for the zone is ""
[18.03.2008 18:22:21] Use the existing name server configuration: y
[18.03.2008 18:22:21] Set autoboot to enable for the zone: n
[18.03.2008 18:22:21] Boot the zone after installation: n
[18.03.2008 18:22:21] Free space in KB necessary for creating the zone is: 200000
[18.03.2008 18:22:21] 
[18.03.2008 18:22:21] Edit the zone config before creating the zone y
 
[18.03.2008 18:22:22] WARNING: The zone "testzone3" already exists; the status is "configured" 
 
Recreate the zone (y/N)?  y
[18.03.2008 18:22:23] Checking the zone configuration ...
[18.03.2008 18:22:25] The zone configuration seems to be okay 
[18.03.2008 18:22:25] Deleting the existing zone "testzone3" ...
cannot manage a zone which is in state 'configured'
zoneadm: zone 'testzone3': could not start zoneadmd
[18.03.2008 18:22:25] WARNING: Error calling zoneadm -z testzone3 halt
zoneadm: zone 'testzone3': is already in state 'configured'.
[18.03.2008 18:22:26] Removing the existing zone directory "/export/testzone3" ...
[18.03.2008 18:22:27] Configuring the zone "testzone3" ...
[18.03.2008 18:22:27] Calling the editor "cat" to edit the zone configuration \"/tmp/create_zone.sh.14320.14305.TEMP1\" ...

create
set autoboot=false
set zonepath=/export/testzone3

add net
set address=10.1.2.5/24 
set physical=hme0
end

add inherit-pkg-dir
set dir=/bootcd
end
add inherit-pkg-dir
set dir=/sol10ramfs
end
add inherit-pkg-dir
set dir=/sol9ramfs
end
add fs
set dir=/tftpboot
set special=/var/zones/testzone3/tftpboot
set type=lofs
add options rw
end
add fs
set dir=/usr/local
set special=/var/zones/testzone3/usr/local
set type=lofs
add options rw
end
commit
exit

Continue creating the zone (y/N)?  y
[18.03.2008 18:22:28] Installing the zone "testzone3" ...
Preparing to install zone <testzone3>.
Creating list of files to copy from the global zone.
Copying <8701> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <1213> packages on the zone.
Initialized <1213> packages on zone.                                
Zone <testzone3> is initialized.
The file </export/testzone3/root/var/sadm/system/logs/install_log> contains a log of the zone installation.
[18.03.2008 19:07:02] Preparing the zone "testzone3" for running applications ...
[18.03.2008 19:07:05] Post configuring the zone "testzone3"  ...
[18.03.2008 19:07:05] Changing the nameserver configuration of the zone "testzone3" ...
[18.03.2008 19:07:05] Processing the file "/etc/resolv.conf" ...
[18.03.2008 19:07:05] Processing the file "/etc/nsswitch.conf" ...
[18.03.2008 19:07:06] Installing the customize script "/etc/rc3.d/S99customize_script" in the zone "testzone3" ...
[18.03.2008 19:07:06]  ... done. zone "testzone3" installed and configured
[18.03.2008 19:07:06] The log file used was "/var/tmp/create_zone.LOG" 
[18.03.2008 19:07:06] create_zone.sh v1.1.3 ended on Tue Mar 18 19:07:06 MET 2008.
[18.03.2008 19:07:06] The RC is 0.

[Tue Mar 18 19:07:06 root@sol9 /]
#


# check the results:

[Tue Mar 18 19:13:31 root@sol9 /]
# zonecfg -z testzone3 info
zonename: testzone3
zonepath: /export/testzone3
brand: native
autoboot: false
bootargs:
pool:
limitpriv:
scheduling-class:
ip-type: shared
inherit-pkg-dir:
        dir: /lib
inherit-pkg-dir:
        dir: /platform
inherit-pkg-dir:
        dir: /sbin
inherit-pkg-dir:
        dir: /usr
inherit-pkg-dir:
        dir: /bootcd
inherit-pkg-dir:
        dir: /sol10ramfs
inherit-pkg-dir:
        dir: /sol9ramfs
fs:
        dir: /tftpboot
        special: /var/zones/testzone3/tftpboot
        raw not specified
        type: lofs
        options: [rw]
fs:
        dir: /usr/local
        special: /var/zones/testzone3/usr/local
        raw not specified
        type: lofs
        options: [rw]
net:
        address: 10.1.2.5/24
        physical: hme0

[Tue Mar 18 19:13:39 root@sol9 /]
# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP   
   0 global           running    /                              native   shared
   1 gcc              running    /zones/gcc                     native   shared
   2 sunstudio12      running    /zones/sunstudio12             native   shared
   3 template         running    /zones/template                native   shared
   4 test             running    /zones/test                    native   shared
   7 testzone         ready      /zones/testzone                native   excl 
   8 testzone3        ready      /export/testzone3              native   shared

[Tue Mar 18 19:13:45 root@sol9 /]
#





Back to top

Internas

Sample config file for create_zone.sh v1.1.10:


# config file for create_zone.sh v1.1.10, created Sun Mar 29 18:33:14 CEST 2009


# extension for backup files

  DEFAULT_BACKUP_EXTENSION=".$$.backup"

## EXCLUSIVE_IP_STACK_CONFIG_FILES
##   network configuration files that will be copied from the global zone
##   to the non-global zone if an exclusive IP stack is used
##   Note: Add only fully qualified filenames here!
##
  EXCLUSIVE_IP_STACK_CONFIG_FILES="
/etc/netmasks
/etc/networks
/etc/defaultrouter
/etc/hosts
"

## NAME_SERVER_CONFIG_FILES
##   name server configuration files
##   Note: Add only fully qualified filenames here!
##
  NAME_SERVER_CONFIG_FILES="
/etc/resolv.conf
/etc/nsswitch.conf
"

## DEFAULT_FREE_SPACE_FOR_THE_ZONE
##   free space neccessary for the zone in KB
##   (the default depends on the type of the zone)
##
  DEFAULT_FREE_SPACE_FOR_THE_ZONE=""

## DEFAULT_FREE_SPACE_FOR_A_BIG_ZONE
##   default free space needed for a big zone in kb
##
  DEFAULT_FREE_SPACE_FOR_A_BIG_ZONE=3500000

## DEFAULT_FREE_SPACE_FOR_A_SMALL_ZONE
##   default free space needed for a small zone in kb
##
  DEFAULT_FREE_SPACE_FOR_A_SMALL_ZONE=200000

## DEFAULT_ZONE_MODE
##   default type of the new zone;
##   possible values: small (= sparse zone) or big (= whole root zone)
##
  DEFAULT_ZONE_MODE="small"

## DEFAULT_ZONE_CLONE_SOURCE
##   source zone for cloning
##
  DEFAULT_ZONE_CLONE_SOURCE=""
 
## DEFAULT_ZONE_PATH
##   base directory for zones (can be a symbolic link;
##   this will be resolved by the script)
##
  DEFAULT_ZONE_PATH="/zones"

## DEFAULT_ZONE_ROOT_PASSWORD
##   default for the root password is the password
##   of the existing root user
## 
  DEFAULT_ZONE_ROOT_PASSWORD="$( grep root /etc/shadow 2>/dev/null | cut -f2 -d ":" )"

## DEFAULT_ZONE_TZ
##   the default timezone is the timezone of the machine
##
  DEFAULT_ZONE_TZ="$( grep "^TZ=" /etc/TIMEZONE 2>/dev/null | cut -f2 -d"=" )"
  [ "${DEFAULT_TZ}"x = ""x ] && DEFAULT_TZ="${TZ}"

## DEFAULT_ZONE_LOCALE
##   default locale is the current locale
##
  DEFAULT_ZONE_LOCALE="${LANG}"
  [ "${DEFAULT_ZONE_LOCAL}"x = ""x ] && DEFAULT_ZONE_LOCALE="C"

## DEFAULT_ZONE_TERMINAL 
##   default terminal type for the zone
##
  DEFAULT_ZONE_TERMINAL="${TERM:-vt100}"

## DEFAULT_ZONE_TIMESERVER
##   default timeserver for the zones
##
  DEFAULT_ZONE_TIMESERVER="localhost"

## DEFAULT_ZONE_CUSTOMIZE_SCRIPT_SOURCE 
##   default customize script for the zone
##   Possible values for this variabe are:
##       "builtin", "none", or the name of an existing script
##   The customize script runs inside the new zone
##   while first rebooting the zone
##
  DEFAULT_ZONE_CUSTOMIZE_SCRIPT_SOURCE="builtin"

## DEFAULT_ZONE_CUSTOMIZE_SCRIPT_TARGET
##   fully qualified name of the customize script inside the zone
##
##   Note: The runlevel in which the script runs depends on the path of the
##         customize scripts
##         The default is rc3.d = multi-user-server
##      
  DEFAULT_ZONE_CUSTOMIZE_SCRIPT_TARGET="/etc/rc3.d/S99customize_script"

## DEFAULT_ZONE_SMF_PROFILE
##   SMF site profile for the zone; default: none
##
  DEFAULT_ZONE_SMF_PROFILE=""

## DEFAULT_ZONE_IP_ADDRESS 
##   there is no default IP address for the zone
##
  DEFAULT_ZONE_IP_ADDRESS=""

## DEFAULT_ZONE_IP_STACK
##   this can be either SHARED or EXCLUSIVE; the default is SHARED
##
  DEFAULT_ZONE_IP_STACK="SHARED"

## DEFAULT_ZONE_NETMASK
##  netmask for the zone (only used for zones with exclusive IP stack!)
##
  DEFAULT_ZONE_NETMASK=""
 
## DEFAULT_ZONE_DEFAULT_ROUTER
##  default router for the zones
##  Note: A default router for a zone can only be configured for zones in Solaris 10 Update 6 and newer
##
  DEFAULT_ZONE_DEFAULT_ROUTER=""
#  $(  netstat -rn | grep "^default" | tr -s " " | cut -f2 -d " " | head -1 )"
 
## ZONE_GLDV3_CHECK
##   Do check the GLDv3 capabiltiy (yes, default) of the network adapter or not (no)
##
   DEFAULT_ZONE_GLDV3_CHECK="yes"

## DEFAULT_ZONE_NAME
##   there is no default name for the zone
##
  DEFAULT_ZONE_NAME=""

## DEFAULT_ZONE_GLOBAL_OPTIONS
##   additional global options for the zone
##   (e.g. bootargs, pool, limitpriv, etc)
##   Please note that the script DOES not check the syntax or semantic for these entries!
##
   DEFAULT_ZONE_GLOBAL_OPTIONS=""
  
## DEFAULT_USE_EXISTING_NAMESERVER_CONFIG
##   default nameserver configuration is:
##     use the existing nameserver configuration
##
  DEFAULT_USE_EXISTING_NAMESERVER_CONFIG=${__TRUE}

## DEFAULT_ZONE_AUTOBOOT
##   enable zone autoboot?; default is false
##
  DEFAULT_ZONE_AUTOBOOT=${__FALSE}
 
## DEFAULT_ZONE_NETWORK_INTERFACE
##   the default network interface for the zone
##   The default is the network interface which hosts the
##   network with the IP address for the zone
##
  DEFAULT_ZONE_NETWORK_INTERFACE=""

## DEFAULT_BOOT_THE_ZONE_NOW
##   boot the zone after installation?
##
  DEFAULT_BOOT_THE_ZONE_NOW=${__FALSE}

## DEFAULT_ZONE_MEMORY_LIMIT
##   the memory limit for the zone
##   There is no default for this keyword
##   Note that this configuration is only supported in
##   Solaris 10 8/07 and newer!
## 
  DEFAULT_ZONE_MEMORY_LIMIT=""

## DEFAULT_ZONE_SWAP_LIMIT
##   the swap limit for the zone
##   There is no default for this keyword
##   Note that this configuration is only supported in
##   Solaris 10 8/07 and newer!
##
  DEFAULT_ZONE_SWAP_LIMIT=""

## DEFAULT_ZONE_CPU_COUNT
##   the number of CPUs for the zone
##   There is no default for this keyword
##   Note that this configuration is only supported in
##   Solaris 10 8/07 and newer!
##
  DEFAULT_ZONE_CPU_COUNT=""

## DEFAULT_ZONE_CPU_SHARES
##   the number of CPU shares for the zone
##   There is no default for this keyword
##   Note that this configuration is only supported in
##   Solaris 10 8/07 and newer!
##
  DEFAULT_ZONE_CPU_SHARES=""

## DEFAULT_ZONE_INHERITED_DIRS
##   add. directories that should be inherited by the zone
##   Note: Directories with space or tabs in the name are NOT supported!
##
   DEFAULT_ZONE_INHERITED_DIRS=""

## DEFAULT_ZONE_WRITABLE_DIRS
##   directories that should be mounted r/w in the zone
##   Format of the entries:
##      zone_dir:global_dir
##   Note: Directories with space or tabs in the name are NOT supported!
##
   DEFAULT_ZONE_WRITABLE_DIRS=""

## DEFAULT_ZONE_READONLY_DIRS
##   directories that should be mounted r/o in the zone
##   Format of the entries:
##      zone_dir:global_dir
##   Note: Directories with space or tabs in the name are NOT supported!
##
   DEFAULT_ZONE_READONLY_DIRS=""

## DEFAULT_ZONE_DATASETS
##   ZFS datasets for the zone
##
   DEFAULT_ZONE_DATASETS=""

## DEFAULT_ZONE_DEVICES
##
  DEFAULT_ZONE_DEVICES=""
 
## DEFAULT_EDIT_ZONE_CONFIG
##   edit the zone configuration before creating the zone
##   after exiting the editor the user can choose to continue
##   or to abort the zone installation
##
  DEFAULT_EDIT_ZONE_CONFIG=${__FALSE}

## DEFAULT_ZONE_TEMPLATE_DIRS
##   Template directories for the zone; all files and directories in the
##   directories listed in this variable are copied to the root dir of the
##   zone
  if [ -d "${DEFAULT_ZONE_PATH}/template_dir" ] ; then
    ZONE_TEMPLATE_DIRS="${DEFAULT_ZONE_PATH}/template_dir"
  else
    ZONE_TEMPLATE_DIRS=""
  fi

## DEFAULT_ZONE_FINISH_SCRIPT
##
##   finish script for creating the zone
##   This script is called in the global zone after the new
##   zone is created and configured but before it is booted
##   The parameters for the script are
##     - the fully qualified name of the directory for the zone
##
##   Note: Please write your finish scripts so that they handle multiple parameter correct
##         because there may be additional parameter in a future version of this script!
##
##   The finish script must return 0 if everything is okay; everthing else
##   is interpreted as error and the zone creation is aborted
##
##   Note that you can change the configuration of the zone from within the finish script
##   with a few exceptions (e.g. you can NOT add directories to inherit here)
##
##   All environment variables beginning with ZONE_ are exported and can be used by the
##   finish script. The exported variables are:
##
##     ZONE_AUTOBOOT
##     ZONE_CLONE_SOURCE
##     ZONE_CUSTOMIZE_SCRIPT_CONTENTS
##     ZONE_CUSTOMIZE_SCRIPT_SOURCE
##     ZONE_CUSTOMIZE_SCRIPT_TARGET
##     ZONE_FINISH_SCRIPT
##     ZONE_IP_ADDRESS
##     ZONE_LOCALE
##     ZONE_MODE
##     ZONE_NAME
##     ZONE_NETWORK_INTERFACE
##     ZONE_PATH
##     ZONE_ROOT_PASSWORD
##     ZONE_SMF_PROFILE
##     ZONE_TERMINAL
##     ZONE_TIMESERVER
##     ZONE_TZ
##     ZONE_IP_STACK
##     ZONE_NETMASK
##     ZONE_DEFAULT_ROUTER
##     ZONE_MEMORY_LIMIT
##     ZONE_SWAP_LIMIT
##     ZONE_CPU_COUNT
##     ZONE_CPU_SHARES
##     ZONE_INHERITED_DIRS
##     ZONE_WRITABLE_DIRS
##     ZONE_READONLY_DIRS
##     ZONE_DATASETS
##     ZONE_GLDV3_CHECK
##     ZONE_GLOBAL_OPTIONS
##     ZONE_DEVICES
##     ZONE_TEMPLATE_DIRS
##
##
  DEFAULT_ZONE_FINISH_SCRIPT=""

## DEFAULT_ZONE_CUSTOMIZE_SCRIPT_CONTENTS
##   builtin customize script for the zones
##   The customize script runs inside the new zone while first
##   booting the zone
##
  DEFAULT_ZONE_CUSTOMIZE_SCRIPT_CONTENTS="
  echo \"Customization of the zone is running ...\"

  echo \"Disabling sendmail ...\"
  svcadm disable sendmail

  echo \" ... customization done. Removing the customize script\"
  rm \$0
"
 
# only change the following variables if you know what you are doing #


# no further internal variables defined yet
#
# Note you can redefine any variable that is initialized before calling
# ReadConfigFile here!







Back to top

Notes

Please see the source code of the script for additional information



Back to top

Download


Download create_zone.sh




Back to top