summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2025-05-06 11:50:31 +0200
committerHelmut Grohne <helmut@subdivi.de>2025-05-06 11:50:31 +0200
commit0f2f563bedd683a9271fe32b158fb978861ae4d4 (patch)
tree38ffd18dd7e712a0a4906bec9765db038274bb7c
parent3affb25556fde51cf8574e51fbaa6ee025549c33 (diff)
downloaddebvm-0f2f563bedd683a9271fe32b158fb978861ae4d4.tar.gz
debvm-create: fix network during mmdebstrap for old releases
We primarily run the systemd network stack inside debvm and that comes with turning /etc/resolv.conf into a symbolic link. Unfortunately, we may break networking during VM construction that way. The behavior is quite release dependent. For trixie and later, systemd-resolved.postinst takes a copy of /etc/resolv.conf and places it at the symlink target. For bookworm, systemd-resolved.postinst overwrites /etc/resolv.conf with a link that becomes dead. For bullseye and earlier, customize-resolved.conf overwrites /etc/resolv.conf with a link that becomes dead. That being dead means that passing any further customize hooks will not be able to utilize networking as DNS resolution fails. To improve the user experience, customize-resolved.sh will now turn ensure that those symlink targets are reasonably popoulated.
-rwxr-xr-xshare/customize-resolved.sh23
1 files changed, 21 insertions, 2 deletions
diff --git a/share/customize-resolved.sh b/share/customize-resolved.sh
index 8885d18..ee9d0c3 100755
--- a/share/customize-resolved.sh
+++ b/share/customize-resolved.sh
@@ -11,6 +11,14 @@ TARGET=$1
LIBNSS_RESOLVE_VERSION=$(dpkg-query --root "$TARGET" -f '${Version}' -W libnss-resolve 2>/dev/null) || :
+link_resolv_conf() {
+ if ! test -e "$TARGET$1" -o -h "$TARGET/etc/resolv.conf"; then
+ # To avoid breaking network during mmdebstrap via a dead link, take a copy.
+ install -D "$TARGET/etc/resolv.conf" "$TARGET$1"
+ fi
+ ln -fs "..$1" "$TARGET/etc/resolv.conf"
+}
+
if dpkg --compare-versions "$LIBNSS_RESOLVE_VERSION" lt 251.3-2~exp1; then
if test "${MMDEBSTRAP_MODE:-}" = chrootless; then
systemctl --root "$TARGET" enable systemd-resolved.service
@@ -19,8 +27,19 @@ if dpkg --compare-versions "$LIBNSS_RESOLVE_VERSION" lt 251.3-2~exp1; then
fi
if test -z "$LIBNSS_RESOLVE_VERSION" || dpkg --compare-versions "$LIBNSS_RESOLVE_VERSION" lt 236; then
- ln -fs ../run/systemd/resolve/resolv.conf "$TARGET/etc/resolv.conf"
+ link_resolv_conf /run/systemd/resolve/resolv.conf
else
- ln -fs ../run/systemd/resolve/stub-resolv.conf "$TARGET/etc/resolv.conf"
+ link_resolv_conf /run/systemd/resolve/stub-resolv.conf
+ fi
+else
+ if test -h "$TARGET/etc/resolv.conf" && ! test -e "$TARGET/etc/resolv.conf"; then
+ resolvconftarget=$(readlink "$TARGET/etc/resolv.conf")
+ if test "${resolvconftarget#../run/}" != "$resolvconftarget"; then
+ # /etc/resolv.conf is a dead link pointing to ../run/*
+ # mmdebstrap originally copied /etc/resolv.conf
+ # This situation arises when installing systemd-resolved in bookworm
+ # Fix network during mmdebstrap.
+ install -D /etc/resolv.conf "$TARGET${resolvconftarget#..}"
+ fi
fi
fi