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.
See also the comments in https:/ /unix.stackexch ange.com/ questions/ 106614/ preseed- cfg-ignoring- hostname- setting, and in particular the reference to d-i.alioth. debian. org/manual/ en.i386/ apbs04. html#preseed- network
http://
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; \ 0.1.1\t. */127.0. 1.1\t$hostname/ " -i /etc/hosts; \
sed "s/^127.
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.