Solaris Zones Tutorial
Solaris Zones Tutorial
Disclaimer: Instructions provided in this tutorial have been validated on the Solaris 10 5/08 release. Changes may be required to replicate the provided scenarios on Solaris releases other than 10 5/08.
Contents
Introduction................................................................................................................................................... 2 The Global Zone............................................................................................................................................. 2 Setting up a File System for the Zone............................................................................................................ 2 Zone Configuration ........................................................................................................................................ 3 Zone Installation ............................................................................................................................................ 5 Booting the Zone ........................................................................................................................................... 6 DNS configuration for the zone ................................................................................................................... 16 Halting a zone .............................................................................................................................................. 16 Uninstalling a non-global zone .................................................................................................................... 16 Deleting a non-global zone.......................................................................................................................... 17 Deleting the zone specific file system ......................................................................................................... 17 Further Reading ........................................................................................................................................... 18 Official Documentation from Oracle ....................................................................................................... 18 Documentation regarding commands .................................................................................................... 18 Appendix - Useful commands...................................................................................................................... 19 Processor Information ............................................................................................................................. 19 Memory Information ............................................................................................................................... 19 Operating System Information ................................................................................................................ 19 Process Information ................................................................................................................................ 19 Adjusting resources for a running zone .................................................................................................. 19
Introduction
In this tutorial, we will create a non-global zone called my-zone, with the following allocated resources: 1 dedicated CPU A limit of maximum 1000 Light-weight Processes (LWPs) 100MB of main memory 512MB of swap memory Fair Share Scheduler 2GB of hard disk space Network with a dedicated IP address
The following sections will illustrate how to configure and boot the zone, and also certain post-boot DNS configurations. We will also go over the steps to uninstall and delete a non-global zone.
root@tb3:~# newfs /dev/lofi/1 /dev/rlofi/1: Unable to find Media type. Proceeding with system determined parameters. newfs: construct a new file system /dev/rlofi/1: (y/n)? y /dev/rlofi/1: 4194000 sectors in 6990 cylinders of 1 tracks, 600 sectors 2047.9MB in 219 cyl groups (32 c/g, 9.38MB/g, 2368 i/g) super-block backups (for fsck -F ufs -o b=#) at: 32, 19232, 38432, 57632, 76832, 96032, 115232, 134432, 153632, 172832, 4012832, 4032032, 4051232, 4070432, 4089632, 4108832, 4128032, 4147232, 4166432, 4185632 The final step is to mount the file system. But before we do that, lets create a suitable mount point: root@tb3:~# mkdir /mnt/myzone_fs Now we can mount the file system on this mount point: root@tb3:~# mount /dev/lofi/1 /mnt/myzone_fs We can verify the mounted partition as: root@tb3:~# df -k /mnt/myzone_fs Filesystem /dev/lofi/1 kbytes 2028652 used 2065 avail 1965728 capacity 1% Mounted on /mnt/myzone_fs
We now have a UFS file system that is limited to 2GB. However, before we can use this as a zones root file system, we have to set the appropriate permissions: root@tb3:~# chmod 700 /mnt/myzone_fs This is important since the zoneadm command generates an error otherwise.
Zone Configuration
The following set of commands is used to create a non-global zone with the previously mentioned resource constraints. root@tb3:~# zonecfg -z my-zone my-zone: No such zone configured Use 'create' to begin configuring a new zone. 3
zonecfg:my-zone> create zonecfg:my-zone> set zonepath=/mnt/myzone_fs This is where the zone will be created. The above mentioned path points to the file system we mounted earlier. This restricts the zone size to the size of this file system (i.e. 2GB in this case). zonecfg:my-zone> set max-lwps=1000 The maximum number of LWPs that can be created in this zone. zonecfg:my-zone> add dedicated-cpu zonecfg:my-zone:dedicated-cpu> set ncpus=1 zonecfg:my-zone:dedicated-cpu> end One CPU is dedicated to this zone. Please note that the zone cannot be booted if a dedicated CPU is not available. Also, on a multi-processor machine, only 1 CPU will be visible to the zone. zonecfg:my-zone> add capped-memory zonecfg:my-zone:capped-memory> set physical=100m zonecfg:my-zone:capped-memory> set swap=512m zonecfg:my-zone:capped-memory> end Memory constraints for the available physical and swap memory. zonecfg:my-zone> set scheduling-class=FSS The zone will use a Fair Share Scheduler. zonecfg:my-zone> set ip-type=shared The ip-type parameter supports two types i.e. shared and explicit. Here, we will consider the shared type. For the shared ip-type, the IP layer configuration and state is shared between the non-global and the global zone. zonecfg:my-zone> add net zonecfg:my-zone:net> set address=141.89.226.31 zonecfg:my-zone:net> set physical=ce0 zonecfg:my-zone:net> end
By adding a network resource, we have provided the zone with a unique IP address, so that the zone can be uniquely identified from the outside world. That is, even though the IP layer state and configuration are shared with the global zone, traffic can still be routed explicitly to the non-global zone. zonecfg:my-zone> add attr zonecfg:my-zone:attr> set name=comment zonecfg:my-zone:attr> set type=string zonecfg:my-zone:attr> set value="Server OS - Demo zone" zonecfg:my-zone:attr> end This is just a comment. zonecfg:my-zone> verify The verify command is used to ensure correctness of the configuration. However, certain aspects (e.g. path to the file system) can only be verified during zone installation. Please note that these paths must have been created prior to installing the zone. zonecfg:my-zone> commit zonecfg:my-zone> exit
Zone Installation
Once the zone has been configured, the next step is to install the zone: root@tb3:~# zoneadm -z my-zone install Preparing to install zone <my-zone>. Creating list of files to copy from the global zone. Copying <14339> files to the zone. Initializing zone product registry. Determining zone package initialization order. Preparing to initialize <1203> packages on the zone. Initialized <1203> packages on zone. Zone <my-zone> is initialized. Installation of <1> packages was skipped. 5
Once all the services have been configured, interactive configuration options will be displayed. First is the language selection: Select a Language
0. English 1. German 2. es 3. fr
Please make a choice (0 - 3), or press h or ? for help: 0 Here we have chosen English. Next we select the Locale:
Select a Locale
0. English (C - 7-bit ASCII) 1. Canada (English) (UTF-8) 2. Canada-English (ISO8859-1) 3. Czech Republic (ISO8859-2) 4. Czech Republic (UTF-8 + euro) 5. Czech Republic (UTF-8) 6. Hungary (ISO8859-2) 7. Hungary (UTF-8) 8. Poland (ISO8859-2) 9. Poland (UTF-8) 10. Slovakia (ISO8859-2) 11. Slovakia (UTF-8) 12. U.S.A. (UTF-8) 13. U.S.A. (en_US.ISO8859-1) 14. U.S.A. (en_US.ISO8859-15) 15. Go Back to Previous Screen
What type of terminal are you using? 1) ANSI Standard CRT 2) DEC VT52 3) DEC VT100 4) Heathkit 19 5) Lear Siegler ADM31 6) PC Console 7) Sun Command Tool 8) Sun Workstation 9) Televideo 910 10) Televideo 925 11) Wyse Model 50 12) X Terminal Emulator (xterms) 13) CDE Terminal Emulator (dtterm) 14) Other Type the number of your choice and press Return: 3
Creating new rsa public/private host key pair Creating new dsa public/private host key pair Configuring network interface addresses: ce0.
q Host Name for ce0:7 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Enter the host name which identifies this system on the network. The name must be unique within your domain; creating a duplicate host name will cause problems on the network after you install Solaris. A host name must have at least one character; it can contain letters, digits, and minus signs (-). Host name for ce0:7 my-zone
Specify Yes if the system will use the Kerberos security mechanism. Specify No if this system will use standard UNIX security. Configure Kerberos Security qqqqqqqqqqqqqqqqqqqqqqqqqqq [ ] Yes [X] No
Here have chosen to use the standard UNIX security. The next step is the naming service configuration. We will configure the NIS. 9
q Name Service qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq On this screen you must provide name service information. Select the name service that will be used by this system, or None if your system will either not use a name service at all, or if it will use a name service not listed here. > To make a selection, use the arrow keys to highlight the option and press Return to mark it [X]. Name service qqqqqqqqqqqq [ ] NIS+ [X] NIS [ ] DNS [ ] LDAP [ ] None
q Domain Name qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq On this screen you must specify the domain where this system resides. Make sure you enter the name correctly including capitalization and punctuation. Domain name: asg-platform.org
q Name Server qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq On this screen you must specify how to find a name server for this system. You can let the software try to find one, or you can specify one. The software can find a name server only if it is on your local subnet. > To make a selection, use the arrow keys to highlight the option and press Return to mark it [X]. Name server qqqqqqqqqqqqqqq [ ] Find one [X] Specify one
Configure the name server: q Name Server Information qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq On this screen you must enter the host name and IP address of your name server. Host names must be at least two characters, and may contain letters, digits, and minus signs (-). IP addresses must contain four sets of numbers separated by periods (for example 129.200.9.1).
Next: q NFSv4 Domain Name qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq NFS version 4 uses a domain name that is automatically derived from the system's naming services. The derived domain name is sufficient for most configurations. In a few cases, mounts that cross domain boundaries might cause files to appear to be owned by "nobody" due to the lack of a common domain name. The current NFSv4 default domain is: "org"
NFSv4 Domain Configuration qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq [X] Use the NFSv4 domain derived by the system [ ] Specify a different NFSv4 domain
12
q Time Zone qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq On this screen you must specify your default time zone. You can specify a time zone in three ways: select one of the continents or oceans from the list, select other - offset from GMT, or other specify time zone file. > To make a selection, use the arrow keys to highlight the option and press Return to mark it [X]. Continents and Oceans qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq x x x x x x x v [ ] Africa [ ] Americas [ ] Antarctica [ ] Arctic Ocean [ ] Asia [ ] Atlantic Ocean [ ] Australia [X] Europe [ ] Indian Ocean
Next:
13
q Country or Region qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq > To make a selection, use the arrow keys to highlight the option and press Return to mark it [X].
Countries and Regions qqqqqqqqqqqqqqqqqqqqqqqq ^ x x x x x x x x x x x v [ ] Bosnia & Herzegovina [ ] Britain (UK) [ ] Bulgaria [ ] Croatia [ ] Czech Republic [ ] Denmark [ ] Estonia [ ] Europe - Central [ ] Europe - Eastern [ ] Europe - Western [ ] Finland [ ] France [X] Germany
We can how set a password for this non-global zones root use. Please note that this root is not associated with the global zones root in anyway:
14
q Root Password qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq Please enter the root password for this system. The root password may contain alphanumeric and special characters. For security, the password will not be displayed on the screen as you type it. > If you do not want a root password, leave both entries blank.
*********** ***********
After successful configuration, the zone will reboot: System identification is completed. rebooting system due to change(s) in /etc/default/init
[NOTICE: Zone rebooting] SunOS Release 5.10 Version Generic_127127-11 64-bit Copyright 1983-2008 Sun Microsystems, Inc. Use is subject to license terms. Hostname: my-zone NIS domain name is asg-platform.org All rights reserved.
Halting a zone
The following command can be used to safely shut down a running non-global zone from the global zone: root@tb3:~# zlogin my-zone shutdown -y g0 -i 0 Shutdown started. Fri Jul 15 18:51:42 CEST 2011
The following command can be used to forcefully halt the zone: root@tb3:~# zoneadm -z my-zone halt The non-global zone should now be in the installed state. The following command can be used to verify the zones state: root@tb3:~# zoneadm list -iv ID NAME 0 global - my-zone STATUS running installed PATH / /export/home/my-zone BRAND native native IP shared shared
root@tb3:~# zoneadm -z my-zone uninstall Are you sure you want to uninstall zone my-zone (y/[n])? y
17
Further Reading
Official Documentation from Oracle
The most significant resource is the System Administration Guide: Oracle Solaris Containers-Resource Management and Oracle Solaris Zones: http://download.oracle.com/docs/cd/E19455-01/817-1592/index.html Part II of the guide is a detailed administration guide for Zones. Consolidating Applications with Oracle Solaris Containers http://www.oracle.com/us/products/servers-storage/solaris/consolid-solaris-containers-wp075578.pdf Fair Share Scheduler (Overview): http://download.oracle.com/docs/cd/E1996301/html/821-1460/rmfss-1.html
18
psrinfo p psrinfo v
Memory Information
Process Information
ps ef ps efZ ps fz my-zone (all processes) (all processes along with the corresponding zone names) (all processes associated with my-zone)
19