The main script, which creates the initramfs is dracut itself. It parses all arguments and sets up the directory, in which everything is installed. It then executes all check, install, installkernel scripts found in the modules, which are to be processed. After everything is installed, the install directory is archived and compressed to the final initramfs image. All helper functions used by check, install and installkernel are found in in the file dracut-functions. These shell functions are available to all module installer (install, installkernel) scripts, without the need to source dracut-functions.
A module can check the preconditions for install and installkernel with the check script. Also dependencies can be expressed with check. If a module passed check, install and installkernel will be called to install all of the necessary files for the module. To split between kernel and non-kernel parts of the installation, all kernel module related parts have to be in installkernel. All other files found in a module directory are module specific and mostly are hook scripts and udev rules.
In this hook the most important environment variable is defined: root. The second one is rootok, which indicates, that a module claimed to be able to parse the root defined. So for example, root=iscsi:.... will be claimed by the iscsi dracut module, which then sets rootok.
This hook gets executed every time a script is inserted here, regardless of the udev state.
This hook (initqueue/settled) gets executed every time udev has settled.
This hook (initqueue/timeout) gets executed, when the main loop counter becomes half of the rd.retry counter.
This hook (initqueue/online) gets executed whenever a network interface comes online (that is, once it is up and configured by the configured network module).
This hook (initqueue/finished) is called after udev has settled and if all scripts herein return 0 the main loop will be ended. Arbitrary scripts can be added here, to loop in the initqueue until something happens, which a dracut module wants to wait for.
To ensure all files in the initramfs hierarchy can be removed, all processes still running from the initramfs should not have any open file descriptors left.
All module installation information is in the file module-setup.sh.
First we create a check() function, which just exits with 0 indicating that this module should be included by default.
Then we create the install() function, which installs a cmdline hook with priority number 20 called parse-insmodpost.sh. It also installs the insmodpost.sh script in /sbin.
inst_hook cmdline 20 "$moddir/parse-insmodpost.sh" inst_simple "$moddir/insmodpost.sh" /sbin/insmodpost.sh
The parse-instmodpost.sh parses the kernel command line for a argument rd.driver.post, blacklists the module from being autoloaded and installs the hook insmodpost.sh in the initqueue/settled.
for p in $(getargs rd.driver.post=); do echo "blacklist $p" >> /etc/modprobe.d/initramfsblacklist.conf _do_insmodpost=1 done [ -n "$_do_insmodpost" ] && /sbin/initqueue --settled --unique --onetime /sbin/insmodpost.sh unset _do_insmodpost
insmodpost.sh, which is called in the initqueue/settled hook will just modprobe the kernel modules specified in all rd.driver.post kernel command line parameters. It runs after udev has settled and is only called once (--onetime).
. /lib/dracut-lib.sh for p in $(getargs rd.driver.post=); do modprobe $p done
check() should return with:
To address a file in the current module directory, use the variable "$moddir".
installs multiple binaries and files. If executables are specified without a path, dracut will search the path PATH=/usr/sbin:/sbin:/usr/bin:/bin for the binary. If the option "-o" is given as the first parameter, a missing file does not lead to an error.
inst <src> [<dst>]
installs one file <src> either to the same place in the initramfs or to an optional <dst>. inst with more than two arguments is treated the same as inst_multiple, all arguments are treated as files to install and none as install destinations.
inst_hook <hookdir> <prio> <src>
installs an executable/script <src> in the dracut hook <hookdir> with priority <prio>.
inst_rules <udevrule> [ <udevrule> ...]
installs one or more udev rules. Non-existant udev rules are reported, but do not let dracut fail.
instmods <kernelmodule> [ <kernelmodule> ... ]
instmods should be used only in the installkernel() function.
instmods installs one or more kernel modules in the initramfs. <kernelmodule> can also be a whole subsystem, if prefixed with a "=", like "=drivers/net/team".
instmods will not install the kernel module, if $hostonly is set and the kernel module is not currently needed by any /sys/.../uevent MODALIAS. To install a kernel module regardless of the hostonly mode use the form:
hostonly='' instmods <kernelmodule>