]> git.ipfire.org Git - thirdparty/dracut.git/blob - man/dracut.modules.7.asc
fix(dmsquash-live): allow other fstypes
[thirdparty/dracut.git] / man / dracut.modules.7.asc
1 DRACUT.MODULES(7)
2 =================
3 :doctype: manpage
4 :man source: dracut
5 :man manual: dracut
6 :man version: {version}
7
8 NAME
9 ----
10 dracut.modules - dracut modules
11
12 DESCRIPTION
13 -----------
14
15 dracut uses a modular system to build and extend the initramfs image. All
16 modules are located in _/usr/lib/dracut/modules.d_ or in _<git-src>/modules.d_.
17 The most basic dracut module is _99base_. In _99base_ the initial shell script
18 init is defined, which gets run by the kernel after initramfs loading. Although
19 you can replace init with your own version of _99base_, this is not encouraged.
20 Instead you should use, if possible, the hooks of dracut. All hooks, and the
21 point of time in which they are executed, are described in <<stages>>.
22
23 The main script, which creates the initramfs is dracut itself. It parses all
24 arguments and sets up the directory, in which everything is installed. It then
25 executes all check, install, installkernel scripts found in the modules, which
26 are to be processed. After everything is installed, the install directory is
27 archived and compressed to the final initramfs image. All helper functions used
28 by check, install and installkernel are found in in the file _dracut-functions_.
29 These shell functions are available to all module installer (install,
30 installkernel) scripts, without the need to source _dracut-functions_.
31
32 A module can check the preconditions for install and installkernel with the
33 check script. Also dependencies can be expressed with check. If a module passed
34 check, install and installkernel will be called to install all of the necessary
35 files for the module. To split between kernel and non-kernel parts of the
36 installation, all kernel module related parts have to be in installkernel. All
37 other files found in a module directory are module specific and mostly are hook
38 scripts and udev rules.
39
40
41 [[stages]]
42 == Boot Process Stages
43
44 dracut modules can insert custom script at various points, to control the boot
45 process.
46 These hooks are plain directories containing shell scripts ending with ".sh",
47 which are sourced by init.
48 Common used functions are in _dracut-lib.sh_, which can be sourced by any script.
49
50 === Hook: cmdline
51
52 The _cmdline_ hook is a place to insert scripts to parse the kernel command line
53 and prepare the later actions, like setting up udev rules and configuration
54 files.
55
56 In this hook the most important environment variable is defined: root. The
57 second one is rootok, which indicates, that a module claimed to be able to parse
58 the root defined. So for example, **root=**__iscsi:....__ will be claimed by the
59 iscsi dracut module, which then sets rootok.
60
61 === Hook: pre-udev
62
63 This hook is executed right after the cmdline hook and a check if root and
64 rootok were set. Here modules can take action with the final root, and before
65 udev has been run.
66
67 === Start Udev
68
69 Now udev is started and the logging for udev is setup.
70
71 === Hook: pre-trigger
72
73 In this hook, you can set udev environment variables with **udevadm control
74 --property=KEY=_value_** or control the further execution of udev with
75 udevadm.
76
77 === Trigger Udev
78
79 udev is triggered by calling udevadm trigger, which sends add events for all
80 devices and subsystems.
81
82 === Main Loop
83
84 In the main loop of dracut loops until udev has settled and
85 all scripts in _initqueue/finished_ returned true.
86 In this loop there are three hooks, where scripts can be inserted
87 by calling /sbin/initqueue.
88
89 ==== Initqueue
90
91 This hook gets executed every time a script is inserted here, regardless of the
92 udev state.
93
94 ==== Initqueue settled
95
96 This hook (initqueue/settled) gets executed every time udev has settled.
97
98 ==== Initqueue timeout
99
100 This hook (initqueue/timeout) gets executed, when the main loop counter becomes
101 half of the rd.retry counter.
102
103 ==== Initqueue online
104
105 This hook (initqueue/online) gets executed whenever a network interface comes online
106 (that is, once it is up and configured by the configured network module).
107
108 ==== Initqueue finished
109
110 This hook (initqueue/finished) is called after udev has settled and
111 if all scripts herein return 0 the main loop will be ended.
112 Arbitrary scripts can be added here, to loop in the
113 initqueue until something happens, which a dracut module wants to wait for.
114
115 === Hook: pre-mount
116
117 Before the root device is mounted all scripts in the hook pre-mount are
118 executed. In some cases (e.g. NFS) the real root device is already mounted,
119 though.
120
121 === Hook: mount
122
123 This hook is mainly to mount the real root device.
124
125 === Hook: pre-pivot
126
127 This hook is called before cleanup hook, This is a good place for
128 actions other than cleanups which need to be called before pivot.
129
130 === Hook: cleanup
131
132 This hook is the last hook and is called before init finally switches root to
133 the real root device. This is a good place to clean up and kill processes not
134 needed anymore.
135
136
137 === Cleanup and switch_root
138
139 Init (or systemd) kills all udev processes, cleans up the environment,
140 sets up the arguments for the real init process and finally calls switch_root.
141 switch_root removes the whole filesystem hierarchy of the initramfs,
142 chroot()s to the real root device and calls /sbin/init with the specified
143 arguments.
144
145 To ensure all files in the initramfs hierarchy can be removed, all processes
146 still running from the initramfs should not have any open file descriptors left.
147
148 == Network Infrastructure
149
150 FIXME
151
152 == Writing a Module
153
154 A simple example module is _90kernel-modules_, which modprobes a kernel module
155 after udev has settled and the basic device drivers have been loaded.
156
157 All module installation information is in the file module-setup.sh.
158
159 First we create a check() function, which just exits with 0 indicating that this
160 module should be included by default.
161
162 check():
163 ----
164 return 0
165 ----
166
167 Then we create the install() function, which installs a cmdline hook with
168 priority number 20 called _parse-insmodpost.sh_. It also installs the
169 _insmodpost.sh_ script in _/sbin_.
170
171 install():
172 ----
173 inst_hook cmdline 20 "$moddir/parse-insmodpost.sh"
174 inst_simple "$moddir/insmodpost.sh" /sbin/insmodpost.sh
175 ----
176
177 The _parse-instmodpost.sh_ parses the kernel command line for a argument
178 rd.driver.post, blacklists the module from being autoloaded and installs the
179 hook _insmodpost.sh_ in the _initqueue/settled_.
180
181 _parse-insmodpost.sh_:
182 ----
183 for p in $(getargs rd.driver.post=); do
184 echo "blacklist $p" >> /etc/modprobe.d/initramfsblacklist.conf
185 _do_insmodpost=1
186 done
187
188 [ -n "$_do_insmodpost" ] && /sbin/initqueue --settled --unique --onetime /sbin/insmodpost.sh
189 unset _do_insmodpost
190
191 ----
192
193 _insmodpost.sh_, which is called in the _initqueue/settled_ hook will just
194 modprobe the kernel modules specified in all rd.driver.post kernel command line
195 parameters. It runs after udev has settled and is only called once (--onetime).
196
197 _insmodpost.sh_:
198 ----
199 . /lib/dracut-lib.sh
200
201 for p in $(getargs rd.driver.post=); do
202 modprobe $p
203 done
204
205 ----
206
207
208 === module-setup.sh: check()
209
210 _check()_ is called by dracut to evaluate the inclusion of a dracut module in
211 the initramfs.
212
213 $hostonly:: If the $hostonly variable is set, then the module check() function
214 should be in "hostonly" mode, which means, that the check() should only return
215 0, if the module is really needed to boot this specific host.
216
217 check() should return with:
218
219 0:: Include the dracut module in the initramfs.
220
221 1:: Do not include the dracut module. The requirements are not fulfilled
222 (missing tools, etc.)
223
224 255:: Only include the dracut module, if another module requires it or if
225 explicitly specified in the config file or on the argument list.
226
227
228 === module-setup.sh: depends()
229
230 The function depends() should echo all other dracut module names the module
231 depends on.
232
233 === module-setup.sh: cmdline()
234
235 This function should print the kernel command line options needed to boot the
236 current machine setup. It should start with a space and should not print a
237 newline.
238
239 === module-setup.sh: install()
240
241 The install() function is called to install everything non-kernel related.
242 To install binaries, scripts, and other files, you can use the functions
243 mentioned in <<creation>>.
244
245 To address a file in the current module directory, use the variable "$moddir".
246
247 === module-setup.sh: installkernel()
248
249 In installkernel() all kernel related files should be installed. You can use all
250 of the functions mentioned in <<creation>> to install files.
251
252 === [[creation]]Creation Functions
253
254 ==== inst_multiple [-o] <file> [ <file> ...]
255
256 installs multiple binaries and files. If executables are specified without a
257 path, dracut will search the path PATH=/usr/sbin:/sbin:/usr/bin:/bin for the
258 binary. If the option "-o" is given as the first parameter, a missing file does
259 not lead to an error.
260
261 ==== inst <src> [<dst>]
262
263 installs _one_ file <src> either to the same place in the initramfs or to an
264 optional <dst>. inst with more than two arguments is treated the same as
265 inst_multiple, all arguments are treated as files to install and none as
266 install destinations.
267
268 ==== inst_hook <hookdir> <prio> <src>
269
270 installs an executable/script <src> in the dracut hook <hookdir> with priority
271 <prio>.
272
273 ==== inst_rules <udevrule> [ <udevrule> ...]
274
275 installs one or more udev rules. Non-existant udev rules are reported, but do
276 not let dracut fail.
277
278 ==== instmods <kernelmodule> [ <kernelmodule> ... ]
279
280 instmods should be used only in the installkernel() function.
281
282 instmods installs one or more kernel modules in the initramfs. <kernelmodule>
283 can also be a whole subsystem, if prefixed with a "=", like "=drivers/net/team".
284
285 instmods will not install the kernel module, if $hostonly is set and the kernel
286 module is not currently needed by any /sys/*...*/uevent MODALIAS.
287 To install a kernel module regardless of the hostonly mode use the form:
288 ----
289 hostonly='' instmods <kernelmodule>
290 ----
291
292 === Initramfs Functions
293
294 FIXME
295
296
297 === Network Modules
298
299 FIXME
300
301 AUTHOR
302 ------
303 Harald Hoyer
304
305 SEE ALSO
306 --------
307 *dracut*(8)