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
80 # udev rules and systemd units
81 map add_udev_rule
"$rules" \
82 50-udev-default.rules \
83 60-persistent-storage.rules \
88 map add_systemd_unit \
89 initrd-cleanup.service \
91 initrd-parse-etc.service \
92 initrd-root-fs.target \
93 initrd-root-device.target \
94 initrd-switch-root.service \
95 initrd-switch-root.target \
96 initrd-udevadm-cleanup-db.service \
98 kmod-static-nodes.service \
100 local-fs-pre.target \
106 systemd-fsck@.service \
107 systemd-hibernate-resume@.service \
108 systemd-journald.service \
109 systemd-journald-audit.socket \
110 systemd-journald-dev-log.socket \
111 systemd-modules-load.service \
112 systemd-tmpfiles-setup-dev.service \
113 systemd-udev-trigger.service \
114 systemd-udevd-control.socket \
115 systemd-udevd-kernel.socket \
116 systemd-udevd.service \
121 add_symlink
"/usr/lib/systemd/system/default.target" "initrd.target"
122 add_symlink
"/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
124 printf '%s\n' >"$BUILDROOT/etc/nsswitch.conf" \
129 echo "root:x:0:0:root:/root:/bin/sh" >"$BUILDROOT/etc/passwd"
130 echo 'root:*:::::::' >"$BUILDROOT/etc/shadow"
131 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"
133 add_dir
"/etc/modules-load.d"
137 printf '%s\n' ${MODULES[@]} >"$BUILDROOT/etc/modules-load.d/MODULES.conf"
143 This will install a basic systemd setup in your initramfs, and is meant to
144 replace the 'base', 'usr', 'udev' and 'resume' hooks. Other hooks with runtime
145 components will need to be ported, and will not work as intended. You also may
146 wish to still include the 'base' hook (before this hook) to ensure that a
147 rescue shell exists on your initramfs.
151 # vim: set ft=sh ts=4 sw=4 et: