summaryrefslogtreecommitdiffstats
path: root/builder/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh
blob: 9510c8d30119eaeb1eb5336ae612317aa44558cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#!/bin/bash
#
# This hook copies the core systemd-networkd related service
# to the NEWROOT and activated them in sysinit.target
# to prevent systemd from killing these while pivot_root
new_sysinit_wants="${NEWROOT}/usr/lib/systemd/system/sysinit.target.wants/"
mkdir -p "${new_sysinit_wants}"

for unit in \
	systemd-networkd.socket \
	systemd-networkd.service \
	systemd-networkd-wait-online.service \
	systemd-resolved.service
do
	service_path="$(systemctl show -p FragmentPath $unit | cut -c 14-)"
	cp "${service_path}" "${NEWROOT}/${service_path}"
	ln -sf "../${unit}" "${new_sysinit_wants}/${unit}"
done

# this drop-in is needed to prevent a pull-in loop sysinit.target <-> basic.target
mkdir -p "${NEWROOT}/usr/lib/systemd/system/systemd-resolved.service.d/"
echo '[Unit]' > "${NEWROOT}/usr/lib/systemd/system/systemd-resolved.service.d/00-no-default-deps.conf"
echo 'DefaultDependencies=no' >> "${NEWROOT}/usr/lib/systemd/system/systemd-resolved.service.d/00-no-default-deps.conf"

# 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