amluto/virtme

DNS fails

muelli opened this issue · 0 comments

The DNS logic in virtme-init uses test -f /etc/resolv.conf for checking whether a resolv.conf exists and, if so, replace it with a writeable file supposedly s.t. the udhcp can write it s.t. name resolution works.

On my Ubuntu 18.04, however, /etc/resolv.conf is a symlink:

lrwxrwxrwx 1 root root 39 Oct 13  2017 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

and that target directory does not exist (does systemd-tmpfiles not create it..?).

On top of that, it seems, that bind-mounting over a symlink doesn't work:
https://serverfault.com/questions/322906/how-do-i-do-a-bind-mount-over-a-symlink :(

This dirty patch makes it work for me:

diff --git a/virtme/guest/virtme-init b/virtme/guest/virtme-init
index 44a018a..82f6c89 100755
--- a/virtme/guest/virtme-init
+++ b/virtme/guest/virtme-initdiff --git a/virtme/guest/virtme-init b/virtme/guest/virtme-init
index 44a018a..d080aae 100755
--- a/virtme/guest/virtme-init
+++ b/virtme/guest/virtme-init
@@ -146,16 +146,18 @@ fi
 ip link set dev lo up
 
 if cat /proc/cmdline |grep -q -E '(^| )virtme.dhcp($| )'; then
-    if [[ -f /etc/resolv.conf ]]; then
+    #if [[ test -f /etc/resolv.conf || test -h /etc/resolv.conf || test -e /etc/resolv.conf ]]; then
        tmpfile="`mktemp --tmpdir=/tmp`"
        chmod 644 "$tmpfile"
        mount --bind "$tmpfile" /etc/resolv.conf
        rm "$tmpfile"
-    fi
+    #fi
 
     # udev is liable to rename the interface out from under us.
     virtme_net=`ls "$(ls -d /sys/bus/virtio/drivers/virtio_net/virtio* |sort -g |head -n1)"/net`
     busybox udhcpc -i "$virtme_net" -t 1 -n -q -f -s "$(dirname $0)/virtme-udhcpc-script"
+    mkdir /run/systemd/resolve/
+    echo nameserver 10.0.2.3 | tee /run/systemd/resolve/stub-resolv.conf
 fi
 
 if [[ -x /run/virtme/data/script ]]; then