f.zz.de
posts /

Debian Install and hostname preseeding

Posted Wed 29 Oct 2014 04:48:00 PM CET
in

Typically i didnt care for hostname setting in d-i because machines i installed were later modified manually a lot. Now i am facing more automated creation of virtual machines i would not like to touch manually a lot.

So i tried preseeding the hostname with the documented methods e.g.

netcfg/get_hostname=vmXYZ

Which worked kind of. When i moved to the production environment suddenly DNS was involved and i learned that d-i tries very hard to work around 'netcfg/get_hostname' by looking at DHCP responses and into the DNS reverse DNS.

So i had a look at the code and found this in 'netcfg/dhcp.c'

572                 debconf_get(client, "netcfg/hostname");
573                 if (!empty_str(client->value)) {
574                     strncpy(buf, client->value, MAXHOSTNAMELEN);
575                     di_debug("Using preseeded hostname");
576                     preseed_hostname_from_fqdn(client, buf);
577                 }
578                 else if (gethostname(buf, sizeof(buf)) == 0
579                     && !empty_str(buf)
580                     && strcmp(buf, "(none)")
581                     ) {
582                     di_info("DHCP hostname: \"%s\"", buf);
583                     preseed_hostname_from_fqdn(client, buf);
584                 }
585                 else if (!empty_str(interface->dhcp_hostname)) {
586                     di_debug("Defaulting hostname to provided DHCP hostname");
587                     debconf_set(client, "netcfg/get_hostname", interface->dhcp_hostname);
588                 } else {

I havnt found a lot of documentation on these logic so i am writing it here.

So 'netcfg/hostname' is the way to set the users wish of a hostname.