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 <niteshkonkar@in.ibm.com>
This commit is contained in:
Nitesh Konkar 2019-09-26 20:16:02 +05:30
parent c33068de10
commit 9e10b341d6
2 changed files with 9 additions and 3 deletions

View File

@ -391,9 +391,6 @@ create_rootfs_image() {
info "Creating empty machine-id to allow systemd to bind-mount it" info "Creating empty machine-id to allow systemd to bind-mount it"
touch "${mount_dir}/etc/machine-id" 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" info "Unmounting root partition"
umount "${mount_dir}" umount "${mount_dir}"
OK "Root partition unmounted" OK "Root partition unmounted"

View File

@ -510,6 +510,15 @@ EOT
[ -x "${init}" ] || [ -L "${init}" ] || die "/sbin/init is not installed in ${ROOTFS_DIR}" [ -x "${init}" ] || [ -L "${init}" ] || die "/sbin/init is not installed in ${ROOTFS_DIR}"
OK "init is installed" 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" info "Creating summary file"
create_summary_file "${ROOTFS_DIR}" create_summary_file "${ROOTFS_DIR}"
} }