4 # Add a systemd unit file to the initcpio image. Hard dependencies on binaries
5 # and other unit files will be discovered and added.
6 # $1: path to rules file (or name of rules file)
8 local unit
= rule
= entry
= key
= value
= binary
= dep
=
10 unit
=$
(PATH
=/usr
/lib
/systemd
/system
:/lib
/systemd
/system
type -P "$1")
11 if [[ -z $unit ]]; then
12 # complain about not found unit file
18 while IFS
='=' read -r key values
; do
19 read -ra values
<<< "$values"
23 # only add hard dependencies (not Wants)
24 map add_systemd_unit
"${values[@]}"
27 # do not add binaries unless they are required,
28 # strip special executable prefixes
31 !!*) add_binary
"${values[0]#!!}" ;;
32 *) add_binary
"${values[0]#[@!:+]}" ;;
39 # preserve reverse soft dependency
40 for dep
in {/usr
,}/lib
/systemd
/system
/*.wants
/${unit##*/}; do
41 if [[ -L $dep ]]; then
46 # add hard dependencies
47 if [[ -d $unit.requires
]]; then
48 for dep
in "$unit".requires
/*; do
49 add_systemd_unit
${dep##*/}
54 add_systemd_drop_in
() {
55 local unit
=$1 dropin_name
=$2
57 mkdir
-p "$BUILDROOT/etc/systemd/system/$unit.d"
58 cat >"$BUILDROOT/etc/systemd/system/$unit.d/$2.conf"
64 add_binary
/usr
/bin
/kmod
/usr
/bin
/modprobe
65 add_binary
/usr
/bin
/mount
66 add_binary
/usr
/bin
/sulogin
67 add_binary
/usr
/bin
/umount
68 add_binary
/usr
/lib
/systemd
/systemd
/init
72 /usr
/bin
/systemd-tmpfiles \
73 /usr
/lib
/systemd
/systemd-hibernate-resume \
74 /usr
/lib
/systemd
/systemd-shutdown \
75 /usr
/lib
/systemd
/systemd-sulogin-shell \
76 /usr
/lib
/systemd
/system-generators
/systemd-fstab-generator \
77 /usr
/lib
/systemd
/system-generators
/systemd-gpt-auto-generator \
78 /usr
/lib
/systemd
/system-generators
/systemd-hibernate-resume-generator
81 map add_udev_rule
"$rules" \
82 50-udev-default.rules \
83 60-persistent-storage.rules \
89 map add_systemd_unit \
90 initrd-cleanup.service \
92 initrd-parse-etc.service \
93 initrd-root-fs.target \
94 initrd-root-device.target \
95 initrd-switch-root.service \
96 initrd-switch-root.target \
97 initrd-udevadm-cleanup-db.service \
99 kmod-static-nodes.service \
101 local-fs-pre.target \
107 systemd-fsck@.service \
108 systemd-hibernate-resume@.service \
109 systemd-journald-audit.socket \
110 systemd-journald-dev-log.socket \
111 systemd-journald.service \
112 systemd-modules-load.service \
113 systemd-pcrphase-initrd.service \
114 systemd-tmpfiles-setup-dev.service \
115 systemd-udevd-control.socket \
116 systemd-udevd-kernel.socket \
117 systemd-udevd.service \
118 systemd-udev-trigger.service \
123 # add libraries dlopen()ed by tpm2-util
124 for LIB
in tss2-
{esys
,rc
,mu
,tcti-
'*'}; do
125 for FILE
in $
(find /usr
/lib
/ -maxdepth 1 -name "lib${LIB}.so*"); do
126 if [[ -L "${FILE}" ]]; then
127 add_symlink
"${FILE}"
134 add_symlink
"/usr/lib/systemd/system/default.target" "initrd.target"
135 add_symlink
"/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
137 printf '%s\n' >"$BUILDROOT/etc/nsswitch.conf" \
142 echo "root:x:0:0:root:/root:/bin/sh" >"$BUILDROOT/etc/passwd"
143 echo 'root:*:::::::' >"$BUILDROOT/etc/shadow"
144 getent group root audio disk input kmem kvm
lp optical render sgx storage tty
uucp video |
awk -F: ' { print $1 ":x:" $3 ":" }' >"$BUILDROOT/etc/group"
146 add_dir
"/etc/modules-load.d"
150 printf '%s\n' ${MODULES[@]} >"$BUILDROOT/etc/modules-load.d/MODULES.conf"
156 This will install a basic systemd setup in your initramfs, and is meant to
157 replace the 'base', 'usr', 'udev' and 'resume' hooks. Other hooks with runtime
158 components will need to be ported, and will not work as intended. You also may
159 wish to still include the 'base' hook (before this hook) to ensure that a
160 rescue shell exists on your initramfs.
164 # vim: set ft=sh ts=4 sw=4 et: