preseed.cfg ignoring hostname setting

10,316

Solution 1

If you are netbooting (with PXE and friends), the hostname is set up before fetching the preseed file, so the hostname should be set on the kernel command-line like this :

hostname=myhostname domain=mydomain

From the introduction of the appendix B (on preseeding) of the debian-installer manual :

An important difference between the preseeding methods is the point at which the preconfiguration file is loaded and processed. For initrd preseeding this is right at the start of the installation, before the first question is even asked. For file preseeding this is after the CD or CD image has been loaded. For network preseeding it is only after the network has been configured.

Solution 2

Not a solution but a workaround

I too have faced a similar issue and I worked around it by setting the host name after installation via the following lines added at the end of my pressed.cfg:

d-i pressed/late_command string\
    in-target /bin/bash -c 'echo desired_name > /etc/hostname'

The in-target is necessary so that the / refers to the target filesystem (that will eventually become your root filesystem) that usually appears as /target during installation.

Solution 3

I found that this problem went away when I removed priority=critical from the arguments I was passing-in to the kernel at the net install command line (via the pxelinux.cfg directory entries).

I assume this means that the question which asks the hostname has been given a priority which is lower than 'critical', and so gets populated with the default answer.

If you do make this change, you may find that you have to preseed some other lower-than-critical answers for other questions later on in the install process...

Solution 4

It's debian-installer limitation. By the time you fetch your preseed config file from network, netcfg has already done it's job and is gone, so it won't refetch values.

somewhat offical kludge is to use in your preseed.cfg line:

d-i preseed/run string http://example.net/d-i/jessie/preseed.sh

and in that preseed.sh then specify:

#!/bin/sh
kill-all-dhcp; netcfg

That way, when network is established and preseed.cfg is fetched, preseed.sh will also be fetch and run, so it will restart netcfg which will then read all preseed values for netcfg/* and configure them correctly (/etc/hostsname, /etc/hosts, /etc/network/interfaces if you're setting static IP configuration via preseed etc)

Share:
10,316

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    I am installing Debian Wheezy (netinstall) in VirtualBox using preseed.cfg.

    I tried both d-i netcfg/get_hostname string somehost and d-i netcfg/get_hostname string somehost, but in both cases the host gets set as "debian". I tried both at the same time but still the host is set as "debian".

    Excerpt from Debian's guide about preconfiguration file:

    If you want to force a hostname, regardless of what either the DHCP server returns or what the reverse DNS entry for the IP is, uncommentand adjust the following line

    d-i netcfg/hostname string somehost

    Is this a bug or am I just unlucky?

  • Martin
    Martin almost 9 years
    I've also used this but with a slight modification so that the hostname is automatically set from a DNS lookup: d-i pressed/late_command string in-target /bin/bash -c 'echo $(dig +short -x $(facter ipaddress)) | sed -e \'s/\.$//\' > /etc/hostname'. This uses "facter" from puppetlabs to get the IP address but you could do something similar using ip addr and sed.
  • Flakx
    Flakx over 6 years
    You can do this without a separate file: d-i preseed/early_command string kill-all-dhcp; netcfg in your preseed file is enough. Tested with Stretch in an automated netinstall.