Professional Documents
Culture Documents
The Zone Manager: Simplifying The Creation and Management of Solaris 10 Zones
The Zone Manager: Simplifying The Creation and Management of Solaris 10 Zones
Brad Diggs
Senior Directory Architect
Sun Microsystems, Inc.
Purpose
2
Agenda
3
Solaris Zones Today
4
Solaris Zones Virtualization
A Solaris zone is a virtual semi-shared instance of the Solaris operating
system that in almost every way feels like an autonomous system. Unlike
other virtualization systems such as VMware, Xen and others, zones
share system resources (CPU, RAM, Disk, and Network) instead of
pre-allocating fixed portions of these resources for each virtual container.
Private Solaris 10 Global Zone
Network1
192.168.10.0/24 Sparse Root zfs1
Zone m1
Minimized and
Private Hardened /share
Network2 Whole Root (ro)
192.168.20.0/24 Zone m2
/data
DSEE (rw)
Public
Network apache zfs2
72.5.124.0/24
5
Sparse and Whole Root Zones
Sparse root zones are non-global zones that inherit in read-only mode the /lib,
/platform, /sbin, and /usr directories from the global zone.
Whole root zones are non-global zones that do not inherit any directories from the
global zone.
To create a whole root zone, you include the following lines in the zone configuration
file to force non-inheritance of the default directories.
6
Sparse Root Zones
• Advantages of Sparse Root Zones
> Consumes less RAM and Disk
> Easier to manage software updates
7
Whole Root Zones
• Advantages of Whole Root Zones
> Can control package list (add/remove) of non-global zone
> Can minimize non-global zone
> Can have truly minimized global zone
8
Sparse Zone Example
9
Sparse Zone Configuration File
create
set zonepath=/zone/zone1
set autoboot=true
add inherit-pkg-dir
set dir=/ds
end
add net
set address=192.168.1.11
set physical=hme0
end
add attr
set name=comment
set type=string
set value="Directory Service Zone"
end
verify
commit
10
Sparse Zone Installation
Installing the zone from zone configuration file (zone1.inf):
# zonecfg -z zone1 -f ./zone1.inf
# zoneadm -z zone1 install
Preparing to install zone <zone1>.
Creating list of files to copy from the global zone.
Copying <2502> files to the zone.
Initializing zone product registry.
Determining zone package initialization order.
Initializing package <5> of <690>: percent complete: 0%
... continues until 100% complete and takes a while...
Initialized <690> packages on zone.
Successfully initialized zone <zone1>.
# zoneadm -z zone1 boot
# zoneadm list -vc
ID NAME STATUS PATH
0 global running /
1 zone1 running /zone/zone1
# zlogin -C -e\@ zone1
11
Zones Today Can Get Complicated
Zone Configuration – sparse, whole root, fs, net, ...
Zones Administration – zonecfg, zoneadm, zlogin
Zone State Management – boot, reboot, shutdown, only X zones, ...
Minimization – pkgrm, pkgadd, ...
Hardening – svcadm, svcs, inetadm, /etc/rcX.d, ...
Filesystems – mount, newfs, zpool, zfs
Containment/Resource Management – pset, rcapd, ...
Privileges – Apply zone specific privilege constraints
brandZ – Linux binary compatible zone
Automated Software Installation – Blastwave (pkg-get)
12
Necessity: The Mother of Invention
13
ZoneMgr Actions
add – Add a zone
modify – Modify an existing zone
del – Delete a zone
info – Show zone configuration
move – Move a zone from one dir to another
detach/attach – Move a zone from one server to another
clone – Clone the configuration and contents of a zone
boot/reboot/shutdown/halt – Start/Restart/Stop a zone
only – Manage multi-zone state
runcmd – Run a command within a zone
zcontainer – Apply containment to a zone
14
ZoneMgr by Examples
15
ZoneMgr by Example 1:
add, delete, and list
16
ZoneMgr by Example 1:
add, delete, and list
Add a zone:
Create zone config file file: zcfgfile
zonecfg -z m1 -f zcfgfile
zoneadm -z m1 install
zoneadm -z m1 boot
zlogin -C m1 # Manually answer the SysIdCfg questions
Delete a zone:
zoneadm -z m1 halt
zoneadm -z m1 uninstall -F
zonecfg -z m1 delete -F
17
ZoneMgr by Example 1:
add, delete, and list
Add a zone:
zonemgr -a add -n m1 -z /zones -P pw
Delete a zone:
zonemgr -a del -n m1
18
ZoneMgr by Example 2:
boot, reboot, shutdown, and halt
19
ZoneMgr by Example 2:
boot, reboot, shutdown, and halt
Boot a zone:
zoneadm -z m1 boot
Reboot a zone:
zoneadm -z m1 reboot
Shutdown a zone:
zlogin m1 “shutdown -y -g 0 -i 5”
Halt a zone:
zoneadm -z m1 halt
20
ZoneMgr by Example 2:
boot, reboot, shutdown, and halt
Boot a zone:
zonemgr -a boot -n m1
Reboot a zone:
zonemgr -a reboot -n m1
Shutdown a zone:
zonemgr -a shutdown -n m1
Halt a zone:
zonemgr -a halt -n m1
21
ZoneMgr by Example 3:
Multi-zone state management
22
ZoneMgr by Example 3:
only – Multi-zone state management
Boot all zones:
for z in `zoneadm list -c | grep -v “^global$”`
do zoneadm -z $z boot; done
23
ZoneMgr by Example 3:
only – Multi-zone state management
Boot all zones:
zonemgr -a only -n bootall
24
ZoneMgr by Example 4:
modify network
25
ZoneMgr by Example 4:
modify network
Add a network address:
zonecfg -z m1
zonecfg:m1> add net
zonecfg:m1:net> set address=192.168.0.11/24
zonecfg:m1:net> set physical=hme0
zonecfg:m1:net> end; verify; commit; exit
Modify the network address:
zonecfg -z m1
zonecfg:m1> select net address=192.168.0.11/24
zonecfg:m1:net> set address=192.168.0.12/24
zonecfg:m1:net> end; verify; commit; exit
Delete the network address:
zonecfg -z m1
zonecfg:m1> remove net address=192.168.0.12/24
zonecfg:m1:net> verify; commit; exit
26
ZoneMgr by Example 4:
modify network
Add a network address:
zonemgr -a modify -n m1 -I “192.168.0.11|hme0|24|m1a”
27
ZoneMgr by Example 5:
modify filesystem
28
ZoneMgr by Example 5:
modify filesystem
Add directory from the global zone in read-only mode:
zonecfg -z m1
zonecfg:m1> add fs
zonecfg:m1:fs> set dir=/tmp
zonecfg:m1:fs> set special=/bob
zonecfg:m1:fs> set type=lofs
zonecfg:m1:fs> add options [ro,nodevices]
zonecfg:m1:fs> end; verify; commit; exit
Modify read-only directory:
zonecfg -z m1
zonecfg:m1> select fs special=/bob
zonecfg:m1:fs> set special=/frank
zonecfg:m1:fs> end; verify; commit; exit
Delete the read-only directory:
zonecfg -z m1
zonecfg:m1> remove fs special=/frank
zonecfg:m1:fs> end; verify; commit; exit29
ZoneMgr by Example 5:
modify filesystem
Add readonly directory from global zone in read-only mode:
zonemgr -a modify -n m1 -r “/tmp|/bob”
30
ZoneMgr by Example 6:
minimize zone
31
ZoneMgr by Example 6:
minimize zone
Minimize an existing zone:
Figure out what packages to remove.
Make file containing list of those packages: pkgs_to_remove_file
for pkg in `cat pkgs_to_remove_file`
do
zlogin m1 “yes | pkgrm $pkg”
done
32
ZoneMgr by Example 6:
minimize zone
Add a minimized zone:
Create zone config file file: zcfgfile
zonecfg -z m2 -f zcfgfile
zoneadm -z m2 install
zoneadm -z m2 boot
zlogin -C m2 # Manually answer the SysIdCfg questions
Figure out what packages to remove.
Make file containing list of those packages: pkgs_to_remove_file
for pkg in `cat pkgs_to_remove_file`
do
zlogin m2 “yes | pkgrm $pkg”
done
33
ZoneMgr by Example 6:
minimize zone
Minimize a zone with a specific package list:
Make file containing list of those packages: /pkglist.txt
for pkg in `cat /pkglist.txt`
do
zlogin m1 “yes | pkgrm $pkg”
done
34
ZoneMgr by Example 6:
minimize zone
Minimize an existing zone:
zonemgr -a modify -n m1 -M basic
35
ZoneMgr by Example 7:
harden zone
36
ZoneMgr by Example 7:
harden zone
Harden an existing zone with the basic mode:
Figure out what services to disable.
Make file containing list of those packages: svcs_to_disable
for svc in `cat svcs_to_disable`
do
zlogin m1 “svcadm disable $svc”
done
37
ZoneMgr by Example 7:
harden zone
Add a hardened zone:
Create zone config file file: zcfgfile
zonecfg -z m2 -f zcfgfile
zoneadm -z m2 install
zoneadm -z m2 boot
zlogin -C m2 # Manually answer the SysIdCfg questions
Figure out what services to disable.
Make file containing list of those packages: svcs_to_disable
for svc in `cat svcs_to_disable`
do
zlogin m2 “svcadm disable $svc”
done
38
ZoneMgr by Example 7:
harden zone
Harden an existing zone with a specific list of services to disable:
for svc in `cat /svcs.file`
do
zlogin m1 “svcadm disable $svc”
done
39
ZoneMgr by Example 7:
harden zone
Harden an existing zone with the basic mode:
zonemgr -a modify -n m1 -s “basic|lock”
40
ZoneMgr by Example 8:
ZFS filesystem
41
ZoneMgr by Example 8:
ZFS filesystem
Add ZFS filesystem to a zone:
Assuming ZFS pool myzfspool already exists:
zfs create myzfspool/zfsdata
zfs set mountpoint=legacy myzfspool/zfsdata
zfs set zoned=on myzfspool/zfsdata
zonecfg -z m1
zonecfg:m1> add fs
zonecfg:m1:fs> set dir=/zfsdata
zonecfg:m1:fs> set special=backup/zfsdata
zonecfg:m1:fs> set type=zfs
zonecfg:m1:fs> end; verify; commit; exit
42
ZoneMgr by Example 8:
ZFS filesystem
Add a zone and add a ZFS filesystem:
Assuming ZFS pool myzfspool already exists:
zfs create myzfspool/zfsdata
zfs set mountpoint=legacy myzfspool/zfsdata
zfs set zoned=on myzfspool/zfsdata
Create zone config file file that includes the following zfs config: zcfgfile
zonecfg:m2> add fs
zonecfg:m2:fs> set dir=/zfsdata
zonecfg:m2:fs> set special=backup/zfsdata
zonecfg:m2:fs> set type=zfs
zonecfg:m2:fs> end; verify; commit; exit
zonecfg -z m2 -f zcfgfile
zoneadm -z m2 install
zoneadm -z m2 boot
zlogin -C m2 # Manually answer the SysIdCfg questions
43
ZoneMgr by Example 8:
ZFS filesystem
Add ZFS filesystem to a zone:
zonemgr -a modify -n m1 -w "zfs|/zfsdata|myzfspool"
44
ZoneMgr by Example 9:
automated software installation
45
ZoneMgr by Example 9:
automated software installation
Install MySQL5 on existing zone from Blastwave:
zlogin m1 “wget http://www.blastwave.org/pkg_get-3.7.1-all-CSW.pkg”
zlogin m1 “yes | pkgadd -d. ./pkg_get-3.7.1-all-CSW.pkg”
zlogin m1 “yes | /opt/csw/bin/pkg-get install mysql5”
Add a zone and install multiple Blastwave packages:
Create zone config file file: zcfgfile
zonecfg -z m2 -f zcfgfile
zoneadm -z m2 install
zoneadm -z m2 boot
zlogin -C m2 # Manually answer the SysIdCfg questions
zlogin m2 “wget http://www.blastwave.org/pkg_get-3.7.1-all-CSW.pkg”
zlogin m2 “yes | pkgadd -d. ./pkg_get-3.7.1-all-CSW.pkg”
zlogin m2 “yes | /opt/csw/bin/pkg-get install mysql5”
zlogin m2 “yes | /opt/csw/bin/pkg-get install apache2”
zlogin m2 “yes | /opt/csw/bin/pkg-get install dss”
46
ZoneMgr by Example 9:
automated software installation
Install MySQL5 on existing zone from Blastwave:
zonemgr -a modify -n m1 -G mysql5
47
ZoneMgr by Example 10:
complexity simplified
Warning: The following relatively complex example
could very well take 20 or more steps if performing
manually without the simplification of the Zone Manager.
Fortunately with the Zone Manager you only have to type
in a single (although somewhat long) command.
48
ZoneMgr by Example 10:
complexity simplified
Lets consider what it would take to
create a non-global zone with the Network Global Zone
following features: 192.168.0.0/24
Whole Zone Zed
• Set home directory and shell of root user Minimized & Hardened
• Add network address mysql5 sshd
• Add read-only and read-write mounted /zfs(rw)
/zshare(ro) /zdata(rw)
directories from the global zone
• Add zfs filesystem
• Minimize: Un-install all un-necessary packages /share zfs /data
• Harden: Disable all un-necessary services
• Apply custom configuration files
• Install MySQL5 from network package
repository
• Apply specific privileges to the zone
• Add a user to the zone
49
ZoneMgr by Example 10:
complexity simplified
The following command will perform the details stated in the following
slides.
Global Zone
zonemgr -a add -n zed -t w -z /zones \
-P "pw" -R “/root|/bin/bash” \ Whole Root
-I "192.168.0.10|hme0|24|zed" \ Zone Zed
root user:
-M basic -s "basic|lock" \ password=pw
-r "/share|/zshare" -w "/data|/zdata" \ home=/root
shell=/bin/bash
-w "zfs|/zfs|mypool" \
-C /etc/ssh/sshd_config -S ssh \ Zone Zed Base Dir:
-C /etc/resolv.conf \ /zones/zed
-C “/etc/nsswitch.dns|/etc/nsswitch.conf” \
-G mysql5 -L default,dtrace_proc,dtrace_user \
-X “useradd -m myuser”
1. Create a whole root zone named zed in /zones/zed.
2. Set the root user password of zone zed to pw.
3. Set the root user home directory of zone zed to /root.
4. Set the root user shell of zone zed to /bin/bash.
50
ZoneMgr by Example 10:
complexity simplified
The following command will perform the details stated in the following
slides.
Network Global Zone
zonemgr -a add -n zed -t w -z /zones \ 192.168.0.0/24
-P "pw" -R “/root|/bin/bash” \ Zone Zed
Minimize:
-I "192.168.0.10|hme0|24|zed" \ pkgrm <pkgs>
-M basic -s "basic|lock" \
Harden:
-r "/share|/zshare" -w /data \ svcadm disable <svcs>
-w "zfs|/zfs|mypool" \
-C /etc/ssh/sshd_config -S ssh \
-C /etc/resolv.conf \
-C “/etc/nsswitch.dns|/etc/nsswitch.conf” \
-G mysql5 -L default,dtrace_proc,dtrace_user \
-X “useradd -m myuser”
5. Set the IP address of zone zed to 192.168.0.10, the
netmask to 255.255.255.0, assign it to interface hme0, and
assign it a host name of zed in /etc/hosts.
6. Uninstall all un-necessary packages from zone zed and disable all
un-necessary services using the basic hardening method.
51
ZoneMgr by Example 10:
complexity simplified
The following command will perform the details stated in the following
slides.
Network Global Zone
zonemgr -a add -n zed -t w -z /zones \ 192.168.0.0/24
-P "pw" -R “/root|/bin/bash” \ Whole Zone Zed
Minimized & Hardened
-I "192.168.0.10|hme0|24|zed" \
-M basic -s "basic|lock" \
-r "/share|/zshare" -w "/data|/zdata" \ /zfs(rw)
/zshare(ro) /zdata(rw)
-w "zfs|/zfs|mypool" \
-C /etc/ssh/sshd_config -S ssh \
-C /etc/resolv.conf \ /share zfs /data
-C “/etc/nsswitch.dns|/etc/nsswitch.conf” \
-G mysql5 -L default,dtrace_proc,dtrace_user \
-X “useradd -m myuser”
7. Read only mount directory /share from the global zone to /zshare
in non-global zone zed.
8. Read write mount directory /data from the global zone to /data
in non-global zone zed.
9. Create legacy mode zfs filesystem and mount it exclusively in zone zed.
52
ZoneMgr by Example 10:
complexity simplified
The following command will perform the details stated in the following
slides.
Network Global Zone
zonemgr -a add -n zed -t w -z /zones \ 192.168.0.0/24
-P "pw" -R “/root|/bin/bash” \ Whole Zone Zed
Minimized & Hardened
-I "192.168.0.10|hme0|24|zed" \
-M basic -s "basic|lock" \ sshd
-r "/share|/zshare" -w "/data|/zdata" \ /zfs(rw)
/zshare(ro) /zdata(rw)
-w "zfs|/zfs|mypool" \
-C /etc/ssh/sshd_config -S ssh \
-C /etc/resolv.conf \ /share zfs /data
-C “/etc/nsswitch.dns|/etc/nsswitch.conf” \
-G mysql5 -L default,dtrace_proc,dtrace_user \
-X “useradd -m myuser”
10. Copy sshd_config and resolv.conf from global zone to zone zed.
11. Replace resolv.conf in zone zed with the contents of resolv.dns from
the global zone.
12. Once the zone has completed being created and the configuration
file copies are complete, restart the ssh service.
53
ZoneMgr by Example 10:
complexity simplified
The following command will perform the details stated in the following
slides.
Network Global Zone
zonemgr -a add -n zed -t w -z /zones \ 192.168.0.0/24
-P "pw" -R “/root|/bin/bash” \ Whole Zone Zed
Minimized & Hardened
-I "192.168.0.10|hme0|24|zed" \
-M basic -s "basic|lock" \ mysql5 sshd
-r "/share|/zshare" -w "/data|/zdata" \ /zfs(rw)
/zshare(ro) /zdata(rw)
-w "zfs|/zfs|mypool" \
-C /etc/ssh/sshd_config -S ssh \
-C /etc/resolv.conf \ /share zfs /data
-C “/etc/nsswitch.dns|/etc/nsswitch.conf” \
-G mysql5 -L default,dtrace_proc,dtrace_user \
-X “useradd -m myuser”
13. Install mysql5 from the Blastwave.org package repository into
zone zed.
14. Set default, dtrace_proc, and dtrace_user privileges for zone zed.
15. Add user “myuser” to zone zed.
54
ZoneMgr Resources
OpenSolaris Project Page (Downloads, Docs, Bugs, RFEs,...):
http://opensolaris.org/os/project/zonemgr/
Contact Me:
ZoneMgr@Sun.COM
Thank You
Brad Diggs
Senior Directory Architect
Sun Microsystems, Inc.
ZoneMgr@Sun.COM