]> git.ipfire.org Git - thirdparty/dracut.git/blob - modules.d/00systemd/module-setup.sh
added debug-shell to initrd in systemd version >= 240
[thirdparty/dracut.git] / modules.d / 00systemd / module-setup.sh
1 #!/bin/bash
2
3 getSystemdVersion() {
4 SYSTEMD_VERSION=$($systemdutildir/systemd --version | { read a b a; echo $b; })
5 # Check if the systemd version is a valid number
6 if ! [[ $SYSTEMD_VERSION =~ ^[0-9]+$ ]]; then
7 dfatal "systemd version is not a number ($SYSTEMD_VERSION)"
8 exit 1
9 fi
10
11 echo $SYSTEMD_VERSION
12 }
13
14 # called by dracut
15 check() {
16 [[ $mount_needs ]] && return 1
17 if require_binaries $systemdutildir/systemd; then
18 SYSTEMD_VERSION=$(getSystemdVersion)
19 (( $SYSTEMD_VERSION >= 198 )) && return 0
20 return 255
21 fi
22
23 return 1
24 }
25
26 # called by dracut
27 depends() {
28 return 0
29 }
30
31 installkernel() {
32 hostonly='' instmods autofs4 ipv6 algif_hash hmac sha256
33 instmods -s efivarfs
34 }
35
36 # called by dracut
37 install() {
38 local _mods
39
40 if [[ "$prefix" == /run/* ]]; then
41 dfatal "systemd does not work with a prefix, which contains \"/run\"!!"
42 exit 1
43 fi
44
45 if [ $(getSystemdVersion) -ge 240 ]; then
46 inst_multiple -o \
47 $systemdutildir/system-generators/systemd-debug-generator \
48 $systemdsystemunitdir/debug-shell.service
49 fi
50
51 inst_multiple -o \
52 $systemdutildir/systemd \
53 $systemdutildir/systemd-coredump \
54 $systemdutildir/systemd-cgroups-agent \
55 $systemdutildir/systemd-shutdown \
56 $systemdutildir/systemd-reply-password \
57 $systemdutildir/systemd-fsck \
58 $systemdutildir/systemd-udevd \
59 $systemdutildir/systemd-journald \
60 $systemdutildir/systemd-sysctl \
61 $systemdutildir/systemd-modules-load \
62 $systemdutildir/systemd-vconsole-setup \
63 $systemdutildir/systemd-volatile-root \
64 $systemdutildir/system-generators/systemd-fstab-generator \
65 $systemdutildir/system-generators/systemd-gpt-auto-generator \
66 \
67 $systemdsystemunitdir/cryptsetup.target \
68 $systemdsystemunitdir/emergency.target \
69 $systemdsystemunitdir/sysinit.target \
70 $systemdsystemunitdir/basic.target \
71 $systemdsystemunitdir/halt.target \
72 $systemdsystemunitdir/kexec.target \
73 $systemdsystemunitdir/local-fs.target \
74 $systemdsystemunitdir/local-fs-pre.target \
75 $systemdsystemunitdir/remote-fs.target \
76 $systemdsystemunitdir/remote-fs-pre.target \
77 $systemdsystemunitdir/multi-user.target \
78 $systemdsystemunitdir/network.target \
79 $systemdsystemunitdir/network-pre.target \
80 $systemdsystemunitdir/network-online.target \
81 $systemdsystemunitdir/nss-lookup.target \
82 $systemdsystemunitdir/nss-user-lookup.target \
83 $systemdsystemunitdir/poweroff.target \
84 $systemdsystemunitdir/reboot.target \
85 $systemdsystemunitdir/rescue.target \
86 $systemdsystemunitdir/rpcbind.target \
87 $systemdsystemunitdir/shutdown.target \
88 $systemdsystemunitdir/final.target \
89 $systemdsystemunitdir/sigpwr.target \
90 $systemdsystemunitdir/sockets.target \
91 $systemdsystemunitdir/swap.target \
92 $systemdsystemunitdir/timers.target \
93 $systemdsystemunitdir/paths.target \
94 $systemdsystemunitdir/umount.target \
95 \
96 $systemdsystemunitdir/sys-kernel-config.mount \
97 \
98 $systemdsystemunitdir/kmod-static-nodes.service \
99 $systemdsystemunitdir/systemd-tmpfiles-setup.service \
100 $systemdsystemunitdir/systemd-tmpfiles-setup-dev.service \
101 $systemdsystemunitdir/systemd-ask-password-console.path \
102 $systemdsystemunitdir/systemd-udevd-control.socket \
103 $systemdsystemunitdir/systemd-udevd-kernel.socket \
104 $systemdsystemunitdir/systemd-ask-password-plymouth.path \
105 $systemdsystemunitdir/systemd-journald.socket \
106 $systemdsystemunitdir/systemd-journald-audit.socket \
107 $systemdsystemunitdir/systemd-ask-password-console.service \
108 $systemdsystemunitdir/systemd-modules-load.service \
109 $systemdsystemunitdir/systemd-halt.service \
110 $systemdsystemunitdir/systemd-poweroff.service \
111 $systemdsystemunitdir/systemd-reboot.service \
112 $systemdsystemunitdir/systemd-kexec.service \
113 $systemdsystemunitdir/systemd-fsck@.service \
114 $systemdsystemunitdir/systemd-udevd.service \
115 $systemdsystemunitdir/systemd-udev-trigger.service \
116 $systemdsystemunitdir/systemd-udev-settle.service \
117 $systemdsystemunitdir/systemd-ask-password-plymouth.service \
118 $systemdsystemunitdir/systemd-journald.service \
119 $systemdsystemunitdir/systemd-vconsole-setup.service \
120 $systemdsystemunitdir/systemd-volatile-root.service \
121 $systemdsystemunitdir/systemd-random-seed-load.service \
122 $systemdsystemunitdir/systemd-random-seed.service \
123 $systemdsystemunitdir/systemd-sysctl.service \
124 \
125 $systemdsystemunitdir/sysinit.target.wants/systemd-modules-load.service \
126 $systemdsystemunitdir/sysinit.target.wants/systemd-ask-password-console.path \
127 $systemdsystemunitdir/sysinit.target.wants/systemd-journald.service \
128 $systemdsystemunitdir/sockets.target.wants/systemd-udevd-control.socket \
129 $systemdsystemunitdir/sockets.target.wants/systemd-udevd-kernel.socket \
130 $systemdsystemunitdir/sockets.target.wants/systemd-journald.socket \
131 $systemdsystemunitdir/sockets.target.wants/systemd-journald-audit.socket \
132 $systemdsystemunitdir/sockets.target.wants/systemd-journald-dev-log.socket \
133 $systemdsystemunitdir/sysinit.target.wants/systemd-udevd.service \
134 $systemdsystemunitdir/sysinit.target.wants/systemd-udev-trigger.service \
135 $systemdsystemunitdir/sysinit.target.wants/kmod-static-nodes.service \
136 $systemdsystemunitdir/sysinit.target.wants/systemd-tmpfiles-setup.service \
137 $systemdsystemunitdir/sysinit.target.wants/systemd-tmpfiles-setup-dev.service \
138 $systemdsystemunitdir/sysinit.target.wants/systemd-sysctl.service \
139 \
140 $systemdsystemunitdir/ctrl-alt-del.target \
141 $systemdsystemunitdir/reboot.target \
142 $systemdsystemunitdir/systemd-reboot.service \
143 $systemdsystemunitdir/syslog.socket \
144 \
145 $systemdsystemunitdir/slices.target \
146 $systemdsystemunitdir/system.slice \
147 $systemdsystemunitdir/-.slice \
148 \
149 $tmpfilesdir/systemd.conf \
150 \
151 journalctl systemctl \
152 echo swapoff \
153 kmod insmod rmmod modprobe modinfo depmod lsmod \
154 mount umount reboot poweroff \
155 systemd-run systemd-escape \
156 systemd-cgls systemd-tmpfiles \
157 /etc/udev/udev.hwdb \
158 ${NULL}
159
160 inst_multiple -o \
161 /usr/lib/modules-load.d/*.conf \
162 /usr/lib/sysctl.d/*.conf
163
164 modules_load_get() {
165 local _line i
166 for i in "$1"/*.conf; do
167 [[ -f $i ]] || continue
168 while read _line || [ -n "$_line" ]; do
169 case $_line in
170 \#*)
171 ;;
172 \;*)
173 ;;
174 *)
175 echo $_line
176 esac
177 done < "$i"
178 done
179 }
180
181 _mods=$(modules_load_get /usr/lib/modules-load.d)
182 [[ $_mods ]] && hostonly='' instmods $_mods
183
184 if [[ $hostonly ]]; then
185 inst_multiple -H -o \
186 /etc/systemd/journald.conf \
187 /etc/systemd/journald.conf.d/*.conf \
188 /etc/systemd/system.conf \
189 /etc/systemd/system.conf.d/*.conf \
190 /etc/hostname \
191 /etc/machine-id \
192 /etc/machine-info \
193 /etc/vconsole.conf \
194 /etc/locale.conf \
195 /etc/modules-load.d/*.conf \
196 /etc/sysctl.d/*.conf \
197 /etc/sysctl.conf \
198 /etc/udev/udev.conf \
199 ${NULL}
200
201 _mods=$(modules_load_get /etc/modules-load.d)
202 [[ $_mods ]] && hostonly='' instmods $_mods
203 fi
204
205 if ! [[ -e "$initdir/etc/machine-id" ]]; then
206 > "$initdir/etc/machine-id"
207 fi
208
209 # install adm user/group for journald
210 inst_multiple nologin
211 grep '^systemd-journal:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
212 grep '^adm:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
213 grep '^systemd-journal:' /etc/group >> "$initdir/etc/group"
214 grep '^wheel:' /etc/group >> "$initdir/etc/group"
215 grep '^adm:' /etc/group >> "$initdir/etc/group"
216 grep '^utmp:' /etc/group >> "$initdir/etc/group"
217 grep '^root:' /etc/group >> "$initdir/etc/group"
218
219 # we don't use systemd-networkd, but the user is in systemd.conf tmpfiles snippet
220 grep '^systemd-network:' /etc/passwd 2>/dev/null >> "$initdir/etc/passwd"
221 grep '^systemd-network:' /etc/group >> "$initdir/etc/group"
222
223 ln_r $systemdutildir/systemd "/init"
224 ln_r $systemdutildir/systemd "/sbin/init"
225
226 inst_binary true
227 ln_r $(type -P true) "/usr/bin/loginctl"
228 ln_r $(type -P true) "/bin/loginctl"
229 inst_rules \
230 70-uaccess.rules \
231 71-seat.rules \
232 73-seat-late.rules \
233 90-vconsole.rules \
234 99-systemd.rules \
235 ${NULL}
236
237 for i in \
238 emergency.target \
239 rescue.target \
240 systemd-ask-password-console.service \
241 systemd-ask-password-plymouth.service \
242 ; do
243 mkdir -p "${initdir}${systemdsystemunitdir}/${i}.wants"
244 ln_r "${systemdsystemunitdir}/systemd-vconsole-setup.service" \
245 "${systemdsystemunitdir}/${i}.wants/systemd-vconsole-setup.service"
246 done
247
248 mkdir -p "$initdir/etc/systemd"
249 # We must use a volatile journal, and we don't want rate-limiting
250 {
251 echo "[Journal]"
252 echo "Storage=volatile"
253 echo "RateLimitInterval=0"
254 echo "RateLimitBurst=0"
255 } >> "$initdir/etc/systemd/journald.conf"
256
257 ln_r "${systemdsystemunitdir}/multi-user.target" "${systemdsystemunitdir}/default.target"
258 }
259