From 9e10b341d60c4f1a56e184ae3a48f7add3857eda Mon Sep 17 00:00:00 2001 From: Nitesh Konkar Date: Thu, 26 Sep 2019 20:16:02 +0530 Subject: [PATCH] rootfs_builder: Create /etc/resolv.conf in rootfs Create an empty /etc/resolv.conf in rootfs if it does not already exists else preserve it if not a symlink. This would allow the agent to bind mount it for DNS in kata VM. Fixes: #365 Signed-off-by: Nitesh Konkar --- image-builder/image_builder.sh | 3 --- rootfs-builder/rootfs.sh | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/image-builder/image_builder.sh b/image-builder/image_builder.sh index d7878c0cfc..7d7178dc68 100755 --- a/image-builder/image_builder.sh +++ b/image-builder/image_builder.sh @@ -391,9 +391,6 @@ create_rootfs_image() { info "Creating empty machine-id to allow systemd to bind-mount it" touch "${mount_dir}/etc/machine-id" - info "Creating empty resolv.conf to allow kata-agent to bind-mount it" - touch "${mount_dir}/etc/resolv.conf" - info "Unmounting root partition" umount "${mount_dir}" OK "Root partition unmounted" diff --git a/rootfs-builder/rootfs.sh b/rootfs-builder/rootfs.sh index 0b68764f07..ab6a95701a 100755 --- a/rootfs-builder/rootfs.sh +++ b/rootfs-builder/rootfs.sh @@ -510,6 +510,15 @@ EOT [ -x "${init}" ] || [ -L "${init}" ] || die "/sbin/init is not installed in ${ROOTFS_DIR}" OK "init is installed" + # Create an empty /etc/resolv.conf, to allow agent to bind mount container resolv.conf to Kata VM + dns_file="${ROOTFS_DIR}/etc/resolv.conf" + if [ -L "$dns_file" ]; then + # if /etc/resolv.conf is a link, it cannot be used for bind mount + rm -f "$dns_file" + fi + info "Create /etc/resolv.conf file in rootfs if not exist" + touch "$dns_file" + info "Creating summary file" create_summary_file "${ROOTFS_DIR}" }