diff --git a/installsystems/tools.py b/installsystems/tools.py
index 1e7d5cb8cfb7485e8fbcb5d98c20a7c86c79438f..7bf6570f58df21d1b0575127e16dd530c7cd294e 100644
--- a/installsystems/tools.py
+++ b/installsystems/tools.py
@@ -375,12 +375,10 @@ def prepare_chroot(path, mount=True):
                     warn("Mount failed: %s.\n" % e)
     # trick resolv.conf
     try:
-        if os.path.exists("/etc/resolv.conf"):
+        if os.path.exists("/etc/resolv.conf") and os.path.exists(os.path.join(path, "etc")):
             resolv_path = os.path.join(path, "etc/resolv.conf")
             if os.path.exists(resolv_path):
                 os.rename(resolv_path, "%s.isbackup" % resolv_path)
-            if not os.path.exists(os.path.dirname(resolv_path)):
-                os.makedirs(os.path.dirname(resolv_path))
             shutil.copy("/etc/resolv.conf", resolv_path)
     except Exception as e:
         warn("resolv.conf tricks fail: %s" % e)
@@ -404,7 +402,7 @@ def unprepare_chroot(path, mount=True):
     Rollback preparation of a chroot environment inside a directory
     '''
     # untrick resolv.conf
-    if os.path.exists("/etc/resolv.conf"):
+    if os.path.exists("/etc/resolv.conf") and os.path.exists(os.path.join(path, "etc"))::
         resolv_path = os.path.join(path, "etc/resolv.conf")
         if os.path.exists(resolv_path):
             os.unlink(resolv_path)