How to change the host ID for Solaris 10 global/non-global zones and Solaris 8/9 containters.

In Solaris 10 you cannot change the host ID of the server without doing some major hardware replacement. I will explain a workaround hack to change the hostid for Solaris 10 later in this article. Some applications will not run if you install them on a different server other than the one it was licensed for. This is because the license is associated with the host ID, if it is different then the license check will fail and the application will not launch.

However you can specify a custom host ID for Solaris 8 or 9 containers (non-global zone) running in Solaris 10 global zone. This can be done with using the zonecfg -z command. The instructions for changing the hostid for Solaris 10 global and non-global zones is in the bottom half of this article.

myserver # zonecfg -z myzone1
zonecfg:myzone1> add attr
zonecfg:myzone1:attr> set name=123456
zonecfg:myzone1:attr> set type=string
zonecfg:myzone1:attr> set value=”123456″
zonecfg:myzone1:attr> end
zonecfg:myzone1> exit

Stop myzone1

myserver # zonecfg -z myzone1 halt

Start myzone1

myserver # zonecfg -z myzone boot

Check on the status of myzone1

myserver # zonecfg list -vc

Now logon to the console of myzone1 and check the hostid

myserver @ zlogin -C myzone1

After you enter the login ID and password, run the command hostid.

# hostid
123456

Changing the hostid for Solaris 10 global and non-global zones.
Now you know how to change the host id for Solaris 8 and 9 containers. Here is a great script written by Brendan Gregg that can be used to change the host ID for Solaris 10 global and non-global zones. This script must run as a process in the background. Killing this process will revert the host ID to the factory ID imbedded in the hardware.

Cut and paste the below script to a file called zhostid, make the file executable. Change the following lines to refect the host IDs you want.
global 12345678
myzone1 90abcdef

#!/usr/bin/ksh
#
# zhostid – demo changing hostids for Solaris Zones.
# Written using DTrace (Solaris 10 3/05).
#
# WARNING: This is a demonstration of DTrace, it is not intended as a
# standard daemon. In particular, hostids are used by Sun to track support
# calls, so changing hostids may make life somewhat confusing for all.
#
# 21-Jun-2005, ver 0.70 (first release)
#
# USAGE: zhostid &
#
# Edit the “Configuration” section below to set the zones and
# hostids to what is desirable.
#
# BASED ON: hostid.d by Iain Hayes, and idea by Jon Haslam.
#
# COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place – Suite 330, Boston, MA 02111-1307, USA.
#
# (http://www.gnu.org/copyleft/gpl.html)
#
# 21-Jun-2005 Brendan Gregg Created this.

#
# Configuration
#
hostids=’
global 12345678
myzone1 90abcdef

‘ # simply modify the above by adding extra lines for each zone.

#
# Check hostids
#
print “$hostids” | while read zone hostid_hex; do
### Sanity check hostid
if [[ “$zone” == “” || “$zone” == “#” ]]; then continue; fi
if [[ “$hostid_hex” == *[g-zG-Z]* ]]; then
print “ERROR2: Invalid hostid $hostid_hex. ”
print “Please use hexadecimal.\n”
exit 2
fi
if (( ${#hostid_hex} > 11 )); then
# see /usr/src/uts/common/conf/param.c for limit.
print “ERROR3: Length of hostid $hostid_hex too long. ”
print “Limit 11 chars.\n”
exit 3
fi

### Convert hostid to decimal
typeset -i10 hostid_dec
hostid_dec=16#$hostid_hex

### Build DTrace code
body=”$body
syscall::systeminfo:return
/zonename == \”$zone\” && self->command == 7/
{
copyoutstr(\”$hostid_dec\”, self->buffer, 11);
}”
done

#
# Run DTrace
#
exec /usr/sbin/dtrace -n ‘

#pragma D option destructive
#pragma D option quiet
#pragma D option bufsize=32k

inline string hostid = “‘$hostid_dec'”;

syscall::systeminfo:entry
{
self->command = arg0;
self->buffer = arg1;
}

‘”$body”‘

syscall::systeminfo:return
{
self->command = 0;
self->buffer = 0;
}

Now run the zhostid file in the background as a process. The & option means to run in the background and it will give you back the prompt. This file must be run from the global zone.

myserver # ./zhostid &

Check the host ID with the hostid command.

myserver # hostid
12345678

Logon the the console of myzone1

# zlogin myzone1
[Connected to zone ‘myzone1’ pts/10]
Last login: Tue Jun 21 03:51:10 on pts/10
Sun Microsystems Inc. SunOS 5.10 Generic January 2005

myzone1 # hostid
90abcdef

7 comments for “How to change the host ID for Solaris 10 global/non-global zones and Solaris 8/9 containters.

Comments are closed.