diff options
author | Andrea Righi <andrea.righi@canonical.com> | 2019-08-13 17:19:22 +0200 |
---|---|---|
committer | Andrea Righi <andrea.righi@canonical.com> | 2019-08-13 17:44:47 +0200 |
commit | 14b4957d668c2840ce91584ffd5dc4cb938774f6 (patch) | |
tree | 1d556f0695940e8836877220f72b781dacb72d6b | |
parent | 538f1e756139a6b57a4780e7ceb3ac6bcaa4fe6f (diff) | |
download | virtme-14b4957d668c2840ce91584ffd5dc4cb938774f6.tar.gz |
virtme-init: correctly initialize resolv.conf under ubuntu
In recent distro (i.e., Ubuntu) resolv.conf is a symlink to
/run/systemd/resolve/stub-resolv.conf that is not visible by the guest.
This results in a failure when trying to initialize this file.
Make sure to resolve the symlink first and initialize the actual file
with an empty file before trying to rewrite its content.
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
-rwxr-xr-x | virtme/guest/virtme-init | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/virtme/guest/virtme-init b/virtme/guest/virtme-init index 91201b5..db63fcb 100755 --- a/virtme/guest/virtme-init +++ b/virtme/guest/virtme-init @@ -155,10 +155,18 @@ fi ip link set dev lo up if cat /proc/cmdline |grep -q -E '(^| )virtme.dhcp($| )'; then - if [[ -f /etc/resolv.conf ]]; then + real_resolv_conf=/etc/resolv.conf + if [[ -L "$real_resolv_conf" ]]; then + real_resolv_conf="`readlink /etc/resolv.conf`" + if [[ ! -e $real_resolv_conf ]]; then + mkdir -p "`dirname $real_resolv_conf`" + touch $real_resolv_conf + fi + fi + if [[ -f "$real_resolv_conf" ]]; then tmpfile="`mktemp --tmpdir=/tmp`" chmod 644 "$tmpfile" - mount --bind "$tmpfile" /etc/resolv.conf + mount --bind "$tmpfile" "$real_resolv_conf" rm "$tmpfile" fi |