The DHCP can specify a host and domain name for the system. live-boot
fills `/etc/hostname` and `/etc/resolv.conf` with the data from the DHCP
server, but resolving the fully qualified domain name (FQDN) fails, when
the host is not specified in DNS:
```
(initramfs) hostname -f
hostname: example-host: Host name lookup failure
```
To make the FQDN resolvable without DNS, `libnss_files.so` needs to be
included in the initramfs, `/etc/nsswitch.conf` need to prefer `files`
over `dns`, and `/etc/hosts` needs to be filled with the data from the
DHCP server.
# /lib/libnss_files.so.*: /etc/hosts and /etc/passwd
# /lib/libnss_compat.so.*: /etc/passwd
-for _SHLIB in $(find /lib -name 'libnss_dns.so.*')
+for _SHLIB in $(find /lib -name 'libnss_dns.so.*' -o -name 'libnss_files.so.*')
do
copy_exec "${_SHLIB}"
done
-# might be needed if /etc/hosts is used
-#mkdir -p "${DESTDIR}/etc"
-#cp -p /etc/nsswitch.conf "${DESTDIR}/etc"
+if [ ! -e "${DESTDIR}/etc/nsswitch.conf" ]
+then
+ # Needed to make "hostname -f" honor the domainname provided by DHCP
+ echo "hosts: files dns" > "${DESTDIR}/etc/nsswitch.conf"
+fi
[ "${QUIET}" ] || echo .
HWADDR="$(cat /sys/class/net/${interface}/address)"
fi
+ # Only create /etc/hosts if FQDN is known (to let 'hostname -f' query
+ # this file). Otherwise DNS will be queried to determine the FQDN.
+ if [ ! -e "/etc/hosts" ] && [ -n "${DNSDOMAIN}" ]
+ then
+ echo "Creating /etc/hosts"
+ cat > /etc/hosts <<EOF
+127.0.0.1 localhost
+127.0.1.1 ${HOSTNAME}.${DNSDOMAIN} ${HOSTNAME}
+
+# The following lines are desirable for IPv6 capable hosts
+::1 localhost ip6-localhost ip6-loopback
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters
+EOF
+ fi
+
if [ ! -e "/etc/resolv.conf" ]
then
echo "Creating /etc/resolv.conf"