Solaris ZonesObjectives: Explain consolidation issues and features of Solaris zones, and decipher between the different zone concepts including zone types, daemons, networking, command scope, and given a scenario, create a Solaris zone.
The zones technology provides virtual operating system services to allow applications to run in an isolated and secure environment. A zone is a virtual environment that is created within a single running instance of the Solaris Operating Environment. Applications running in a zone environment cannot affect applications running in a different zone, even though they exist and run on the same physical server. Even a privileged user in a zone cannot monitor or access processes running in a different zone. Types of ZonesThere are two types of zones, global and non-global. Think of a global zone as the server itself, the traditional view of a Solaris system as we all know it, where you can login as root and have full control of the entire system. The global zone is the default zone and is used for system-wide configuration and control. Every system contains a global zone and there can only be one global zone on a physical Solaris server. A non-global zone is created from the global zone and also managed by it. You can have up to 8192 non-global zones on a single physical systemthe only real limitation is the capability of the server itself. Applications that run in a non-global zone are isolated from applications running in a separate non-global zone, allowing multiple versions of the same application to run on the same physical server. Zone StatesNon-global zones are referred to simply as zones and can be in a number of states depending on the current state of configuration or readiness for operation. You should note that zone states only refer to non-global zones because the global zone is always running and represents the system itself. The only time the global zone is not running is when the server has been shut down. Table 13.1 describes the six states that a zone can be in: Exam Alert Know Your Zone States There is often at least one question in the exam relating to different zone states. Pay particular attention to the differences between the configured, installed, ready, and running states. You may get a question that asks you to match the correct state to the correct description. Zone FeaturesThis section describes the features of both the global zone and non-global zones. The global zone has the following features:
Non-global zones have the following features:
Non-Global Zone Root File System ModelsA non-global zone contains its own root (/) file system. The size and contents of this file system depend on how you configure the global zone and the amount of configuration flexibility that is required. There is no limit on how much disk space a zone can use, but the zone administrator, normally the system administrator, must ensure that sufficient local storage exists to accommodate the requirements of all non-global zones being created on the system. The system administrator can restrict the overall size of the non-global zone file system by using any of the following:
Sparse Root ZonesWhen you create a non-global zone, you have to decide how much of the global zone file system you want to be inherited from the global zone. A sparse root zone optimizes sharing by implementing read-only loopback file systems from the global zone and only installing a subset of the system root packages locally. The majority of the root file system is shared (inherited) from the global zone. Generally this model would require about 100 Megabytes of disk space when the global zone has all of the standard Solaris packages installed. A sparse root zone uses the inherit-pkg-dir resource, where a list of inherited directories from the global zone are specified. Whole Root ZonesThis model provides the greatest configuration flexibility because all of the required (and any other selected) Solaris packages are copied to the zone's private file system, unlike the sparse root model where loopback file systems are used. The disk space requirement for this model is considerably greater and is determined by evaluating the space used by the packages currently installed in the global zone. Networking in a Zone EnvironmentOn a system supporting zones the zones can communicate with each other over the network, but even though the zones reside on the same physical system, network traffic is restricted so that applications running on a specified zone cannot interfere with applications running on a different zone. Each zone has its own set of bindings and zones can all run their own network daemons. As an example, consider three zones all providing web server facilities using the apache package. Using zones, all three zones can host websites on port 80, the default port for http TRaffic, without any interference between them. This is because the IP stack on a system supporting zones implements the separation of network traffic between zones. The only interaction allowed is for ICMP traffic to resolve problems, so that commands such as ping can be used to check connectivity. Of course, when a zone is running, it behaves like any other Solaris system on the network in that you can telnet or ftp to the zone as if it was any other system, assuming the zone has configured these network services for use. When a zone is created, a dedicated IP address is configured that identifies the host associated with the zone. In reality though, the zone's IP address is configured as a logical interface on the network interface specified in the zone's configuration parameters. Only the global zone has visibility of all zones on the system and can also inspect network traffic, using for example, snoop. Zone DaemonsThe zone management service is managed through the Service Management Facility (SMF), the service identifier is called: svc:/system/zones:default There are two daemon processes associated with zones, zoneadmd and zsched. The zoneadmd daemon starts when a zone needs to be managed. An instance of zoneadmd will be started for each zone, so it is not uncommon to have multiple instances of this daemon running on a single server. It is started automatically by SMF and is also shut down automatically when no longer required. The zoneadmd daemon carries out the following actions:
The zsched process is started by zoneadmd and exists for each active zone (a zone is said to be active when in the ready, running, or shutting down state. The job of zsched is to keep track of kernel threads running within the zone. It is also known as the zone scheduler. Configuring a ZoneBefore a zone can be installed and booted it has to be created and configured. This section deals with the initial configuration of a zone and describes the zone components. A zone is configured using the zonecfg command. The zonecfg command is also used to verify that the resources and properties that are specified during configuration are valid for use on a Solaris system. zonecfg checks that a zone path has been specified and that for each resource, all of the required properties have been specified. The zonecfg CommandThe zonecfg command is used to configure a zone. It can run interactively, on the command-line, or using a command-file. A command-file is created by using the export subcommand of zonecfg. zonecfg carries out the following operations:
When you enter zonecfg in interactive mode, the prompt changes to show that you are in a zonecfg session. If you are configuring a zone called apps, then the prompt changes as follows: # zonecfg -z apps zonecfg:apps> This is known as the global scope of zonecfg. When you configure a specific resource, the prompt changes to include the resource being configured. The command scope also changes so that you are limited to entering commands relevant to the current scope. You have to enter an end command to return to the global scope. Table 13.2 describes the subcommands that are available with the interactive mode of zonecfg: Table 13.3 lists the resource types that are applicable to the zonecfg command:
Some of the resource types described in Table 13.3 also have properties that need to be configured if the resource type is to be used. The following list describes the properties and the parameters, along with examples of usage:
Viewing the Zone ConfigurationThe zone configuration data can be viewed in two ways:
Both of these are described here: The zone configuration file is held in the /etc/zones directory and is stored as an xml file. To view the configuration for a zone named testzone, you would enter: # cat /etc/zones/testzone.xml The alternative method of viewing the configuration is to use the zonecfg command with the export option. The following example shows how to export the configuration data for zone testzone: # zonecfg -z testzone export By default, the output goes to stdout, but this can be changed by entering a filename instead. If you save the configuration to a file, then it can be used at a later date, if required, as a command file input to the zonecfg command. This option is useful if you have to recreate the zone for any reason. Installing a ZoneWhen a zone has been configured, the next step in its creation is to install it. This has the effect of copying the necessary files from the global zone and populating the product database for the zone. You should verify a configuration before it is installed to ensure that everything is set up correctly. To verify the zone configuration for a zone named testzone enter the following command: zoneadm -z testzone verify If, for example, the zonepath does not exist, or it has not had the correct permissions set, then the verify operation will generate a suitable error message. When the zone has been successfully verified it can be installed, as follows: zoneadm -z testzone install A number of status and progress messages are displayed on the screen as the files are copied and the package database is updated. Notice that whilst the zone is installing, its state will change from configured to incomplete. The state will change to installed when the install operation has completed. Booting a ZoneBefore issuing the boot command, a zone needs to be transitioned to the ready state. This can be done using the zoneadm command as follows: zoneadm -z testzone ready The effect of the ready command is to establish the virtual platform, plumb the network interface and mount any file systems. At this point though, there are no processes running. To boot the zone testzone, issue the following command: zoneadm -z testzone boot Confirm that the zone has booted successfully by listing the zone using the zoneadm command as follows: zoneadm -z testzone list -v The state of the zone will have changed to running if the boot operation was successful. Note No Need to Ready If you want to boot a zone, then there is no need to transition to the ready state. The boot operation does this automatically prior to booting the zone. Halting a ZoneTo shut down a zone, issue the halt option of the zoneadm command as shown in the following: zoneadm -z testzone halt The zone state changes from running to installed when a zone is halted. Rebooting a ZoneA zone can be rebooted at any time without affecting any other zone on the system. The reboot option of the zoneadm command is used to reboot a zone as shown here to reboot the zone testzone: zoneadm -z testzone reboot The state of the zone should be running when the reboot operation has completed. Uninstalling a ZoneWhen a zone is no longer required, it should be uninstalled before it is deleted. In order to uninstall a zone, it must first be halted. When this has been done, issue the uninstall command as shown here to uninstall the zone testzone: zoneadm -z testzone uninstall -F The -F option forces the command to execute without confirmation. If you omit this option, then you will be asked to confirm that you wish to uninstall the zone. Deleting a ZoneWhen a zone has been successfully uninstalled, its configuration can be deleted from the system. Enter the zonecfg command as shown here to delete the zone testzone from the system: zonecfg -z testzone delete -F The -F option forces the command to execute without confirmation. If you omit this option, then you will be asked to confirm that you wish to delete the zone configuration. Exam Alert Remember the Force Unlike most other Unix commands, zoneadm and zonecfg use an uppercase letter F to force the command to be executed without prompting you for confirmation. All other commands, such as mv, rm, and umount, for example, always use a lowercase letter f. Make sure you are aware of this anomaly when you sit for the exam. Zone LoginWhen a zone is operational and running, the normal network access commands can be used to access a zone, such as telnet, rlogin, and ssh, but a non-global zone can also be accessed from the global zone using zlogin command. This is necessary for administration purposes and to be able to access the console session for a zone. Only the Superuser (root), or a role with the RBAC profile "Zone Management" can use the zlogin command from the global zone. The syntax for the zlogin command is as follows: zlogin [-CE] [-e c] [-l username] zonename zlogin [-ES] [-e c] [-l username] zonename utility [argument...] zlogin works in three modes:
Table 13.4 describes the various options for zlogin: Initial Zone LoginWhen a zone has been installed and is booted for the first time, it is still not fully operational because the internal zone configuration needs to be completed. This includes setting the following:
These settings are configured interactively the first time you use zlogin to connect to the zone console, similar to when you first install the Solaris 10 Operating Environment. The zone then reboots to implement the changes. When this reboot completes, the zone is fully operational. Note Initial Console Login You must complete the configuration by establishing a console connection. If this is not completed, the zone will not be operational and users will be unable to connect to the zone across the network. Using a sysidcfg FileInstead of completing the zone configuration interactively, you can pre-configure the required options in a sysidcfg file. This enables the zone configuration to be completed without intervention. The sysidcfg file needs to be placed in the /etc directory of the zone's root. For a zone named testzone with a zonepath of /export/zones/testzone, the sysidcfg file would be placed in /export/zones/testzone/root/etc. The following example of a sysidcfg file sets the required parameters, but doesn't use a naming service, or a security policy. Note that the root password entry needs to include the encrypted password: lang=C system_locale=en_GB terminal=vt100 network_interface=primary { hostname=testzone } security_policy=NONE name_service=NONE timezone=GB root_password=dKsw26jNk2CCE There is one other question that is asked by the zone configuration utility, relating to NFS version 4 domain parameter. To complete a hands-off configuration, create the following file in the zone's root/etc directory: # touch /export/zones/testzone/root/etc/.NFS4inst_state.domain This file indicates that the NFSv4 domain has been set, so you don't get asked to confirm it. Note Install sysidcfg Before Boot You need to install the sysidcfg file and create the .NFS4inst_state.domain file before the initial boot of the zone, otherwise the files will be ignored and you will have to complete the zone setup interactively. Logging in to the Zone ConsoleYou can access the console of a zone by using the zlogin -C <zonename> command. If you are completing a hands-off configuration, connect to the console before the initial boot and you will see the boot messages appear in the console as well as the reboot after the sysidcfg file has been referenced. The following session shows what happens when the zone testzone is booted for the first time, using a sysidcfg file: # zlogin -C testzone
[NOTICE: Zone readied]
[NOTICE: Zone booting up]
SunOS Release 5.10 Version Generic 64-bit
Copyright 1983-2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
Hostname: testzone
Loading smf(5) service descriptions: 100/100
Creating new rsa public/private host key pair
Creating new dsa public/private host key pair
rebooting system due to change(s) in /etc/default/init
[NOTICE: Zone rebooting]
SunOS Release 5.10 Version Generic 64-bit
Copyright 1983-2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
Hostname: testzone
testzone console login: Logging in to a ZoneThe Superuser (root), or a role with the RBAC profile "Zone Management", can log directly into a zone from the global zone, without having to supply a password. The system administrator uses the zlogin command; the following example shows a zone login to the testzone zone, the command zonename is run and then the connection is closed: # zlogin testzone [Connected to zone 'testzone' pts/6] Sun Microsystems Inc. SunOS 5.10 Generic January 2005 # zonename testzone # exit [Connection to zone 'testzone' pts/6 closed] Running a Command in a ZoneIn the previous section an interactive login to a zone was achieved. Here, a non-interactive login is actioned and a single command is executed. The connection is automatically disconnected as soon as the command has completed. The following example shows how this works. First, the hostname command is run, demonstrating that we are on the host called global, then a non-interactive login to the testzone zone runs, which runs the zonename command and then exits automatically. Finally, the same hostname command is run, which shows we are back on the host called global: # hostname global # zlogin testzone zonename testzone # hostname global Exam Alert No -z in zlogin Be careful not to include the -z option when answering questions on zlogin in the exam. It's easy to get confused with the zoneadm command, where the -z option IS used. Creating a ZoneNow that we have seen the technicalities of configuring a zone, let's put it all together and create a zone. Step by Step 13.1 configures the zone named testzone, installs it and boots it. Finally, we will list the zone configuration data. Exam Alert Zone Configuration File You can also view the configuration file directly by viewing /etc/zones/<zonename>.xml. This file is created when you save the configuration using zonecfg. You might be asked this location in the exam. ![]() |