Comment 65 for bug 1452202

Revision history for this message
Peter Wu (lekensteyn) wrote :

See also the comments in https://unix.stackexchange.com/questions/106614/preseed-cfg-ignoring-hostname-setting, and in particular the reference to
http://d-i.alioth.debian.org/manual/en.i386/apbs04.html#preseed-network
The hostname is probably a very common case though.

I am currently using this in my preseed file (tested with Ubuntu 16.04.2 mini.iso):

d-i preseed/early_command string hostname=ubuntu; \
    sed "s/^127.0.1.1\t.*/127.0.1.1\t$hostname/" -i /etc/hosts; \
    echo "$hostname" > /etc/hostname; hostname "$hostname"

Proposal: revert the current patch and suggest the above preseed config *or* modify preseed:
1. Change sed commands to something like the above.
2. Remove "f ! echo "$RET" | grep -q 'ubuntu';" such that the hostname is unconditionally set when netcfg/hostname is given.

Note that "127.0.1.1\t%s" originates from netcfg-1.135ubuntu4.2, function netcfg_write_common in netcfg-common.c. This exact match does not rely on the current hostname which should possible regex injection issues.