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