Thursday, August 28, 2008

Solaris Zone Global Hardware Identification

How do you tell what physical hardware a zone resides on?

After creating zones on more than one or two physical hosts I lose track of what zones were on what physical hardware. My solution is to create a file on the global zone, suppose the physical server is called "sun-server":

echo sun-server >> /usr/local/global


The file /usr/local/global now contains the name of the physical host that the zone resides on.

For sparse zones the file on the global zone is visible so you don't have to create one there, but for whole zones you will need to run the command in the zone.

Simple and easy to check when you are on a host:

cat /usr/local/global
sun-server


1 comment:

fagrangeat said...

Michael, thanks for the info. I take one more step. I did a script to set in the crontab. In this case if you move the zone to other global zone the file will be refreshed.

#!/bin/bash

/usr/sbin/zoneadm list -iv | grep -v global | grep -v PATH | awk '{print $4}' > /tmp/localzone.txt

LZONE=/tmp/localzone.txt

for B in $(cat $LZONE)

do

if [ ! -e $B/root/etc/global.Zone ]
then
echo `hostname` > $B/root/etc/global.Zone
hostname | awk '{print "grep " $1 " /etc/hosts"}'| ksh | awk '{ print $1 }' >> $B/root/etc/global.Zone
else


if [ $(cat $B/root/etc/global.Zone) != `hostname` ]
then
echo `hostname` > $B/root/etc/global.Zone
hostname | awk '{print "grep " $1 " /etc/hosts"}'| ksh | awk '{ print $1 }' >> $B/root/etc/global.Zone
fi

fi

done

rm /tmp/localzone.txt