1 <?xml version='1.0' encoding='UTF-8'?>
2 <!-- This document was created with Syntext Serna Free. -->
3 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
5 <title><inlinemediaobject>
7 <imagedata valign="middle" fileref="dracut.png" format="PNG"/>
10 <imagedata valign="middle" fileref="dracut.svg" format="SVG"/>
13 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.svg" encoding="UTF-8" parse="xml"/>
15 </inlinemediaobject>dracut</title>
18 <firstname>Harald</firstname>
19 <surname>Hoyer</surname>
21 <pubdate>2010</pubdate>
22 <edition>Version 1.0</edition>
25 <holder>Harald Hoyer</holder>
29 This work is licensed under the Creative Commons Attribution/Share-Alike License. To view a copy of this license, visit <ulink url="http://creativecommons.org/licenses/by-sa/3.0/">http://creativecommons.org/licenses/by-sa/3.0/</ulink> or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
38 This section is a modified version of <ulink url="http://en.wikipedia.org/wiki/Initrd">http://en.wikipedia.org/wiki/Initrd</ulink>, which is licensed under the Creative Commons Attribution/Share-Alike License.
42 <title>Introduction</title>
44 <title>Definition</title>
45 <para>An <emphasis>initial ramdisk</emphasis> is a temporary file system used in the boot process of the Linux kernel. <emphasis>initrd</emphasis> and <emphasis>initramfs</emphasis> refer to slightly different schemes for loading this file system into memory. Both are commonly used to make preparations before the real root file system can be mounted.</para>
48 <title>Rationale </title>
49 <para>Many Linux distributions ship a single, generic kernel image that is intended to boot as wide a variety of hardware as possible. The device drivers for this generic kernel image are included as loadable modules, as it is not possible to statically compile them all into the one kernel without making it too large to boot from computers with limited memory or from lower-capacity media like floppy disks.
51 <para>This then raises the problem of detecting and loading the modules necessary to mount the root file system at boot time (or, for that matter, deducing where or what the root file system is).
53 <para>To further complicate matters, the root file system may be on a software <acronym>RAID</acronym> volume, <acronym>LVM</acronym>, <acronym>NFS</acronym> (on diskless workstations), or on an encrypted partition. All of these require special preparations to mount.
55 <para>Another complication is kernel support for hibernation, which suspends the computer to disk by dumping an image of the entire system to a swap partition or a regular file, then powering off. On next boot, this image has to be made accessible before it can be loaded back into memory. </para>
56 <para>To avoid having to hardcode handling for so many special cases into the kernel, an initial boot stage with a temporary root file system—now dubbed early user space—is used. This root file system would contain user-space helpers that would do the hardware detection, module loading and device discovery necessary to get the real root file system mounted.
60 <title>Implementation </title>
61 <para>An image of this initial root file system (along with the kernel image) must be stored somewhere accessible by the Linux bootloader or the boot firmware of the computer. This can be: </para>
64 <para>The root file system itself </para>
67 <para>A boot image on an optical disc
71 <para>A small ext2/ext3 or <acronym>FAT</acronym>-formatted partition on a local disk (a <emphasis>boot partition</emphasis>)</para>
74 <para>A <acronym>TFTP</acronym> server (on systems that can boot from Ethernet) </para>
77 <para>The bootloader will load the kernel and initial root file system image into memory and then start the kernel, passing in the memory address of the image.
79 <para>Depending on which algorithms were compiled statically into it, the kernel can currently unpack initrd/initramfs images compressed with gzip, bzip2 and <acronym>LZMA</acronym>. </para>
82 <title>Mount preparations </title>
83 <para>dracut can generate a customized initrams image which contains only whatever is necessary to boot some particular computer, such as <acronym>ATA</acronym>, <acronym>SCSI</acronym> and filesystem kernel modules (host-only mode).</para>
84 <para>dracut can also generate a more generic initramfs image (default mode). </para>
85 <para>dracut's initramfs starts only with the device name of the root file system (or its <acronym>UUID</acronym>) and must discover everything else at boot time. A complex cascade of tasks must be performed to get the root file system mounted: </para>
88 <para>Any hardware drivers that the boot process depends on must be loaded. All kernel modules for common storage devices are packed onto the initramfs and then udev pulls in modules matching the computer's detected hardware. </para>
91 <para>On systems which display a boot rd.splash screen, the video hardware must be initialized and a user-space helper started to paint animations onto the display in lockstep with the boot process. </para>
94 <para>If the root file system is on NFS, dracut does then: <itemizedlist>
96 <para>Bring up the primary network interface. </para>
99 <para>Invoke a DHCP client, with which it can obtain a DHCP lease. </para>
102 <para>Extract the name of the NFS share and the address of the NFS server from the lease. </para>
105 <para>Mount the <acronym>NFS</acronym> share. </para>
107 </itemizedlist></para>
110 <para>If the root file system appears to be on a software <acronym>RAID</acronym> device, there is no way of knowing which devices the <acronym>RAID</acronym> volume spans; the standard <acronym>MD</acronym> utilities must be invoked to scan all available block devices with a raid signature and bring the required ones online. </para>
113 <para>If the root file system appears to be on a logical volume, the <acronym>LVM</acronym> utilities must be invoked to scan for and activate the volume group containing it. </para>
116 <para>If the root file system is on an encrypted block device: <itemizedlist>
118 <para>Invoke a helper script to prompt the user to type in a passphrase and/or insert a hardware token (such as a smart card or a <acronym>USB</acronym> security dongle). </para>
121 <para>Create a decryption target with the device mapper. </para>
123 </itemizedlist></para>
126 <para>dracut uses udev, an event-driven hotplug agent, which invokes helper programs as hardware devices, disk partitions and storage volumes matching certain rules come online. This allows discovery to run in parallel, and to progressively cascade into arbitrary nestings of <acronym>LVM</acronym>, <acronym>RAID</acronym> or encryption to get at the root file system. </para>
127 <para>When the root file system finally becomes visible: <itemizedlist>
129 <para>Any maintenance tasks which cannot run on a mounted root file system are done. </para>
132 <para>The root file system is mounted read-only. </para>
135 <para>Any processes which must continue running (such as the rd.splash screen helper and its command <acronym>FIFO</acronym>) are hoisted into the newly-mounted root file system. </para>
137 </itemizedlist></para>
138 <para>The final root file system cannot simply be mounted over /, since that would make the scripts and tools on the initial root file system inaccessible for any final cleanup tasks. On an initramfs, the initial root file system cannot be rotated away. Instead, it is simply emptied and the final root file system mounted over the top.
143 <title>User Manual</title>
145 <title>Creating an initramfs Image</title>
146 <para>To create a initramfs image, the most simple command is:</para>
147 <screen># dracut</screen>
148 <para>This will generate a general purpose initramfs image, with all possible functionality resulting of the combination of the installed dracut modules and system tools. The image is /boot/initramfs-<replaceable><kernel version></replaceable>.img and contains the kernel modules of the currently active kernel with version <replaceable><kernel version></replaceable>.</para>
149 <para>If the initramfs image already exists, dracut will display an error message, and to overwrite the existing image, you have to use the <option>--force</option> option. </para>
150 <screen># dracut --force</screen>
151 <para>If you want to specify another filename for the resulting image you would issue a command like:</para>
152 <screen># dracut foobar.img</screen>
153 <para>To generate an image for a specific kernel version, the command would be:</para>
154 <screen># dracut foobar.img 2.6.40-1.rc5.f20</screen>
155 <para>A shortcut to generate the image at the default location for a specific kernel version is:</para>
156 <screen># dracut '' 2.6.40-1.rc5.f20</screen>
157 <para>If you want to create lighter, smaller initramfs images, you may want to specify the <option>--host-only</option> or <option>-H</option> option. Using this option, the resulting image will contain only those dracut modules, kernel modules and filesystems, which are needed to boot this specific machine. This has the drawback, that you can't put the disk on another controller or machine, and that you can't switch to another root filesystem, without recreating the initramfs image. The usage of the <option>--host-only</option> option is only for experts and you will have to keep the broken pieces. At least keep a copy of a general purpose image (and corresponding kernel) as a fallback to rescue your system.</para>
159 <title>Inspecting the Contents</title>
160 <para>To see the contents of the image created by dracut, you can use the <command>lsinitrd</command> tool.</para>
161 <screen># lsinitrd /boot/initramfs-$(uname -r).img | less</screen>
162 <para>To display the contents of a file in the initramfs also use the <command>lsinitrd</command> tool:</para>
163 <screen># lsinitrd /boot/initramfs-$(uname -r).img /etc/ld.so.conf
164 include ld.so.conf.d/*.conf</screen>
167 <title>Adding dracut Modules</title>
168 <para>Some dracut modules are turned off by default and have to be activated manually. You can do this by adding the dracut modules to the configuration file <filename>/etc/dracut.conf</filename> or <filename>/etc/dracut.conf.d/myconf.conf</filename>. See the man page <xref linkend="dracutconf5"/>. You can also add dracut modules on the command line by using the <option>-a</option> or <option>--add</option> option:</para>
169 <screen># dracut --add bootchart initramfs-bootchart.img</screen>
170 <para>To see a list of available dracut modules, use the <option>--list-modules</option> option:</para>
171 <screen># dracut --list-modules</screen>
172 <para>or, if you have a dracut version earlier than <literal>008</literal>, issue the command:</para>
173 <screen># for mod in /usr/lib/dracut/modules.d/*; do echo ${mod##*/??}; done</screen>
176 <title>Omitting dracut Modules</title>
177 <para>Sometimes you don't want a dracut module to be included for reasons of speed, size or functionality. To do this, either specify the <envar>omit_dracutmodules</envar> variable in the <filename>dracut.conf</filename> or <filename>/etc/dracut.conf.d/myconf.conf</filename> configuration file (see man page <xref linkend="dracutconf5"/>), or use the <option>-o</option> or <option>--omit</option> option on the command line:</para>
178 <screen># dracut -o "multipath lvm" no-multipath-lvm.img</screen>
181 <title>Adding Kernel Modules</title>
182 <para>If you need a special kernel module in the initramfs, which is not automatically picked up by dracut, you have the use the <option>--add-drivers</option> option on the command line or the drivers vaiable in the <filename>/etc/dracut.conf</filename> or <filename>/etc/dracut.conf.d/myconf.conf</filename> configuration file (see man page <xref linkend="dracutconf5"/>):</para>
183 <screen># dracut --add-drivers mymod initramfs-with-mymod.img</screen>
187 <title>Boot parameters</title>
188 <para>The generated initramfs.img file normally does not contain any system configuration files (except for some special exceptions), so the configuration has to be done on the kernel command line. With this flexibility, you can easily boot from a changed root partition, without the need to recompile the initramfs image. So, you could completly change your root partition (move it inside a md raid with encryption and LVM on top), as long as you specify the correct filesystem <varname>LABEL</varname> or <varname>UUID</varname> on the kernel command line for your root device, dracut will find it and boot from it.</para>
189 <para>The kernel command line usually can be configured in <filename>/boot/grub/grub.conf</filename>, if grub is your bootloader and it also can be edited in the real boot process in the grub menu.</para>
190 <para>The kernel command line can also be provided by the dhcp server with the root-path option. See <xref linkend="NetworkBoot"/>.</para>
191 <para>For a full reference of all kernel command line parameters, see the <xref linkend="dracutconf5"/> or <xref linkend="dracut8"/> man page.</para>
193 <title>Specifying the root Device</title>
194 <para>This is the only option dracut really needs to boot from your root partition. Because your root partition can live in various environments, there are a lot of formats for the <envar>root=</envar> option. The most basic one is <envar>root=<replaceable><path to device node></replaceable></envar>:</para>
195 <screen>root=/dev/sda2</screen>
196 <para>Because device node names can change, dependent on the drive ordering, you are encouraged to use the filesystem identifier (UUID) or filesystem label (LABEL) to specify your root partition:</para>
197 <screen>root=UUID=19e9dda3-5a38-484d-a9b0-fa6b067d0331</screen>
199 <screen>root=LABEL=myrootpartitionlabel</screen>
200 <para>To see all <envar>UUID</envar>s or <envar>LABEL</envar>s on your system, do:</para>
201 <screen># ls -l /dev/disk/by-uuid</screen>
203 <screen># ls -l /dev/disk/by-label</screen>
204 <para>If your root partition is on the network see <xref linkend="NetworkBoot"/>.</para>
207 <title>Keyboard Settings</title>
208 <para>If you have to input passwords for encrypted disk volumes, you might want to set the keyboard layout and specify a display font.</para>
209 <para>A typical german kernel command would contain:</para>
210 <screen>vconsole.font=latarcyrheb-sun16 vconsole.keymap=de-latin1-nodeadkeys locale.LANG=de_DE.UTF-8</screen>
211 <para>Setting these options can override the setting stored on your system, if you use a modern init system, like systemd.</para>
212 <para>For dracut versions prior to version <literal>008</literal> the line would look like:</para>
213 <screen>LANG=de_DE.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de-latin1-nodeadkeys</screen>
216 <title>Blacklisting Kernel Modules</title>
217 <para>Sometimes it is required to prevent the automatic kernel module loading of a specific kernel module. To do this, just add <envar>rd.blacklist=<replaceable><kernel module name></replaceable></envar>, with <replaceable><kernel module name></replaceable> not containing the <filename>.ko</filename> suffix, to the kernel command line. For example:</para>
218 <screen>rd.blacklist=mptsas rd.blacklist=nouveau</screen>
219 <para>The option can be specified multiple times on the kernel command line.</para>
222 <title>Speeding up the Boot Process</title>
223 <para>If you want to speed up the boot process, you can specify as much information for dracut on the kernel command as possible. For example, you can tell dracut, that you root partition is not on a <acronym>LVM</acronym> volume or not on a raid partition, or that it lives inside a specific crypto <acronym>LUKS</acronym> encrypted volume. By default, dracut searches everywhere. A typical dracut kernel command line for a plain primary or logical partition would contain:</para>
224 <screen>rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0</screen>
225 <para>on systems with dracut version prior to <literal>008</literal> the line would look like:</para>
226 <screen>rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM</screen>
227 <para>This turns off every automatic assembly of <acronym>LVM</acronym>, <acronym>MD</acronym> raids, <acronym>DM</acronym> raids and crypto <acronym>LUKS</acronym>.</para>
228 <para>Of course, you could also omit the dracut modules in the initramfs creation process, but then you would lose the posibility to turn it on on demand.</para>
230 <section id="Injecting">
231 <title>Injecting custom Files</title>
232 <para>To add your own files to the initramfs image, you have several possibilities.</para>
233 <para>The <option>--include</option> option let you specify a source path and a target path. For example</para>
234 <screen># dracut --include cmdline-preset /etc/cmdline initramfs-cmdline-pre.img</screen>
235 <para>will create an initramfs image, where the file cmdline-preset will be copied inside the initramfs to <filename>/etc/cmdline</filename>. <option>--include</option> can only be specified once.</para>
236 <screen># mkdir rd.live.overlay
237 # mkdir rd.live.overlay/etc
238 # mkdir rd.live.overlay/etc/conf.d
239 # echo "ip=auto" >> rd.live.overlay/etc/cmdline
240 # echo export TESTVAR=testtest >> rd.live.overlay/etc/conf.d/testvar.conf
241 # echo export TESTVAR=testtest >> rd.live.overlay/etc/conf.d/testvar.conf
242 # tree rd.live.overlay/
248 # dracut --include rd.live.overlay / initramfs-rd.live.overlay.img</screen>
249 <para>This will put the contents of the rd.live.overlay directory into the root of the initramfs image.</para>
250 <para>The <option>--install</option> option let you specify several files, which will get installed in the initramfs image at the same location, as they are present on initramfs creation time.</para>
251 <screen># dracut --install 'strace fsck.ext3 ssh' initramfs-dbg.img</screen>
252 <para>This will create an initramfs with the <command>strace</command>, <command>fsck.ext3</command> and <command>ssh</command> executables, together with the libraries needed to start those. The <option>--install</option> option can be specified multiple times.</para>
255 <section id="NetworkBoot">
256 <title>Network Boot</title>
257 <para>If your root partition is on a network drive, you have to have the network dracut modules installed to create a network aware initramfs image.</para>
258 <para>On a Red Hat Enterprise Linux or Fedora system, this means, you have to install the <filename>dracut-network</filename> rpm package:</para>
259 <screen># yum install dracut-network</screen>
260 <para>The resulting initramfs image can be served by a boot manager residing on your local hard drive or it can be served by a <acronym>PXE</acronym>/<acronym>TFTP</acronym> server.</para>
261 <para>How to setup your <acronym>PXE</acronym>/<acronym>TFTP</acronym> server can be found in the <ulink url="http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Storage_Administration_Guide/">Red Hat Enterprise Linux Storage Administration Guide</ulink>.</para>
262 <para>If you specify <envar>rd.ip=auto</envar> on the kernel command line, then dracut asks a dhcp server about the ip adress for the machine. The dhcp server can also serve an additional root-path, which will set the root device for dracut. With this mechanism, you have static configuration on your client machine and a centralized boot configuration on your <acronym>TFTP</acronym>/<acronym>DHCP</acronym> server. If you can't pass a kernel command line, then you can inject <filename>/etc/cmdline</filename>, with a method described in <xref linkend="Injecting"/>.
265 <title>Reducing the Image Size</title>
266 <para>To reduce the size of the initramfs, you should create it with by ommitting all dracut modules, which you know, you don't need to boot the machine.</para>
267 <para>You can also specify the exact dracut and kernel modules to produce a very tiny initramfs image.</para>
268 <para>For example for a <acronym>NFS</acronym> image, you would do:</para>
269 <screen># dracut -m "nfs network base" initramfs-nfs-only.img</screen>
270 <para>Then you would boot from this image with your target machine and reduce the size once more by creating it on the target machine with the <option>--host-only</option> option:</para>
271 <screen># dracut -m "nfs network base" --host-only initramfs-nfs-host-only.img</screen>
272 <para>This will reduce the size of the initramfs image significantly.</para>
275 <title>NFS Root Device</title>
279 <title>iSCSI Root Device</title>
284 <title>FCoE Root Device</title>
290 <title>Troubleshooting</title>
291 <para>If the boot process does not succeed, you have several options to debug the situation. Some of the basic operations are covered here. For more information you should also visit: <ulink url="http://fedoraproject.org/wiki/How_to_debug_Dracut_problems">http://fedoraproject.org/wiki/How_to_debug_Dracut_problems</ulink></para>
292 <section id="identifying-your-problem-area">
293 <title>Identifying your problem area</title>
296 <para>Remove ''rhgb'' and ''quiet'' from the kernel command line
300 <para>Add ''rd.shell'' to the kernel command line. This will present a shell should dracut be unable to locate your root device
304 <para>Add ''rd.shell rd.debug log_buf_len=1M'' to the kernel command line so that dracut shell commands are printed as they are executed
308 <para>With dracut >= 002-11, you can inspect the rd.debug output with:
310 <screen># less /run/initramfs/init.log
311 # dmesg | less</screen>
315 <section id="information-to-include-in-your-report">
316 <title id="information-to-include-in-your-report-title">Information to include in your report</title>
317 <section id="all-bug-reports">
318 <title id="all-bug-reports-title">All bug reports</title>
319 <para>In all cases, the following should be mentioned and attached to your bug report:
323 <para>The exact kernel command-line used. Typically from the bootloader configuration file (e.g. <filename>/etc/grub.conf</filename>) or from <filename>/proc/cmdline</filename>.</para>
326 <para>A copy of your disk partition information from <filename>/etc/fstab</filename>, which might be obtained booting an old working initramfs or a rescue medium.</para>
329 <para>A device listing from device-mapper. This can be obtained by running the command <screen># dmsetup ls --tree</screen></para>
332 <para>A list of block device attributes including vol_id compatible mode. This can be obtained by running the commands: <screen># blkid -p
333 # blkid -p -o udev</screen></para>
336 <para>Turn on dracut debugging (see <filename>the 'debugging dracut' section</filename>), and attach all relevant information from the boot log. This can be obtained by running the command <screen># dmesg|grep dracut</screen></para>
339 <para>If you use a dracut configuration file, please include <filename>/etc/dracut.conf</filename>
340 and all files in <filename>/etc/dracut.conf.d/*.conf</filename></para>
344 <section id="logical-volume-management-related-problems">
345 <title id="logical-volume-management-related-problems-title">Logical Volume Management related problems</title>
346 <para>As well as the information from <xref linkend="all-bug-reports"/> include the following information:
350 <para>Include physical volume information by running the command: <screen># lvm pvdisplay</screen></para>
353 <para>Include volume group information by running the command: <screen># lvm vgdisplay</screen></para>
356 <para>Include logical volume information by running the command: <screen># lvm lvdisplay</screen></para>
360 <section id="software-raid-related-problems">
361 <title id="software-raid-related-problems-title">Software RAID related problems</title>
362 <para>As well as the information from <xref linkend="all-bug-reports"/>, include the following information:
366 <para>If using software RAID disk partitions, please include the output of <screen># cat /proc/mdstat</screen></para>
370 <section id="network-root-device-related-problems">
371 <title id="network-root-device-related-problems-title">Network root device related problems</title>
372 <para>This section details information to include when experiencing problems on a system whose root device is located on a network attached volume (e.g. iSCSI, NFS or NBD). As well as the information from <xref linkend="all-bug-reports"/>, include the following information:
376 <para>Please include the output of <screen># /sbin/ifup <replaceable><interfacename></replaceable>
377 # ip addr show</screen></para>
382 <section id="debugging-dracut">
383 <title id="debugging-dracut-title">Debugging dracut</title>
384 <section id="configure-a-serial-console">
385 <title id="configure-a-serial-console-title">Configure a serial console</title>
386 <para>Successfully debugging dracut will require some form of console logging during the system boot. This section documents configuring a serial console connection to record boot messages.
390 <para>First, enable serial console output for both the kernel and the bootloader.
394 <para>Open the file <filename>/etc/grub.conf</filename> for editing. Below the line ''timeout=5'', add the following:
395 <screen>serial --unit=0 --speed=9600
396 terminal --timeout=5 serial console</screen></para>
399 <para>Also in <filename>/etc/grub.conf</filename>, add the following boot arguemnts to the ''kernel'' line:
400 <screen>console=tty0 console=ttyS0,9600</screen></para>
403 <para>When finished, the <filename>/etc/grub.conf</filename> file should look similar to the example below.
406 serial --unit=0 --speed=9600
407 terminal --timeout=5 serial console
408 title Fedora (2.6.29.5-191.fc11.x86_64)
410 kernel /vmlinuz-2.6.29.5-191.fc11.x86_64 ro root=/dev/mapper/vg_uc1-lv_root console=tty0 console=ttyS0,9600
411 initrd /dracut-2.6.29.5-191.fc11.x86_64.img</screen></para>
414 <para>More detailed information on how to configure the kernel for console output can be found at <ulink url="http://www.faqs.org/docs/Linux-HOWTO/Remote-Serial-Console-HOWTO.html#CONFIGURE-KERNEL">http://www.faqs.org/docs/Linux-HOWTO/Remote-Serial-Console-HOWTO.html#CONFIGURE-KERNEL</ulink>.
419 <title>Redirecting non-interactive output</title>
420 <para>You can redirect all non-interactive output to <filename>/dev/kmsg</filename> and the kernel will put it out on the console when it reaches the kernel buffer by doing<screen># exec >/dev/kmsg 2>&1 </dev/console</screen></para>
423 <section id="using-the-dracut-shell">
424 <title id="using-the-dracut-shell-title">Using the dracut shell</title>
425 <para>Dracut offers a shell for interactive debugging in the event dracut fails to locate your root filesystem. To enable the shell:
428 <para>Add the boot parameter ''rd.shell'' to your bootloader configuration file (e.g. <filename>/etc/grub.conf</filename>)</para>
431 <para>Remove the boot arguments ''rhgb'' and ''quiet''
434 A sample <filename>/etc/grub.conf</filename> bootloader configuration file is listed below.
436 <para><screen>default=0
438 serial --unit=0 --speed=9600
439 terminal --timeout=5 serial console
440 title Fedora (2.6.29.5-191.fc11.x86_64)
442 kernel /vmlinuz-2.6.29.5-191.fc11.x86_64 ro root=/dev/mapper/vg_uc1-lv_root console=tty0 rd.shell
443 initrd /dracut-2.6.29.5-191.fc11.x86_64.img</screen></para>
446 <para>If system boot fails, you will be dropped into a shell as seen in the example below.
447 <screen>No root device found
448 Dropping to debug shell.
450 sh: can't access tty; job control turned off
455 <para>Use this shell prompt to gather the information requested above (see <xref linkend="all-bug-reports"/>).
458 </orderedlist></para>
460 <section id="accessing-the-root-volume-from-the-dracut-shell">
461 <title id="accessing-the-root-volume-from-the-dracut-shell-title">Accessing the root volume from the dracut shell</title>
462 <para>From the dracut debug shell, you can manually perform the task of locating and preparing your root volume for boot. The required steps will depend on how your root volume is configured. Common scenarios include:
466 <para>A block device (e.g. <filename>/dev/sda7</filename>)
470 <para>A LVM logical volume (e.g. <filename>/dev/VolGroup00/LogVol00</filename>)
474 <para>An encrypted device (e.g. <filename>/dev/mapper/luks-4d5972ea-901c-4584-bd75-1da802417d83</filename>)
478 <para>A network attached device (e.g. netroot=iscsi:@192.168.0.4::3260::iqn.2009-02.org.fedoraproject:for.all)
482 <para>The exact method for locating and preparing will vary. However, to continue with a successful boot, the objective is to locate your root volume and create a symlink <filename>/dev/root</filename> which points to the file system. For example, the following example demonstrates accessing and booting a root volume that is an encrypted LVM Logical volume. </para>
485 <para>Inspect your partitions using <command>parted</command><screen># parted /dev/sda -s p
486 Model: ATA HTS541060G9AT00 (scsi)
487 Disk /dev/sda: 60.0GB
488 Sector size (logical/physical): 512B/512B
489 Partition Table: msdos
490 Number Start End Size Type File system Flags
491 1 32.3kB 10.8GB 107MB primary ext4 boot
492 2 10.8GB 55.6GB 44.7GB logical lvm</screen></para>
495 <para>You recall that your root volume was a LVM logical volume. Scan and activate any logical volumes.
497 # lvm vgchange -ay</screen></para>
500 <para>You should see any logical volumes now using the command <command>blkid</command>:
502 /dev/sda1: UUID="3de247f3-5de4-4a44-afc5-1fe179750cf7" TYPE="ext4"
503 /dev/sda2: UUID="Ek4dQw-cOtq-5MJu-OGRF-xz5k-O2l8-wdDj0I" TYPE="LVM2_member"
504 /dev/mapper/linux-root: UUID="def0269e-424b-4752-acf3-1077bf96ad2c" TYPE="crypto_LUKS"
505 /dev/mapper/linux-home: UUID="c69127c1-f153-4ea2-b58e-4cbfa9257c5e" TYPE="ext3"
506 /dev/mapper/linux-swap: UUID="47b4d329-975c-4c08-b218-f9c9bf3635f1" TYPE="swap"
510 <para>From the output above, you recall that your root volume exists on an encrypted block device. Following the guidance disk encryption guidance from the Installation Guide, you unlock your encrypted root volume.
511 <screen># UUID=$(cryptsetup luksUUID /dev/mapper/linux-root)
512 # cryptsetup luksOpen /dev/mapper/linux-root luks-$UUID
513 Enter passphrase for /dev/mapper/linux-root:
514 Key slot 0 unlocked. </screen></para>
517 <para>Next, make a symbolic link to the unlocked root volume
518 <screen># ln -s /dev/mapper/luks-$UUID /dev/root</screen></para>
521 <para>With the root volume available, you may continue booting the system by exiting the dracut shell
522 <screen># exit</screen></para>
526 <section id="additional-dracut-boot-parameters">
527 <title id="additional-dracut-boot-parameters-title">Additional dracut boot parameters</title>
528 <para>For more debugging options, see <xref linkend="dracut-kernel-debug"/> in the man page <xref linkend="dracutkernel7"/>.</para>
534 <title>Developer Manual</title>
536 <title>dracut Components</title>
537 <para>dracut uses a modular system to build and extend the initramfs image. All modules are located in <filename>/usr/lib/dracut/modules.d</filename> or in <filename><replaceable><git-src></replaceable>/modules.d</filename>. The most basic dracut module is <filename>99base</filename>. In <filename>99base</filename> the initial shell script <command>init</command> is defined, which gets run by the kernel after initramfs loading. Although you can replace <command>init</command> with your own version of <filename>99base</filename>, this is not encouraged. Instead you should use, if possible, the hooks of dracut. All hooks, and the point of time in which they are executed, are described in <xref linkend="stages"/>.</para>
538 <para>The main script, which creates the initramfs is <command>dracut</command> itsself. It parses all arguments and sets up the directory, in which everything is installed. It then executes all <command>check</command>, <command>install</command>, <command>installkernel</command> 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 <command>check</command>, <command>install</command> and <command>installkernel</command> are found in in the file <filename>dracut-functions</filename>. These shell functions are available to all module installer (<command>install</command>, <command>installkernel</command>) scripts, without the need to source <filename>dracut-functions</filename>.</para>
539 <para>A module can check the preconditions for <command>install</command> and <command>installkernel</command> with the <command>check</command> script. Also dependencies can be expressed with <command>check</command>. If a module passed <command>check</command>, <command>install</command> and <command>installkernel</command> 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 <command>installkernel</command>. All other files found in a module directory are module specific and mostly are hook scripts and udev rules.</para>
541 <section id="stages">
542 <title>Boot Process Stages</title>
543 <para>The <command>init</command> script in <filename>99base</filename> is the main script, which prepares the root file system for usage, runs udev, mounts the real root device, kills the remaining processes, and switches to the real root device for further booting. dracut modules can insert custom script at various points, to control the boot process. These hooks are plain directories containing shell scripts ending with ".sh", which are sourced by <command>init</command>.
544 Common used functions are in <filename>dracut-lib.sh</filename>, which can be sourced by any script. </para>
546 <title>Basic Setup</title>
547 <para>The first thing <command>init</command> does, is to mount <filename>/proc</filename> and <filename>/sys</filename> and manually create the basic device nodes and symbolic links in <filename>/dev</filename> needed to execute basic commands. Then logging is setup according to kernel command line arguments. <filename>/dev/pts</filename> and <filename>/dev/shm</filename> are mounted and the first hook is sourced.</para>
550 <title>Hook: cmdline</title>
552 <function>cmdline</function>
553 </literal> hook is a place to insert scripts to parse the kernel command line and prepare the later actions, like setting up udev rules and configuration files.</para>
554 <para>In this hook the most important environment variable is defined: <envar>root</envar>. The second one is <envar>rootok</envar>, which indicates, that a module claimed to be able to parse the <envar>root</envar> defined. So for example, <envar>root=</envar><replaceable>iscsi:....</replaceable> will be claimed by the <function>iscsi</function> dracut module, which then sets <envar>rootok</envar>.</para>
557 <title>Hook: pre-udev</title>
558 <para>This hook is executed right after the <function>cmdline</function> hook and a check if <envar>root</envar> and <envar>rootok</envar> were set. Here modules can take action with the final <envar>root</envar>, and before <command>udev</command> has been run.</para>
561 <title>Start Udev</title>
562 <para>Now <command>udev</command> is started and the logging for <command>udev</command> is setup.</para>
565 <title>Hook: pre-trigger</title>
566 <para>In this hook, you can set udev environment variables with <code>udevadm control --property=<envar>KEY</envar>=<replaceable>value</replaceable></code> or control the further execution of <command>udev</command> with <command>udevadm</command>.</para>
569 <title>Trigger Udev</title>
570 <para><command>udev</command> is triggered by calling <command>udevadm trigger</command>, which sends <constant>add</constant> events for all devices and subsystems.
574 <title>Main Loop</title>
575 <para>Now the main loop of <command>99base/init</command> begins. Here we loop until <command>udev</command> has settled and all scripts in <filename>initqueue/finished</filename> returned true. In this loop there are three hooks, where scripts can be inserted by calling <command>/sbin/initqueue</command>.
578 <title>Initqueue</title>
579 <para>This hook gets executed every time a script is inserted here, regardless of the <command>udev</command> state.</para>
582 <title>Initqueue settled</title>
583 <para>This hooks gets executed every time <command>udev</command> has settled.</para>
586 <title>Initqueue timeout</title>
587 <para>This hooks gets executed, when the main loop counter becomes half of the rd.retry counter.</para>
590 <title>Initqueue finished</title>
591 <para>This hook is called after <command>udev</command> has settled and if all scripts herein return <errorcode>0</errorcode> the main loop will be ended.</para>
595 <title>Hook: pre-mount</title>
596 <para>Before the root device is mounted all scripts in the hook pre-mount are executed. In some cases (e.g. <acronym>NFS</acronym>) the real root device is already mounted, though.</para>
599 <title>Hook: mount</title>
600 <para>This hook is mainly to mount the real root device.</para>
603 <title>Hook: pre-pivot</title>
604 <para>This hook is the last hook and is called before init finally switches root to the real root device. This is a good place to clean up and kill processes not needed anymore.</para>
607 <title>Cleanup and switch_root</title>
608 <para>Init kills all <command>udev</command> processes, cleans up the environment, sets up the arguments for the real <command>init</command> process and finally calls <command>switch_root</command>. <command>switch_root</command> removes the whole filesystem hierarchy of the initramfs, chroot()s to the real root device and calls <command>/sbin/init</command> with the specified arguments.</para>
609 <para>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.</para>
613 <title>Network Infrastructure</title>
618 <title>Writing a Module</title>
619 <para>A simple example module is <filename>96insmodpost</filename>, which modprobes a kernel module after udev has settled and the basic device drivers have been loaded.</para>
620 <para>All module installation information is in the file module-setup.sh.</para>
621 <para>First we create a <function>check()</function> function, which just exits with <errorcode>0</errorcode> indicating that this module should be included by default.</para>
622 <para><function>check()</function>:</para>
623 <programlisting>return 0</programlisting>
624 <para>The we create the <function>install()</function> function, which installs a cmdline hook with priority number 20 called <filename>parse-insmodpost.sh</filename>. It also installs the <filename>insmodpost.sh</filename> script in <filename>/sbin</filename>.</para>
625 <para><function>install()</function>:</para>
626 <programlisting>inst_hook cmdline 20 "$moddir/parse-insmodpost.sh"
627 inst_simple "$moddir/insmodpost.sh" /sbin/insmodpost.sh</programlisting>
628 <para>The <filename>pase-instmodpost.sh</filename> parses the kernel command line for a argument <envar>rd.driver.post</envar>, blacklists the module from being autoloaded and installs the hook <filename>insmodpost.sh</filename> in the <filename>initqueue/settled</filename>.</para>
629 <para><filename>parse-insmodpost.sh</filename>:</para>
630 <programlisting>for p in $(getargs rd.driver.post=); do
631 echo "blacklist $p" >> /etc/modprobe.d/initramfsblacklist.conf
635 [ -n "$_do_insmodpost" ] && /sbin/initqueue --settled --unique --onetime /sbin/insmodpost.sh
638 <para><filename>insmodpost.sh</filename>, which is called in the <filename>initqueue/settled</filename> hook will just modprobe the kernel modules specified in all <envar>rd.driver.post</envar> kernel command line parameters. It runs after <command>udev</command> has settled and is only called once (<parameter>--onetime</parameter>).</para>
639 <para><filename>insmodpost.sh</filename>:</para>
640 <programlisting>. /lib/dracut-lib.sh
642 for p in $(getargs rd.driver.post=); do
647 <title>check()</title>
649 <function>check()</function>
650 </filename> is called by dracut to evaluate the inclusion of a dracut module in the initramfs.</para>
653 <term> $hostonly</term>
655 <para>If the $hostonly variable is set, then the module check() function should be in "hostonly" mode, which means, that the check() should only return 0, if the module is really needed to boot this specific host.</para>
659 <para><function>check()</function> should return with:</para>
664 <para>Include the dracut module in the initramfs.</para>
670 <para>Do not include the dracut module. The requirements are not fullfilled (missing tools, etc.)</para>
676 <para>Only include the dracut module, if another module requires it or if explicitly specified in the config file or on the argument list.</para>
682 <title>depends()</title>
683 <para>The function <function>depends()</function> should <function>echo</function> all other dracut module names the module depends on.</para>
686 <title>install()</title>
687 <para>dracut_install</para>
689 <para>inst_hook</para>
690 <para>inst_rules</para>
694 <title>installkernel()</title>
695 <para>instmods</para>
698 <title>Creation Functions</title>
703 <title>Initramfs Functions</title>
708 <title>Network Modules</title>
715 <title>Man Pages</title>
716 <section id="dracut.man">
717 <title>dracut</title>
718 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.8.xml" encoding="UTF-8" parse="xml"/>
720 <section id="dracut.conf">
721 <title>dracut.conf</title>
722 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.conf.5.xml" encoding="UTF-8" parse="xml"/>
724 <section id="dracut.cmdline">
725 <title>dracut.cmdline</title>
726 <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.cmdline.7.xml" encoding="UTF-8" parse="xml"/>