1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
<?xml version='1.0' encoding='UTF-8'?>
<!-- This document was created with Syntext Serna Free. --><!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" []>
<book>
<title>dracut</title>
<bookinfo>
<author>
<firstname>Harald</firstname>
<surname>Hoyer</surname>
</author>
<pubdate>2010</pubdate>
<edition>Version 1.0</edition>
<copyright>
<year>2010</year>
<holder>Harald Hoyer</holder>
</copyright>
<legalnotice>
<para>
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.
</para>
</legalnotice>
</bookinfo>
<toc/>
<chapter>
<chapterinfo>
<legalnotice>
<para>
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.
</para>
</legalnotice>
</chapterinfo>
<title>Introduction</title>
<section>
<title>Definition</title>
<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>
</section>
<section>
<title>Rationale </title>
<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.
</para>
<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).
</para>
<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.
</para>
<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>
<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.
</para>
</section>
<section>
<title>Implementation </title>
<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>
<itemizedlist>
<listitem>
<para>The root file system itself </para>
</listitem>
<listitem>
<para>A boot image on an optical disc
</para>
</listitem>
<listitem>
<para>A small ext2/ext3 or <acronym>FAT</acronym>-formatted partition on a local disk (a <emphasis>boot partition</emphasis>)</para>
</listitem>
<listitem>
<para>A <acronym>TFTP</acronym> server (on systems that can boot from Ethernet) </para>
</listitem>
</itemizedlist>
<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.
</para>
<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>
</section>
<section>
<title>Mount preparations </title>
<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>
<para>dracut can also generate a more generic initramfs image (default mode). </para>
<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>
<itemizedlist>
<listitem>
<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>
</listitem>
<listitem>
<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>
</listitem>
<listitem>
<para>If the root file system is on NFS, dracut does then: <itemizedlist>
<listitem>
<para>Bring up the primary network interface. </para>
</listitem>
<listitem>
<para>Invoke a DHCP client, with which it can obtain a DHCP lease. </para>
</listitem>
<listitem>
<para>Extract the name of the NFS share and the address of the NFS server from the lease. </para>
</listitem>
<listitem>
<para>Mount the <acronym>NFS</acronym> share. </para>
</listitem>
</itemizedlist></para>
</listitem>
<listitem>
<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>
</listitem>
<listitem>
<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>
</listitem>
<listitem>
<para>If the root file system is on an encrypted block device: <itemizedlist>
<listitem>
<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>
</listitem>
<listitem>
<para>Create a decryption target with the device mapper. </para>
</listitem>
</itemizedlist></para>
</listitem>
</itemizedlist>
<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>
<para>When the root file system finally becomes visible: <itemizedlist>
<listitem>
<para>Any maintenance tasks which cannot run on a mounted root file system are done. </para>
</listitem>
<listitem>
<para>The root file system is mounted read-only. </para>
</listitem>
<listitem>
<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>
</listitem>
</itemizedlist></para>
<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.
</para>
</section>
</chapter>
<chapter>
<title>User Manual</title>
<section>
<title>Creating an initramfs Image</title>
<para>To create a initramfs image, the most simple command is:</para>
<screen># dracut</screen>
<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>
<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>
<screen># dracut --force</screen>
<para>If you want to specify another filename for the resulting image you would issue a command like:</para>
<screen># dracut foobar.img</screen>
<para>To generate an image for a specific kernel version, the command would be:</para>
<screen># dracut foobar.img 2.6.40-1.rc5.f20</screen>
<para>A shortcut to generate the image at the default location for a specific kernel version is:</para>
<screen># dracut '' 2.6.40-1.rc5.f20</screen>
<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>
<section>
<title>Inspecting the Contents</title>
<para>To see the contents of the image created by dracut, you can use the <command>lsinitrd</command> tool.</para>
<screen># lsinitrd /boot/initramfs-$(uname -r).img | less</screen>
<para>To display the contents of a file in the initramfs also use the <command>lsinitrd</command> tool:</para>
<screen># lsinitrd /boot/initramfs-$(uname -r).img /etc/ld.so.conf
include ld.so.conf.d/*.conf</screen>
</section>
<section>
<title>Adding dracut Modules</title>
<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>
<screen># dracut --add bootchart initramfs-bootchart.img</screen>
<para>To see a list of available dracut modules, use the <option>--list-modules</option> option:</para>
<screen># dracut --list-modules</screen>
<para>or, if you have a dracut version earlier than <literal>008</literal>, issue the command:</para>
<screen># for mod in /usr/share/dracut/modules.d/*; do echo ${mod##*/??}; done</screen>
</section>
<section>
<title>Omitting dracut Modules</title>
<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>add_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>
<screen># dracut -o "multipath lvm" no-multipath-lvm.img</screen>
</section>
<section>
<title>Adding Kernel Modules</title>
<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>
<screen># dracut --add-drivers mymod initramfs-with-mymod.img</screen>
</section>
</section>
<section>
<title>Boot parameters</title>
<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>
<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>
<para>The kernel command line can also be provided by the dhcp server with the root-path option. See <xref linkend="NetworkBoot"/>.</para>
<para>For a full reference of all kernel command line parameters, see the <xref linkend="dracutconf5"/> or <xref linkend="dracut8"/> man page.</para>
<section>
<title>Specifying the root Device</title>
<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>
<screen>root=/dev/sda2</screen>
<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>
<screen>root=UUID=19e9dda3-5a38-484d-a9b0-fa6b067d0331</screen>
<para>or</para>
<screen>root=LABEL=myrootpartitionlabel</screen>
<para>To see all <envar>UUID</envar>s or <envar>LABEL</envar>s on your system, do:</para>
<screen># ls -l /dev/disk/by-uuid</screen>
<para>or</para>
<screen># ls -l /dev/disk/by-label</screen>
<para>If your root partition is on the network see <xref linkend="NetworkBoot"/>.</para>
</section>
<section>
<title>Keyboard Settings</title>
<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>
<para>A typical german kernel command would contain:</para>
<screen>vconsole.font=latarcyrheb-sun16 vconsole.keymap=de-latin1-nodeadkeys locale.LANG=de_DE.UTF-8</screen>
<para>Setting these options can override the setting stored on your system, if you use a modern init system, like systemd.</para>
<para>For dracut versions prior to version <literal>008</literal> the line would look like:</para>
<screen>LANG=de_DE.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de-latin1-nodeadkeys</screen>
</section>
<section>
<title>Blacklisting Kernel Modules</title>
<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>
<screen>rd.blacklist=mptsas rd.blacklist=nouveau</screen>
<para>The option can be specified multiple times on the kernel command line.</para>
</section>
<section>
<title>Speeding up the Boot Process</title>
<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>
<screen>rd.luks=0 rd.lvm=0 rd.md=0 rd.dm=0</screen>
<para>on systems with dracut version prior to <literal>008</literal> the line would look like:</para>
<screen>rd_NO_LUKS rd_NO_LVM rd_NO_MD rd_NO_DM</screen>
<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>
<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>
</section>
<section id="Injecting">
<title>Injecting custom Files</title>
<para>To add your own files to the initramfs image, you have several possibilities.</para>
<para>The <option>--include</option> option let you specify a source path and a target path. For example</para>
<screen># dracut --include cmdline-preset /etc/cmdline initramfs-cmdline-pre.img</screen>
<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>
<screen># mkdir rd.live.overlay
# mkdir rd.live.overlay/etc
# mkdir rd.live.overlay/etc/conf.d
# echo "ip=auto" >> rd.live.overlay/etc/cmdline
# echo export TESTVAR=testtest >> rd.live.overlay/etc/conf.d/testvar.conf
# echo export TESTVAR=testtest >> rd.live.overlay/etc/conf.d/testvar.conf
# tree rd.live.overlay/
rd.live.overlay/
└── etc
├── cmdline
└── conf.d
└── testvar.conf
# dracut --include rd.live.overlay / initramfs-rd.live.overlay.img</screen>
<para>This will put the contents of the rd.live.overlay directory into the root of the initramfs image.</para>
<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>
<screen># dracut --install 'strace fsck.ext3 ssh' initramfs-dbg.img</screen>
<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>
</section>
</section>
<section id="NetworkBoot">
<title>Network Boot</title>
<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>
<para>On a Red Hat Enterprise Linux or Fedora system, this means, you have to install the <filename>dracut-network</filename> rpm package:</para>
<screen># yum install dracut-network</screen>
<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>
<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>
<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"/>.
</para>
<section>
<title>Reducing the Image Size</title>
<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>
<para>You can also specify the exact dracut and kernel modules to produce a very tiny initramfs image.</para>
<para>For example for a <acronym>NFS</acronym> image, you would do:</para>
<screen># dracut -m "nfs network base" initramfs-nfs-only.img</screen>
<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>
<screen># dracut -m "nfs network base" --host-only initramfs-nfs-host-only.img</screen>
<para>This will reduce the size of the initramfs image significantly.</para>
</section>
<section>
<title>NFS Root Device</title>
<para/>
</section>
<section>
<title>iSCSI Root Device</title>
<para>
</para>
</section>
<section>
<title>FCoE Root Device</title>
<para>
</para>
</section>
</section>
<section>
<title>Troubleshooting</title>
<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>
<section id="identifying-your-problem-area">
<title>Identifying your problem area</title>
<orderedlist>
<listitem>
<para>Remove ''rhgb'' and ''quiet'' from the kernel command line
</para>
</listitem>
<listitem>
<para>Add ''rd.shell'' to the kernel command line. This will present a shell should dracut be unable to locate your root device
</para>
</listitem>
<listitem>
<para>Add ''rd.shell rd.debug'' to the kernel command line so that dracut shell commands are printed as they are executed
</para>
</listitem>
<listitem>
<para>With dracut >= 002-11, you can inspect the rd.debug output with:
</para>
<screen># less /init.log
# dmesg | less</screen>
</listitem>
</orderedlist>
</section>
<section id="information-to-include-in-your-report">
<title id="information-to-include-in-your-report-title">Information to include in your report</title>
<section id="all-bug-reports">
<title id="all-bug-reports-title">All bug reports</title>
<para>In all cases, the following should be mentioned and attached to your bug report:
</para>
<itemizedlist>
<listitem>
<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>
</listitem>
<listitem>
<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>
</listitem>
<listitem>
<para>A device listing from device-mapper. This can be obtained by running the command <screen># dmsetup ls --tree</screen></para>
</listitem>
<listitem>
<para>A list of block device attributes including vol_id compatible mode. This can be obtained by running the commands: <screen># blkid -p
# blkid -p -o udev</screen></para>
</listitem>
<listitem>
<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>
</listitem>
<listitem>
<para>If you use a dracut configuration file, please include <filename>/etc/dracut.conf</filename>
and all files in <filename>/etc/dracut.conf.d/*.conf</filename></para>
</listitem>
</itemizedlist>
</section>
<section id="logical-volume-management-related-problems">
<title id="logical-volume-management-related-problems-title">Logical Volume Management related problems</title>
<para>As well as the information from <xref linkend="all-bug-reports"/> include the following information:
</para>
<itemizedlist>
<listitem>
<para>Include physical volume information by running the command: <screen># lvm pvdisplay</screen></para>
</listitem>
<listitem>
<para>Include volume group information by running the command: <screen># lvm vgdisplay</screen></para>
</listitem>
<listitem>
<para>Include logical volume information by running the command: <screen># lvm lvdisplay</screen></para>
</listitem>
</itemizedlist>
</section>
<section id="software-raid-related-problems">
<title id="software-raid-related-problems-title">Software RAID related problems</title>
<para>As well as the information from <xref linkend="all-bug-reports"/>, include the following information:
</para>
<itemizedlist>
<listitem>
<para>If using software RAID disk partitions, please include the output of <screen># cat /proc/mdstat</screen></para>
</listitem>
</itemizedlist>
</section>
<section id="network-root-device-related-problems">
<title id="network-root-device-related-problems-title">Network root device related problems</title>
<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:
</para>
<itemizedlist>
<listitem>
<para>Please include the output of <screen># /sbin/ifup <replaceable><interfacename></replaceable>
# ip addr show</screen></para>
</listitem>
</itemizedlist>
</section>
</section>
<section id="debugging-dracut">
<title id="debugging-dracut-title">Debugging dracut</title>
<section id="configure-a-serial-console">
<title id="configure-a-serial-console-title">Configure a serial console</title>
<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.
</para>
<orderedlist>
<listitem>
<para>First, enable serial console output for both the kernel and the bootloader.
</para>
</listitem>
<listitem>
<para>Open the file <filename>/etc/grub.conf</filename> for editing. Below the line ''timeout=5'', add the following:
<screen>serial --unit=0 --speed=9600
terminal --timeout=5 serial console</screen></para>
</listitem>
<listitem>
<para>Also in <filename>/etc/grub.conf</filename>, add the following boot arguemnts to the ''kernel'' line:
<screen>console=tty0 console=ttyS0,9600</screen></para>
</listitem>
<listitem>
<para>When finished, the <filename>/etc/grub.conf</filename> file should look similar to the example below.
<screen>default=0
timeout=5
serial --unit=0 --speed=9600
terminal --timeout=5 serial console
title Fedora (2.6.29.5-191.fc11.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.29.5-191.fc11.x86_64 ro root=/dev/mapper/vg_uc1-lv_root console=tty0 console=ttyS0,9600
initrd /dracut-2.6.29.5-191.fc11.x86_64.img</screen></para>
</listitem>
<listitem>
<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>.
</para>
</listitem>
</orderedlist>
<note>
<title>Redirecting non-interactive output</title>
<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>
</note>
</section>
<section id="using-the-dracut-shell">
<title id="using-the-dracut-shell-title">Using the dracut shell</title>
<para>Dracut offers a shell for interactive debugging in the event dracut fails to locate your root filesystem. To enable the shell:
<orderedlist>
<listitem>
<para>Add the boot parameter ''rd.shell'' to your bootloader configuration file (e.g. <filename>/etc/grub.conf</filename>)</para>
</listitem>
<listitem>
<para>Remove the boot arguments ''rhgb'' and ''quiet''
</para>
<para>
A sample <filename>/etc/grub.conf</filename> bootloader configuration file is listed below.
</para>
<para><screen>default=0
timeout=5
serial --unit=0 --speed=9600
terminal --timeout=5 serial console
title Fedora (2.6.29.5-191.fc11.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.29.5-191.fc11.x86_64 ro root=/dev/mapper/vg_uc1-lv_root console=tty0 rd.shell
initrd /dracut-2.6.29.5-191.fc11.x86_64.img</screen></para>
</listitem>
<listitem>
<para>If system boot fails, you will be dropped into a shell as seen in the example below.
<screen>No root device found
Dropping to debug shell.
sh: can't access tty; job control turned off
# </screen></para>
</listitem>
<listitem>
<para>Use this shell prompt to gather the information requested above (see <xref linkend="all-bug-reports"/>).
</para>
</listitem>
</orderedlist></para>
</section>
<section id="accessing-the-root-volume-from-the-dracut-shell">
<title id="accessing-the-root-volume-from-the-dracut-shell-title">Accessing the root volume from the dracut shell</title>
<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:
</para>
<itemizedlist>
<listitem>
<para>A block device (e.g. <filename>/dev/sda7</filename>)
</para>
</listitem>
<listitem>
<para>A LVM logical volume (e.g. <filename>/dev/VolGroup00/LogVol00</filename>)
</para>
</listitem>
<listitem>
<para>An encrypted device (e.g. <filename>/dev/mapper/luks-4d5972ea-901c-4584-bd75-1da802417d83</filename>)
</para>
</listitem>
<listitem>
<para>A network attached device (e.g. netroot=iscsi:@192.168.0.4::3260::iqn.2009-02.org.fedoraproject:for.all)
</para>
</listitem>
</itemizedlist>
<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>
<orderedlist>
<listitem>
<para>Inspect your partitions using <command>parted</command><screen># parted /dev/sda -s p
Model: ATA HTS541060G9AT00 (scsi)
Disk /dev/sda: 60.0GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 32.3kB 10.8GB 107MB primary ext4 boot
2 10.8GB 55.6GB 44.7GB logical lvm</screen></para>
</listitem>
<listitem>
<para>You recall that your root volume was a LVM logical volume. Scan and activate any logical volumes.
<screen># lvm vgscan
# lvm vgchange -ay</screen></para>
</listitem>
<listitem>
<para>You should see any logical volumes now using the command <command>blkid</command>:
<screen># blkid
/dev/sda1: UUID="3de247f3-5de4-4a44-afc5-1fe179750cf7" TYPE="ext4"
/dev/sda2: UUID="Ek4dQw-cOtq-5MJu-OGRF-xz5k-O2l8-wdDj0I" TYPE="LVM2_member"
/dev/mapper/linux-root: UUID="def0269e-424b-4752-acf3-1077bf96ad2c" TYPE="crypto_LUKS"
/dev/mapper/linux-home: UUID="c69127c1-f153-4ea2-b58e-4cbfa9257c5e" TYPE="ext3"
/dev/mapper/linux-swap: UUID="47b4d329-975c-4c08-b218-f9c9bf3635f1" TYPE="swap"
</screen></para>
</listitem>
<listitem>
<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.
<screen># UUID=$(cryptsetup luksUUID /dev/mapper/linux-root)
# cryptsetup luksOpen /dev/mapper/linux-root luks-$UUID
Enter passphrase for /dev/mapper/linux-root:
Key slot 0 unlocked. </screen></para>
</listitem>
<listitem>
<para>Next, make a symbolic link to the unlocked root volume
<screen># ln -s /dev/mapper/luks-$UUID /dev/root</screen></para>
</listitem>
<listitem>
<para>With the root volume available, you may continue booting the system by exiting the dracut shell
<screen># exit</screen></para>
</listitem>
</orderedlist>
</section>
<section id="additional-dracut-boot-parameters">
<title id="additional-dracut-boot-parameters-title">Additional dracut boot parameters</title>
<para>For more debugging options, see <xref linkend="dracut-kernel-debug"/> in the man page <xref linkend="dracutkernel7"/>.</para>
</section>
</section>
</section>
</chapter>
<chapter>
<title>Developer Manual</title>
<section>
<title>dracut Components</title>
<para>dracut uses a modular system to build and extend the initramfs image. All modules are located in <filename>/usr/share/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>
<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>
<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>
</section>
<section id="stages">
<title>Boot Process Stages</title>
<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>.
Common used functions are in <filename>dracut-lib.sh</filename>, which can be sourced by any script. </para>
<section>
<title>Basic Setup</title>
<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>
</section>
<section>
<title>Hook: cmdline</title>
<para>The <literal>
<function>cmdline</function>
</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>
<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>
</section>
<section>
<title>Hook: pre-udev</title>
<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>
</section>
<section>
<title>Start Udev</title>
<para>Now <command>udev</command> is started and the logging for <command>udev</command> is setup.</para>
</section>
<section>
<title>Hook: pre-trigger</title>
<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>
</section>
<section>
<title>Trigger Udev</title>
<para><command>udev</command> is triggered by calling <command>udevadm trigger</command>, which sends <constant>add</constant> events for all devices and subsystems.
</para>
</section>
<section>
<title>Main Loop</title>
<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>.
</para>
<section>
<title>Initqueue</title>
<para>This hook gets executed every time a script is inserted here, regardless of the <command>udev</command> state.</para>
</section>
<section>
<title>Initqueue settled</title>
<para>This hooks gets executed every time <command>udev</command> has settled.</para>
</section>
<section>
<title>Initqueue finished</title>
<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>
</section>
</section>
<section>
<title>Hook: pre-mount</title>
<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>
</section>
<section>
<title>Hook: mount</title>
<para>This hook is mainly to mount the real root device.</para>
</section>
<section>
<title>Hook: pre-pivot</title>
<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>
</section>
<section>
<title>Cleanup and switch_root</title>
<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>
<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>
</section>
</section>
<section>
<title>Network Infrastructure</title>
<para>
</para>
</section>
<section>
<title>Writing a Module</title>
<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>
<para>First we create a <filename>check</filename> script, which just exits with <errorcode>0</errorcode> indicating that this module should be included by default.</para>
<para><filename>check</filename>:</para>
<programlisting>exit 0</programlisting>
<para>The we create the install script, 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>
<para><filename>install</filename>:</para>
<programlisting>inst_hook cmdline 20 "$moddir/parse-insmodpost.sh"
inst_simple "$moddir/insmodpost.sh" /sbin/insmodpost.sh</programlisting>
<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>
<para><filename>parse-insmodpost.sh</filename>:</para>
<programlisting>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
</programlisting>
<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>
<para><filename>insmodpost.sh</filename>:</para>
<programlisting>. /lib/dracut-lib.sh
for p in $(getargs rd.driver.post=); do
modprobe $p
done
</programlisting>
<section>
<title>check</title>
<para><filename>check</filename> is called by dracut to evaluate the inclusion of a dracut module in the initramfs.</para>
<para><filename>check</filename> also can be called with arguments, which are described in the following list.</para>
<variablelist>
<varlistentry>
<term><filename>check</filename> -d</term>
<listitem>
<para>If <filename>check</filename> is called with parameter <parameter>-d</parameter>, then the stdout output is taken as the dracut module names of the dependencies this module needs.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><filename>check</filename> -h</term>
<listitem>
<para>If check is called with parameter <parameter>-h</parameter>, then the module check 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>
</listitem>
</varlistentry>
</variablelist>
<para>If <filename>check</filename> is called without parameters, it should return the following exit codes.</para>
<variablelist>
<varlistentry>
<term>exit 0</term>
<listitem>
<para>Include the dracut module in the initramfs.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>exit 1</term>
<listitem>
<para>Do not include the dracut module. The requirements are not fullfilled (missing tools, etc.)</para>
</listitem>
</varlistentry>
<varlistentry>
<term>exit 255</term>
<listitem>
<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>
</listitem>
</varlistentry>
</variablelist>
</section>
<section>
<title>Install</title>
<para>dracut_install</para>
<para>inst</para>
<para>inst_hook</para>
<para>inst_rules</para>
<para/>
</section>
<section>
<title>Installkernel</title>
<para>instmods</para>
</section>
<section>
<title>Creation Functions</title>
<para>
</para>
</section>
<section>
<title>Initramfs Functions</title>
<para>
</para>
</section>
<section>
<title>Network Modules</title>
<para>
</para>
</section>
</section>
</chapter>
<appendix>
<title>Man Pages</title>
<section id="dracut.man">
<title>dracut</title>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.8.xml" encoding="UTF-8" parse="xml"/>
</section>
<section id="dracut.conf">
<title>dracut.conf</title>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.conf.5.xml" encoding="UTF-8" parse="xml"/>
</section>
<section id="dracut.kernel">
<title>dracut.kernel</title>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="dracut.kernel.7.xml" encoding="UTF-8" parse="xml"/>
</section>
</appendix>
</book>
|