linux solaris修改hostid方法

linux:

一个C程序,如下:
#include <stdio.h>
#include <unistd.h>
int main() {
long id=0,res=0;

id = gethostid();
printf("current hostid is: %x\n",id);
res = sethostid(0x837b1d2c);
if (res == 0) printf("if result is zero - success! (%d) \n",res);
id = gethostid();
printf("current hostid is: %x ;ppppp\n",id);
return 0;
}
假设命名为ch_hostid.c
编译 gcc -o ch_hostid ch_hostid.c
执行: ./ch_hostid
使用hostid命令查看是否已经修改成功。

说明: gethostid()获取当前hostid ,  sethostid(参数为要设置的hostid(16进制的))



solaris系统
本来也想用上述程序来修改,但sethostid在solaris里没用,现用以下方法
还是以要修改后的hostid为837b1d2c为例


方法如下


1、837b1d2c转换成10进制
2205883692
2、然后每4位一组,不足4位补0,将数字转换为对应的ASCII码
32323035
38383336
39320000
3、写个脚本 内容如下
adb -w -k /dev/ksyms /dev/mem <<END>/dev/null
                hw_serial/W 0x32323035
                hw_serial+4/W 0x38383336
                hw_serial+8/W 0x39320000
                END
注:使用上述脚本修改后,会将hostid临时修改,系统重启,会失效;为使得永久生效,
可以将脚本放入/etc/rc2.d目录下,则系统启动将自动运行脚本将hostid进行修改但在我这没永久修改,重启后hostid又恢复成以前的了,如果不行换成下面的方法试试,我是采用了下面的方法,永久修改成功)

或者:修改 /etc/rc2.d/S20sysetup
增加如下内容
               adb -w -k /dev/ksyms /dev/mem <<END>/dev/null
                hw_serial/W 0x32323035
                hw_serial+4/W 0x38383336
                hw_serial+8/W 0x39320000
                END
保存后,执行sh S20sysetup

猜你喜欢

转载自liqing6044313.iteye.com/blog/1687330