Archive for January, 2008

Creating (and deleting) a lot of zones

January 15, 2008

As promised, here’s a sample zone cloning session using the zone-clone and delete-cloned-zones script as described in my previous blog. I used a 400 MHz UltraSPARC-IIi 512 MB Ultra 5 with Solaris Nevada build 80.

Please don’t forget to download and use zonemgr for general purpose zone handling. The zone-clone script described here might be used for creating a lot of clones in one step, or you might just use some of the algorithms for automatically setting parameters in scripts that are calling zonemgr.

This is a list of the zones before the script was started:

# zoneadm list -cv
ID NAME             STATUS     PATH                           BRAND    IP
0 global           running    /                              native   shared
- source-zone      installed  /p1/source-zone                native   shared

Then, I started the script. It displays some important data for verification if all the parameters are set appropriately:

  • The status of the retrieval of the password for the root user of the new zones (from the global zone’s /etc/shadow file entry for the user specified as parameter USER_FOR_ROOT_PASSWD)
  • The status of the source zone (the zone that is to be cloned)
  • The contents of the zone config file for the first zone
  • The contents of the sysidcfg file for the first zone
  • The highest IP address
# time ./zone-clone 10
Successfully retrieved password for the root user, from /etc/shadow entry for
user adm.
Check:
------
Source zone:
- source-zone      installed  /p1/source-zone                native   shared
/p1/source-zone
------
Content of first zone config file:
create
set zonepath=/p1/scotty-z-01
add net
set address=192.162.0.5/19
set physical=hme0
end
verify
commit
exit
------
Content of first sysidcfg file:
system_locale=en_US.ISO8859-15
timezone=Europe/Berlin
terminal=xterms
keyboard=German
security_policy=NONE
root_password=Zfcnvzy8TtKVY
timeserver=localhost
name_service=none
network_interface=primary {hostname=scotty-z-01
ip_address=192.162.0.5
netmask=255.255.224.0
protocol_ipv6=yes
default_route=192.162.0.1
}
nfs4_domain=dynamic
------
Highest IP address will be 192.162.0.14, for zone scotty-z-10 .
Press RETURN to start creating 10 zones.

After pressing RETURN, all zones are created:

scotty-z-01 with zonepath=/p1/scotty-z-01 and ip addr=192.162.0.5 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:36:30 2008
sys-unconfig completed Tue Jan 15 18:36:31 2008
... done.
scotty-z-02 with zonepath=/p1/scotty-z-02 and ip addr=192.162.0.6 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:36:48 2008
sys-unconfig completed Tue Jan 15 18:36:49 2008
... done.

(screen output omitted)

scotty-z-08 with zonepath=/p1/scotty-z-08 and ip addr=192.162.0.12 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:38:28 2008
sys-unconfig completed Tue Jan 15 18:38:29 2008
... done.
scotty-z-09 with zonepath=/p1/scotty-z-09 and ip addr=192.162.0.13 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:38:46 2008
sys-unconfig completed Tue Jan 15 18:38:46 2008
... done.
scotty-z-10 with zonepath=/p1/scotty-z-10 and ip addr=192.162.0.14 ...
Cloning snapshot p1/source-zone@SUNWzone1
sys-unconfig started Tue Jan 15 18:39:03 2008
sys-unconfig completed Tue Jan 15 18:39:03 2008
... done.
real    3m22.44s
user    2m6.01s
sys     0m19.57s

That’s about 20 seconds for each zone.

The zfs list looks as follows:

# zfs list
NAME                       USED  AVAIL  REFER  MOUNTPOINT
p1                         670M  15.5G  16.5K  /p1
p1/scotty-z-01             134K  15.5G   664M  /p1/scotty-z-01
p1/scotty-z-02             134K  15.5G   664M  /p1/scotty-z-02
p1/scotty-z-03             134K  15.5G   664M  /p1/scotty-z-03
p1/scotty-z-04             134K  15.5G   664M  /p1/scotty-z-04
p1/scotty-z-05             134K  15.5G   664M  /p1/scotty-z-05
p1/scotty-z-06             134K  15.5G   664M  /p1/scotty-z-06
p1/scotty-z-07             135K  15.5G   664M  /p1/scotty-z-07
p1/scotty-z-08             134K  15.5G   664M  /p1/scotty-z-08
p1/scotty-z-09             134K  15.5G   664M  /p1/scotty-z-09
p1/scotty-z-10             134K  15.5G   664M  /p1/scotty-z-10
p1/source-zone             668M  15.5G   667M  /p1/source-zone
p1/source-zone@SUNWzone1  1.41M      -   664M  -

And the list of zones is:

# zoneadm list -cv
ID NAME             STATUS     PATH                           BRAND    IP
0 global           running    /                              native   shared
2 scotty-z-01      ready      /p1/scotty-z-01                native   shared
4 scotty-z-02      ready      /p1/scotty-z-02                native   shared
6 scotty-z-03      ready      /p1/scotty-z-03                native   shared
8 scotty-z-04      ready      /p1/scotty-z-04                native   shared
10 scotty-z-05      ready      /p1/scotty-z-05                native   shared
12 scotty-z-06      ready      /p1/scotty-z-06                native   shared
14 scotty-z-07      ready      /p1/scotty-z-07                native   shared
16 scotty-z-08      ready      /p1/scotty-z-08                native   shared
18 scotty-z-09      ready      /p1/scotty-z-09                native   shared
20 scotty-z-10      ready      /p1/scotty-z-10                native   shared
- source-zone      installed  /p1/source-zone                native   shared

Let’s boot a zone, and login:

# time zoneadm -z scotty-z-05 boot
real    0m0.38s
user    0m0.14s
sys     0m0.05s
# zlogin scotty-z-05
[Connected to zone 'scotty-z-05' pts/2]
Last login: Mon Jan  7 19:33:29 on console
Sun Microsystems Inc.   SunOS 5.11      snv_80  January 2008

Now, let’s delete all the zones again:

# time ./delete-cloned-zones
Press RETURN to delete the following zones and their zfs file systems:
2 scotty-z-01      ready      /p1/scotty-z-01                native   shared
4 scotty-z-02      ready      /p1/scotty-z-02                native   shared
6 scotty-z-03      ready      /p1/scotty-z-03                native   shared
8 scotty-z-04      ready      /p1/scotty-z-04                native   shared
10 scotty-z-05      running    /p1/scotty-z-05                native   shared
12 scotty-z-06      ready      /p1/scotty-z-06                native   shared
14 scotty-z-07      ready      /p1/scotty-z-07                native   shared
16 scotty-z-08      ready      /p1/scotty-z-08                native   shared
18 scotty-z-09      ready      /p1/scotty-z-09                native   shared
20 scotty-z-10      ready      /p1/scotty-z-10                native   shared
You may now delete lines from file /var/tmp/zones-to-delete-7349.txt
(in case you would like to keep some of the zones).
Press RETURN to halt all zones in file /var/tmp/zones-to-delete-7349.txt.
Trying to halt all zones in file /var/tmp/zones-to-delete-7349.txt:
zone scotty-z-01 halted.
zone scotty-z-02 halted.
zone scotty-z-03 halted.
zone scotty-z-04 halted.
zone scotty-z-05 halted.
zone scotty-z-06 halted.
zone scotty-z-07 halted.
zone scotty-z-08 halted.
zone scotty-z-09 halted.
zone scotty-z-10 halted.
Finished halting all zones in file /var/tmp/zones-to-delete-7349.txt.
Last chance: Press RETURN to stop deleting the zones, or
type in yes, followed by RETURN, to continue.
yes
Trying to delete all zones in file /var/tmp/zones-to-delete-7349.txt:
zone scotty-z-01 deleted.
zone scotty-z-02 deleted.
zone scotty-z-03 deleted.
zone scotty-z-04 deleted.
zone scotty-z-05 deleted.
zone scotty-z-06 deleted.
zone scotty-z-07 deleted.
zone scotty-z-08 deleted.
zone scotty-z-09 deleted.
zone scotty-z-10 deleted.
Trying to destroy all zone zfs file systems:
zfs filesystem p1/scotty-z-01 destroyed.
zfs filesystem p1/scotty-z-02 destroyed.
zfs filesystem p1/scotty-z-03 destroyed.
zfs filesystem p1/scotty-z-04 destroyed.
zfs filesystem p1/scotty-z-05 destroyed.
zfs filesystem p1/scotty-z-06 destroyed.
zfs filesystem p1/scotty-z-07 destroyed.
zfs filesystem p1/scotty-z-08 destroyed.
zfs filesystem p1/scotty-z-09 destroyed.
zfs filesystem p1/scotty-z-10 destroyed.
Press RETURN to delete temporary file /var/tmp/zones-to-delete-7349.txt,
<ctrl>c to keep it.
real    0m28.88s
user    0m3.17s
sys     0m4.22s

I have tested this several times, with different parameters, with 100 and more zones, on SPARC and x86. Works fine! I hope you find some useful cases for these scripts in your environment, or get some ideas for writing your own zone creation scripts.

Advertisements

How to create a lot of zones (and delete them afterwards)

January 15, 2008

Sometimes, e.g. in educational contexts, or for testing purposes, you might want to create a number of zones in one step and delete them later. In this entry, I am describing one possible way of doing this. Other tools are already well-known (e.g. zonemgr), but with a different focus.

The basic steps are as follows:

  1. Create a zone that you want to clone.
  2. Boot that zone so that the SMF manifests are imported.
  3. Customize that zone as you like.
  4. Set some basic parameters in the CUSTOMIZE section of the script.
  5. Start the script and wait for its completion. The creation of one zone can take about 15 to 30 seconds, depending on the server you are using.

The script performs the following steps for each zone, after performing some small calculations, e.g. for creating the default route, the netmask, and the root password:

  1. The IP address and the zone name and zone root path are determined.
  2. The zone configuration file is created.
  3. The sysidcfg file is created.
  4. The zone root path of the source zone is determined
  5. If that zone root path and the destination root path are both on a ZFS file system, zone cloning is performed using ZFS snapshots.
  6. Using the zonecfg command and the zone configuration file, the zone is configured.
  7. Then, the zone is cloned, using the zoneadm command.
  8. The sysidcfg file is copied to the etc directory of the zone, and the .UNCONFIGURED file is deleted from that directory.
  9. The zone is then left in the installed state, brought to the ready state, or booted. Bringing it to the ready state will configure the zone’s IP interface and reduce the boot time of the zone.

Click here to download the zone cloning script. Another script, delete-cloned-zones, can then be used to delete these zones. It searches the list of zones for a certain pattern, halts and deletes each zone and then destroys each of these zone’s zfs file systems. Be sure to test this script carefully!

I’ll post a sample zone cloning and deleting session in my next blog entry.

Font sizes and the Nvidia driver for Solaris

January 13, 2008

I just thought it might help if I describe a small problem I had with my Solaris Nevada system and the Nvidia driver. A really great driver: stable, very fast screen refresh, antialising, and it comes with a useful tool which even can show the GPU chip temperature.

Sometimes, after logging in, the font sizes are relatively small, and I found the following entry in /var/log/Xorg.0.log:

(WW) NVIDIA(0): Unable to get display device CRT-1's EDID; cannot compute DPI
(==) NVIDIA(0): DPI set to (75, 75); computed from built-in default

And in those cases where correct (larger) fonts were set, I found:

(--) NVIDIA(0): DPI set to (109, 108); computed from "UseEdidDpi" X config

A colleague recommended to use the following command to set the font size for a specific user:

$ gconftool-2 -s /desktop/gnome/font_rendering/dpi -t float 108

On the web, there’s another way mentioned to solve this problem: Set the DPI size to a fixed value in /etc/X11/xorg.conf:

Section "Device"
Identifier "NvidiaTwin"
...
Option "UseEdidDpi" "FALSE"
Option "DPI" "86 x 86"
...

I haven’t tested yet but would expect it would work as well, by replacing the DPI values by appropriate ones.

Prepend command output lines with date/time stamps

January 9, 2008

From time to time, I’d like to know at which point in time a server is powered off or loses its network connection when powering down. Or I’d like to know when certain things happened to a system (e.g. during problem analysis).

I found a method which can be used for any command that outputs data in intervals, using nawk. Here’s a sample for ping -s:

ping -s ${HOST} |
nawk '{"date \"+%d.%m.%Y %H:%M:%S\":"|getline date;
close("date \"+%d.%m.%Y %H:%M:%S\":");
printf ("%s %s\n", date, $0)}'

or, in U.S. notation:

ping -s ${HOST} |
nawk '{"date \"+%m/%d/%Y %H:%M:%S\":"|getline date;
close("date \"+%m/%d/%Y %H:%M:%S\":");
printf ("%s %s\n", date, $0)}'

A sample output line looks as follows:

09.01.2008 16:08:24: 64 bytes from p2x (192.168.0.10): icmp_seq=0. time=0.734 ms
09.01.2008 16:08:25: 64 bytes from p2x (192.168.0.10): icmp_seq=1. time=0.357 ms
09.01.2008 16:08:26: 64 bytes from p2x (192.168.0.10): icmp_seq=2. time=0.563 ms

The important thing is to use the same date commands before the pipe and in the close() section of nawk.

By replacing the ping -s ${HOST} command with any other command that prints output to the terminal in intervals (e.g. iostat 2 or vmstat 5), you can use any other command and prepend each output line with corresponding date/time strings. You can then use the output to create charts in OpenOffice Calc or gnuplot.

Netmask calculation with (n)awk

January 4, 2008

I needed a script to calculate a netmask in dotted decimal notation from the number of bits. Here’s how I did it:

echo "22" | \
nawk '{num=$1;
for (i=1; i=8) printf ("255");
else if (num<=0) printf ("0");
else printf ("%s", 256-2^(8-num));
if (i<=3) printf (".")
num-=8
}
printf ("\n")
}'

or:

nawk 'BEGIN{num=22;
for (i=1; i=8) printf ("255");
else if (num<=0) printf ("0");
else printf ("%s", 256-2^(8-num));
if (i<=3) printf (".")
num-=8
}
printf ("\n")
}'

BTW there are a number of other resources on the web which you might use for this purpose, e.g. this link).