summaryrefslogtreecommitdiffstats
path: root/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh
blob: 58f23207aa059624bc7a27385791ad665903eb35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh

# Copy out services over to stage 4, so they still appear in
# systemd-analyze plot etc.
new_systemd_system_unit_path="${NEWROOT}/lib/systemd/system"

mkdir --parents "$new_systemd_system_unit_path/initrd.target.wants"

for dir in /run/systemd/system /lib/systemd/system /etc/systemd/system; do
	for file in "$dir"/s3-*.{service,target} "$dir"/dracut-*.{service,target}; do
		[ -f "$file" ] || continue
		name="${file##*/}"
		cp "${file}" "${new_systemd_system_unit_path}/${name}"
		source_path="../${name}"
		target_path="${new_systemd_system_unit_path}/initrd.target.wants/${name}"
		ln -nfs "$source_path" "$target_path" || \
			warn "Failed to link \"$source_path\" to \"$target_path\"."
	done
done