如何在Debian Jessie启动时使用脚本设置主机名?

我有一个Debian的Jessie安装,我用PXE启动,我需要在启动时使用脚本设置主机名。

我在以前的Debian版本中使用了/etc/init.d/hostname.sh,但似乎并没有在启动时执行。 也许是因为systemd

检查你是否执行了你的脚本

#chmod +x hostname.sh 

为什么不使用DHCP选项12呢?

https://tools.ietf.org/html/rfc1533

 3.14. Host Name Option This option specifies the name of the client. The name may or may not be qualified with the local domain name (see section 3.17 for the preferred way to retrieve the domain name). See RFC 1035 for character set restrictions. The code for this option is 12, and its minimum length is 1. Code Len Host Name +-----+-----+-----+-----+-----+-----+-----+-----+-- | 12 | n | h1 | h2 | h3 | h4 | h5 | h6 | ... +-----+-----+-----+-----+-----+-----+-----+-----+-- 

Edit_1

你也可以在“append”一行中添加deb-confvariables“hostname”作为内核参数

  append initrd=xxx/www/zzz.img hostname=myhostname ....