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