4 # Add an udev rules file to the initcpio image. Dependencies on binaries
5 # will be discovered and added.
6 # $1: path to rules file (or name of rules file)
8 local rules
="$1" rule
= key
= value
= binary
=
10 if [[ ${rules:0:1} != '/' ]]; then
11 rules
=$
(PATH
=/usr
/lib
/udev
/rules.d
:/lib
/udev
/rules.d
type -P "$1")
13 if [[ -z $rules ]]; then
14 # complain about not found rules
18 add_file
"$rules" /usr
/lib
/udev
/rules.d
/"${rules##*/}"
20 while IFS
=, read -ra rule
; do
21 # skip empty lines, comments
22 [[ -z $rule ||
$rule = @
(+([[:space
:]])|
#*) ]] && continue
24 for pair
in "${rule[@]}"; do
25 IFS
=' =' read -r key value
<<< "$pair"
27 RUN@
({program
}|
+)|IMPORT
{program
}|ENV
{REMOVE_CMD
})
29 binary
=${value//[\"\']/}
30 # just take the first word as the binary name
32 [[ ${binary:0:1} == '$' ]] && continue
33 if [[ ${binary:0:1} != '/' ]]; then
34 binary
=$
(PATH
=/usr
/lib
/udev
:/lib
/udev
type -P "$binary")
44 # Add a systemd unit file to the initcpio image. Hard dependencies on binaries
45 # and other unit files will be discovered and added.
46 # $1: path to rules file (or name of rules file)
48 local unit
= rule
= entry
= key
= value
= binary
= dep
=
50 unit
=$
(PATH
=/usr
/lib
/systemd
/system
:/lib
/systemd
/system
:/usr
/lib64
/systemd
/system
:/lib64
/systemd
/system
type -P "$1")
51 if [[ -z $unit ]]; then
52 # complain about not found unit file
58 while IFS
='=' read -r key values
; do
59 read -ra values
<<< "$values"
63 # only add hard dependencies (not Wants)
64 map add_systemd_unit
"${values[@]}"
67 # do not add binaries unless they are required,
68 # strip special executable prefixes
71 !!*) add_binary
"${values[0]#!!}" ;;
72 *) add_binary
"${values[0]#[@!:+]}" ;;
79 # preserve reverse soft dependency
80 for dep
in {/usr
,}/lib
/systemd
/system
/*.wants
/${unit##*/}; do
81 if [[ -L $dep ]]; then
86 # add hard dependencies
87 if [[ -d $unit.requires
]]; then
88 for dep
in "$unit".requires
/*; do
89 add_systemd_unit
${dep##*/}
94 add_systemd_drop_in
() {
95 local unit
=$1 dropin_name
=$2
97 mkdir
-p "$BUILDROOT/etc/systemd/system/$unit.d"
98 cat >"$BUILDROOT/etc/systemd/system/$unit.d/$2.conf"
106 if [ -e /usr
/lib64
] ; then
112 add_binary
/usr
/lib
/initcpio
/busybox
/usr
/bin
/busybox
113 add_symlink
"/bin" /usr
/bin
115 for applet
in $
(/usr
/lib
/initcpio
/busybox
--list |
grep -v busybox
); do
116 add_symlink
"/usr/bin/$applet" /usr
/bin
/busybox
119 add_binary
/usr
/bin
/sulogin
120 add_binary
/usr
/lib
/systemd
/systemd
/init
121 add_file
/etc
/os-release
122 add_file
/etc
/machine-id
123 add_file
/etc
/machine-info
126 /usr
/bin
/systemd-tmpfiles \
127 /usr
/lib
/systemd
/systemd-executor \
128 /usr
/lib
/systemd
/systemd-hibernate-resume \
129 /usr
/lib
/systemd
/systemd-shutdown \
130 /usr
/lib
/systemd
/systemd-sulogin-shell \
131 /usr
/lib
/systemd
/system-generators
/systemd-fstab-generator \
132 /usr
/lib
/systemd
/system-generators
/systemd-gpt-auto-generator \
133 /usr
/lib
/systemd
/system-generators
/systemd-hibernate-resume-generator
135 # udev rules and systemd units
136 map add_udev_rule
"$rules" \
137 50-udev-default.rules \
138 60-persistent-storage.rules \
143 map add_systemd_unit \
144 initrd-cleanup.service \
146 initrd-parse-etc.service \
147 initrd-root-fs.target \
148 initrd-root-device.target \
149 initrd-switch-root.service \
150 initrd-switch-root.target \
153 local-fs-pre.target \
158 systemd-fsck@.service \
159 systemd-hibernate-resume@.service \
160 systemd-modules-load.service \
161 systemd-udev-trigger.service \
162 systemd-udevd-control.socket \
163 systemd-udevd-kernel.socket \
164 systemd-udevd.service \
169 add_symlink
"/usr/lib/systemd/system/default.target" "initrd.target"
170 add_symlink
"/usr/lib/systemd/system/ctrl-alt-del.target" "reboot.target"
172 add_binary
"$(readlink -f /usr/$libdir/libnss_files.so.2)"
173 add_binary
"$(readlink -f /usr/$libdir/libnss_systemd.so.2)"
174 printf '%s\n' >"$BUILDROOT/etc/nsswitch.conf" \
175 'passwd: files systemd' \
176 'group: files [SUCCESS=merge] systemd' \
177 'shadow: files [UNAVAIL=return] systemd'
179 echo "root:x:0:0:root:/root:/bin/sh" >"$BUILDROOT/etc/passwd"
180 echo 'root::18684::::::' >"$BUILDROOT/etc/shadow"
181 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"
183 for sysuserfile
in $
(ls /usr
/lib
/sysusers.d
/) ; do
184 add_file
/usr
/lib
/sysusers.d
/${sysuserfile}
187 add_dir
"/etc/modules-load.d"
191 printf '%s\n' ${MODULES[@]} >"$BUILDROOT/etc/modules-load.d/MODULES.conf"
195 echo -e "[Manager]\\nDefaultStandardOutput=inherit" > $BUILDROOT/etc
/systemd
/system.conf
200 This will install a basic systemd setup in your initramfs, and is meant to
201 replace the 'base', 'usr', 'udev' and 'resume' hooks. Other hooks with runtime
202 components will need to be ported, and will not work as intended. You also may
203 wish to still include the 'base' hook (before this hook) to ensure that a
204 rescue shell exists on your initramfs.
208 # vim: set ft=sh ts=4 sw=4 et: