Home / Solaris 10 / How to find the Solaris global zone from local zone using script

How to find the Solaris global zone from local zone using script

Many of the Solaris administrators will break their head to find Solaris global zone name from  localzone. These kind of questions may asked in interviews too.How do you find it ? The answer is No.There is no simple command to find it.Because Oracle (Sun microsystems  ) designed the Solaris zones in such a way for that, you can’t  find the global zone from local zone due to security reason. But you can add cronjob to write the global zone name on all local zones from global periodically to identify the global.

 
But there are some other alternatives that you can find the global zone name from local zone using MAC address.Here we will see about that and we will see the  permanent fix for that issue.

Assumpations:Here i am having local zone “sol1” is running on Global-zone
Global-zone# zoneadm list -cv
  ID NAME             STATUS     PATH                           BRAND    IP
   0 global           running    /                              native   shared
   8 sol1             running    /export/zone/sollz1            native   shared


Login to local zone and execute the below command:If you are getting many IP’s, then that global zone may have more local zones.You can suppress those IP’s by confirming global or local zone by using zonename command.(Login to those IP address and type “zonename” to determined that.)

Local-zone# arp -a|grep SP
e1000g0 192.168.56.130       255.255.255.255 SPLA     00:0c:29:5e:76:f5
bash-3.00# exit
# ^D

Login to IP 192.168.56.130 and type zonename.If the output global,then this is the global zone where that local zone is running.

Global-zone#zonename
global
Global-zone# ifconfig -a
lo0: flags=2001000849 mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000
lo0:1: flags=2001000849 mtu 8232 index 1
        zone sol1
        inet 127.0.0.1 netmask ff000000
e1000g0: flags=1004843 mtu 1500 index 2
        inet 192.168.56.130 netmask ffffff00 broadcast 192.168.56.255
        ether 0:c:29:5e:76:f5

How to see the global zone name in local zone permanently ?
There is a workaround to see global zone name in local zone permanently by adding one small script in global’s crontab.

Add the below entries in root crontab of global zone.This will write the global zone name in all the local zones every hour.you can check it in /etc/GLOBALZ file in all the local zones.

# To write the global zone name on all local zone hourly
00 * * * * /root/globalzonename.sh  >/dev/null 2>&1


Keep the “globalzonename.s”h in /root and make is executable.

Global-Zone# cat globalzonename.sh
#!/usr/bin/bash
for i in `/usr/sbin/zoneadm list -v | /usr/bin/egrep -v "ID|global" |/usr/bin/awk ' { print $4 } '`; do echo `uname -n` > $i/root/etc/GLOBALZ; done

Verifying our work after an hour,

Local-zone# cat /etc/GLOBALZ
sfos



If you want to find the zone type, you can just type “zonename” command.If its a global zone ,you will get output as “global” otherwise you will get hostname.

How to identify the zone type ? whole root zone or sparse root zone ?
Use “pkgcond -n is_what”  command to determine the zone type. This command output shows the below values. (1= True 0=False )

For local zone + whole root zone
is_global_zone=0
is_nonglobal_zone=1
is_sparse_root_nonglobal_zone=0

is_whole_root_nonglobal_zone=1

For local zone + Sparse root zone
is_global_zone=0
is_nonglobal_zone=1
is_sparse_root_nonglobal_zone=1

is_whole_root_nonglobal_zone=0

For Global zone
is_global_zone=1
is_nonglobal_zone=0
is_sparse_root_nonglobal_zone=0

is_whole_root_nonglobal_zone=0
Refer the here for more information about pkgcond use.

Thank you for reading this article.Please leave a  comment if you have any doubt.I will get back to you.

VMTURBO-CLOUD-CAPACITY

3 comments

  1. Hi Lingeswaran R,
    I just wonder, Why System Admin should need to know the name of global zone if it always has the name ‘global’ ?

    I mean in Solaris 11, I don’t work with Solaris 10 before

    • Global zone name will be updated on the local zone not in global itself.If you connect local zone, you can easily determine , the global zone name.

      Regards
      Lingeswaran
      UnixArena.

  2. I think that an easier way to know the global zone name from the local zone is to execute from the local zone: eeprom and grep that output for the ChassisSerialNumber. Then write a small script to map the serial number to the global zone name in your environment.

    serial=`eeprom | grep ChassisSerial | awk ‘{print $3}’`
    case $serial in
    ABC102100W) echo “Global zone name: ABC” ;;
    XYZ102100T) echo “Global zone name: ZYX” ;;
    esac

Leave a Reply

Your email address will not be published. Required fields are marked *