From bebb037d664185769c12cd061c2221c2d2bdb432 Mon Sep 17 00:00:00 2001 From: abrychcy Date: Fri, 16 Feb 2024 10:31:24 +0100 Subject: [PATCH] Fix DNS resolution in initramfs (#367) Add DNS servers to /etc/resolv.conf after interfaces are setup via configure_networking: * create /etc/resolv.conf from network infos of all configured interfaces * include libnss_dns.so + libnss_files.so in initramfs * copy libs into initrd required for DNS resolution --- src/initramfs-tools/hooks/clevis.in | 8 ++++++++ src/initramfs-tools/scripts/local-top/clevis.in | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/initramfs-tools/hooks/clevis.in b/src/initramfs-tools/hooks/clevis.in index 2c8473c3..3d4eb67f 100755 --- a/src/initramfs-tools/hooks/clevis.in +++ b/src/initramfs-tools/hooks/clevis.in @@ -95,3 +95,11 @@ bash_bin=$(find_binary "bash") copy_exec "${curl_bin}" || die 2 "Unable to copy ${curl_bin} to initrd image" copy_exec "${awk_bin}" || die 2 "Unable to copy ${awk_bin} to initrd image" copy_exec "${bash_bin}" || die 2 "Unable to copy ${bash_bin} to initrd image" + +# Copy latest versions of shared objects needed for DNS resolution +for so in $(ldconfig -p | sed -nr 's/^\s*libnss_files\.so\.[0-9]+\s.*=>\s*//p'); do + copy_exec "${so}" +done +for so in $(ldconfig -p | sed -nr 's/^\s*libnss_dns\.so\.[0-9]+\s.*=>\s*//p'); do + copy_exec "${so}" +done diff --git a/src/initramfs-tools/scripts/local-top/clevis.in b/src/initramfs-tools/scripts/local-top/clevis.in index 7c08a724..14872647 100755 --- a/src/initramfs-tools/scripts/local-top/clevis.in +++ b/src/initramfs-tools/scripts/local-top/clevis.in @@ -263,6 +263,23 @@ do_configure_networking() { echo "clevis: Warning: multiple network interfaces available but no ip= parameter provided." fi configure_networking + + # Add DNS servers from configure_networking to /etc/resolv.conf + if [ ! -e /etc/resolv.conf ]; then + touch /etc/resolv.conf + for intf in /run/net-*.conf; do + . "${intf}" + if [ ! -z "${IPV4DNS0}" ] && [ "${IPV4DNS0}" != "0.0.0.0" ]; then + echo nameserver "${IPV4DNS0}" >> /etc/resolv.conf + fi + if [ ! -z "${IPV4DNS1}" ] && [ "${IPV4DNS1}" != "0.0.0.0" ]; then + echo nameserver "${IPV4DNS1}" >> /etc/resolv.conf + fi + if [ ! -z "${IPV6DNS0}" ]; then + echo nameserver "${IPV6DNS0}" >> /etc/resolv.conf + fi + done + fi fi }