diff options
Diffstat (limited to 'modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh')
-rw-r--r-- | modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh b/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh new file mode 100644 index 00000000..ec61616c --- /dev/null +++ b/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# This hook copies the core systemd-networkd related service +# files to the NEWROOT and activate them in sysinit.target +# to prevent systemd from killing these while pivot_root +NEWROOT_SYSTEMD_DIR="${NEWROOT}/usr/lib/systemd/system" +NEWROOT_SYSINIT_TARGET_DIR="${NEWROOT_SYSTEMD_DIR}/sysinit.target.wants" +mkdir -p "${NEWROOT_SYSINIT_TARGET_DIR}" + +for UNIT in \ + systemd-networkd.socket \ + systemd-networkd.service \ + systemd-resolved.service +do + UNIT_PATH="$(systemctl show -p FragmentPath $UNIT | cut -c 14-)" + [ -z "${UNIT_PATH}" ] && continue + mkdir -p "${NEWROOT}/${UNIT_PATH%/*}" + cp "${UNIT_PATH}" "${NEWROOT}/${UNIT_PATH}" + ln -sf "${UNIT_PATH}" "${NEWROOT_SYSINIT_TARGET_DIR}/${UNIT}" +done + +if [ -e "${NEWROOT_SYSTEMD_DIR}/systemd-resolved.service" ]; then + # this drop-in is needed to prevent a pull-in loop sysinit.target <-> basic.target + mkdir -p "${NEWROOT_SYSTEMD_DIR}/systemd-resolved.service.d/" + cat <<-EOF > "${NEWROOT_SYSTEMD_DIR}/systemd-resolved.service.d/00-no-default-deps.conf" + [Unit] + DefaultDependencies=no + EOF + + # finally make sure the NEWROOT resolv.conf links to the one managed by resolved. + rm "${NEWROOT}"/etc/resolv.conf + ln -s /run/systemd/resolve/resolv.conf "${NEWROOT}"/etc/resolv.conf +fi |