分类 Solaris 下的文章

How to Change the Hostid of a Sun Solaris Machine?

Solaris

The Hostid is a globally unique ID for a Sun Solaris Machine. Sometimes, you need to change this hostid for whatever purpose. For example, you current machine is down for hardware failure and you purchased a new machine. However, all your current running software are based on this old hostid, and you must bring the new machine up within a very short time. The quick solution is to change the new machine's hostid to be as same as the old one.

There are several ways to do so, including using a program to flush NVRAM which will change the hostid permanently. I did following experiment to change the Hostid in a Solaris 10 machine temperately. It adds several lines in the /etc/rc2.d/S20sysetup file. If you want to restore the original hostid, you just need to remove these lines and reboot the machine.

My environment is:
# uname -a
SunOS myhostname 5.10 Generic_127111-11 sun4v sparc SUNW,SPARC-Enterprise-T5120


Step 1: Calculate your new Hostid

(1) If you want to change your hostid to 800a1b2c (hexdecimal format), you need to calculate its decimal first. You can use following online calculator to do this.

http://www.easycalculation.com/hex-converter.php

Hexdecimal: 800a1b2c
Decimal: 2148145964

(2) Then, divide the decimal number to three parts:
2148
1459
64

(3) You treat the above 3 parts as string combined by ASCII Characters. Use following calculator to get the HEX value:
32 31 34 38
31 34 35 39
36 34

http://www.easycalculation.com/ascii-hex.php

You need to pad 0s to the 3rd part. So it will become:
32313438
31343539
36340000

Step 2: Save your original Hostid:
cd /etc
cat hostid > hostid.orig


Step 3: Change the /etc/rc2.d/S20sysetup file
At the bottom of this file, add following code:
# Change Host ID to Hexdecimal: 800a1b2c
# It's Decimal Value: 2148145964
# Divide to 3 parts: 2148 1459 64
# Hex value of the above ASCII Characters:
# 32 31 34 38
# 31 34 35 39
# 36 34
# After padding:
# 32313438
# 31343539
# 36340000
# The following code will apply the new Hostid
adb -w -k /dev/ksyms /dev/mem </dev/null
hw_serial/W 0x32313438
hw_serial+4/W 0x31343539
hw_serial+8/W 0x36340000
END


Step 4: If you want to make the new hostid effective without reboot the machine, just type:
#sh S20sysetup

Otherwise, you can reboot the machine. If you want restore the original factory hostid, you can just comment out the above several lines of code in S20sysetup file.