Go Vegetarian

Go Vegetarian

Thursday, March 05, 2009

Sparse Zones, Cloning and ZFS - OpenSolaris 2008.11

How to create a ZFS "sparse" zone a use cloning to create new zones very quickly ?

In this step by step tutorial I will show you how to create a template that will be used to create all the others zones. The idea is to customize the template and inheritate all the customization in the new zones based on cloning.
  • Creating a ZFS filesystem hosting the zones -MANDATORY-

root@catalogne:~# zfs create -o mountpoint=/z rpool/z
root@catalogne:~# cd /z
root@catalogne:/z# df -h .
Filesystem Size Used Avail Use% Mounted on
rpool/z 83G 18K 83G 1% /z

  • Configuration of the zone
This is the textfile that I will use to create a zone name "sparsetemplate".

root@catalogne:~# cat sparse
create -b
set zonepath=/z/sparse
set autoboot=false
add inherit-pkg-dir
set dir=/lib
end
add inherit-pkg-dir
set dir=/platform
end
add inherit-pkg-dir
set dir=/sbin
end
add inherit-pkg-dir
set dir=/usr
end
add inherit-pkg-dir
set dir=/opt
end
add net
set address=192.168.1.50
set physical=e1000g0
end
add fs
set dir=/share
set special=/z/share
set type=lofs
add options [ro,nodevices]
end
commit


Remark : I did the creation of a zone for Identity Manager. I needed to install Tomcat, MySQL and IDM in /opt. It is maybe not a good idea to inherit /opt because in this case, the filesystem is read only and you cannot add any sofware ! I think it is more interesting in the case of /usr...
  • Installation of the zone

root@catalogne:~# zonecfg -z sparse -f sparse
root@catalogne:~# zoneadm -z sparse verify
WARNING: /z/sparse does not exist, so it could not be verified.
When 'zoneadm install' is run, 'install' will try to create
/z/sparse, and 'verify' will be tried again,
but the 'verify' may fail if:
the parent directory of /z/sparse is group- or other-writable
or
/z/sparse overlaps with any other installed zones.

root@catalogne:~# zoneadm -z sparse install
A ZFS file system has been created for this zone.
Authority: Using http://pkg.opensolaris.org/release/.
Image: Preparing at /z/sparse/root ... done.
Cache: Using /var/pkg/download.
Installing: (output follows)
DOWNLOAD PKGS FILES XFER (MB)
Completed 52/52 7862/7862 72.41/72.41

PHASE ACTIONS
Install Phase 12939/12939
PHASE ITEMS
Reading Existing Index 9/9
Indexing Packages 52/52

Note: Man pages can be obtained by installing SUNWman
Postinstall: Copying SMF seed repository ... done.
Postinstall: Working around http://defect.opensolaris.org/bz/show_bug.cgi?id=741
Done: Installation completed in 129.963 seconds.


Next Steps: Boot the zone, then log into the zone console
(zlogin -C) to complete the configuration process
  • Customization of the zone
boot the zone

root@catalogne:~# zoneadm -z sparse boot


open a console(zlogin -C sparse)
type 1x enter

If you play with sysidcfg you don't have to enter these informations.

This is the output from zlogin -C sparse :

System identification is completed.

rebooting system due to change(s) in /etc/default/init


[NOTICE: Zone rebooting]


SunOS Release 5.11 Version snv_101b 64-bit
Copyright 1983-2008 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.
Hostname: sparse
Reading ZFS config: done.
Mounting ZFS filesystems: (5/5)

sparse console login: root
Password:
Mar 4 17:15:12 sparse login: ROOT LOGIN /dev/console
Sun Microsystems Inc. SunOS 5.11 snv_101b November 2008
root@sparse:~#


exit and halt the zone

root@sparse:~# exit
logout

sparse console login:
sparse console login: ~.
[Connection to zone 'sparse' console closed]
root@catalogne:~# zoneadm -z sparse halt

root@catalogne:~# zoneadm list -iv
ID NAME STATUS PATH BRAND IP
0 global running / native shared
- identity_manager_80 installed /zones/identity_manager_80 ipkg shared
- sparse installed /z/sparse ipkg shared


  • Creation(cloning) of a zone based on sparse

root@catalogne:~/ZoneDefinitions# cp sparse identity-manager-80


modify identity-manager-80 and change the path to the zone and the ip address

clone the zone

root@catalogne:~# zonecfg -z identity-manager-80 -f identity-manager-80
root@catalogne:~/ZoneDefinitions# zoneadm -z identity-manager-80 clone sparse
sys-unconfig started Wed Mar 04 17:32:24 2009
rm: cannot remove `/z/identity-manager-80/root/etc/vfstab.sys-u': No such file or directory
grep: /z/identity-manager-80/root/etc/dumpadm.conf: No such file or directory
sys-unconfig completed Wed Mar 04 17:32:25 2009


The messages are only warnings and can be discarded !

The creation of the new zone is almost immediate.

  • Starting the new cloned zone

root@catalogne:~/ZoneDefinitions# zoneadm list -iv
ID NAME STATUS PATH BRAND IP
0 global running / native shared
- identity_manager_80 installed /zones/identity_manager_80 ipkg shared
- sparse installed /z/sparse ipkg shared
- identity-manager-80 installed /z/identity-manager-80 ipkg shared
root@catalogne:~/ZoneDefinitions# zoneadm -z identity-manager-80 boot


open a console

root@catalogne:~/ZoneDefinitions# zlogin -C identity-manager-80
[Connected to zone 'identity-manager-80' console]


same as before

System identification is completed.

identity-manager-80 console login:


System identification is completed.

identity-manager-80 console login: root
Password:
Mar 4 17:56:46 identity-manager-80 login: ROOT LOGIN /dev/console
Last login: Wed Mar 4 17:15:12 on console
Sun Microsystems Inc. SunOS 5.11 snv_101b November 2008
root@identity-manager-80:~#


To zone is ready to be used and / share contains the software that is needed. If you didn't notice /share does not reserve disk space in the local zone. The disk allocation was made into the global zone.

root@identity-manager-80:~# ls /share
IDM_8_0_0_0.zip javamail-1_4_1.zip
apache-tomcat-6.0.18.zip jdk-6u12-solaris-i586.tar
extra.tar.gz mq4_3-installer-SunOS_X86.zip
jaf-1_0_2-upd2.zip mysql-5.1.31-solaris10-i386.tar


  • ZFS filesystems

rpool/z 85G 1007M 84G 2% /z

rpool/z/sparse 84G 21K 84G 1% /z/sparse

rpool/z/identity-manager-80
84G 21K 84G 1% /z/identity-manager-80

rpool/z/identity-manager-80/ROOT/zbe
84G 239M 84G 1% /z/identity-manager-80/root

/lib 88G 4.0G 84G 5% /z/identity-manager-80/root/lib

/opt 88G 4.0G 84G 5% /z/identity-manager-80/root/opt

/platform 88G 4.0G 84G 5% /z/identity-manager-80/root/platform

/sbin 88G 4.0G 84G 5% /z/identity-manager-80/root/sbin

/z/share 85G 1007M 84G 2% /z/identity-manager-80/root/share

/usr 88G 4.0G 84G 5% /z/identity-manager-80/root/usr

/z/identity-manager-80/root/usr/lib/libc/libc_hwcap1.so.1
88G 4.0G 84G 5% /z/identity-manager-80/root/lib/libc.so.1

swap 1.6G 0 1.6G 0% /z/identity-manager-80/root/tmp

swap 1.6G 8.0K 1.6G 1% /z/identity-manager-80/root/var/run


-Rudy-

1 comment:

Anonymous said...
This comment has been removed by a blog administrator.