diff options
author | rtkapiper <andy.piper@arcticwolf.com> | 2023-07-11 17:43:55 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-07-13 06:31:18 +0000 |
commit | 680be98e8265644a3f5cd8001433482a549470cd (patch) | |
tree | 78cc88f891d6f89ffe536091a7c5a2d13a27d11e | |
parent | dd8b1aa211181afb653bb36d5767d6c6b728e84d (diff) | |
download | vmdb2-680be98e8265644a3f5cd8001433482a549470cd.tar.gz |
unpack_rootfs_plugin: handle `/etc/resolv.conf` symlink in chroot
When `/etc/resolv.conf` is a symlink in the target image (which will be
the case for many modern Linuxes that use systemd-resolved), copy the
host's `/etc/resolv.conf` to the symlink's target location. This will
allow systemd to be able to use the `/etc/resolv.conf` symlink when the
image is booted.
-rw-r--r-- | vmdb/plugins/unpack_rootfs_plugin.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/vmdb/plugins/unpack_rootfs_plugin.py b/vmdb/plugins/unpack_rootfs_plugin.py index ec0ae6a..fb0945a 100644 --- a/vmdb/plugins/unpack_rootfs_plugin.py +++ b/vmdb/plugins/unpack_rootfs_plugin.py @@ -45,5 +45,10 @@ class UnpackCacheStepRunner(vmdb.StepRunnerInterface): state.rootfs_unpacked = True def copy_resolv_conf(self, rootdir): - filename = os.path.join(rootdir, "etc", "resolv.conf") + # handle the case where /etc/resolv.conf is a symlink on the target + # (which is the case for many modern Linuxes) by copying the host file + # to the target of the symlink in the chroot + filename = os.path.realpath(os.path.join(rootdir, "etc", "resolv.conf")) + target_dir = os.path.dirname(filename) + os.makedirs(target_dir, exist_ok=True) vmdb.runcmd(["cp", "/etc/resolv.conf", filename]) |