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
|
.TH INITRAMFS-TOOLS 8 "2010/06/22" "Linux" "mkinitramfs script overview"
.SH NAME
initramfs-tools \- an introduction to writing scripts for mkinitramfs
.SH DESCRIPTION
initramfs-tools has one main script and two different sets of subscripts which
will be used during different phases of execution. Each of these will be
discussed separately below with the help of an imaginary tool which performs a
frobnication of a lvm partition prior to mounting the root partition.
.SH Kernel Command Line
The root filesystem used by the kernel is specified by the boot loader as
always. The traditional \fBroot=/dev/sda1\fR style device specification is
allowed. If a label is used, as in \fBroot=LABEL=rootPart\fR the initrd will
search all available devices for a filesystem with the appropriate label, and
mount that device as the root filesystem. \fBroot=UUID=uuidnumber\fR will
mount the partition with that UUID as the root filesystem.
.SS Standard
.TP
\fB\fI init= "<path to real init>"
the binary to hand over execution to on the root fs after the initramfs scripts are done.
.TP
\fB\fI root= "<path to blockdevice>"
the device node to mount as the root file system.
The recommended usage is to specify the UUID as followed "root=UUID=xxx".
.TP
\fB\fI rootfstype
set the root file system type.
.TP
\fB\fI rootdelay
set delay in seconds. Determines how long mountroot waits for root to appear.
The default is 180 seconds.
.TP
\fB\fI rootflags
set the file system mount option string.
.TP
\fB\fI nfsroot
can be either "auto" to try to get the relevant information from DHCP or a
string of the form NFSSERVER:NFSPATH or NFSSERVER:NFSPATH:NFSOPTS.
Use root=/dev/nfs for NFS to kick to in. NFSOPTS can be looked up in
\fInfs(5)\fP.
.TP
\fB\fI ip
tells how to configure the ip address. Allows to specify an different
NFS server than the DHCP server. See Documentation/filesystems/nfsroot.txt
in any recent Linux source for details. Optional parameter for NFS root.
.TP
\fB\fI BOOTIF
is a mac address in pxelinux format with leading "01-" and "-" as separations.
pxelinux passes mac address of network card used to PXE boot on with this
bootarg.
.TP
\fB\fI boot
either local or NFS (affects which initramfs scripts are run, see the "Subdirectories" section under boot scripts).
.TP
\fB\fI resume
On install initramfs-tools tries to autodetect the resume partition. On success
the RESUME variable is written to /etc/initramfs-tools/conf.d/resume.
The boot variable noresume overrides it.
.TP
\fB\fI resume_offset
Specify the offset from the partition given by "resume=" at which the swap
header of the swap file is located.
.TP
\fB\fI quiet
reduces the amount of text output to the console during boot.
.TP
\fB\fI ro
mounts the rootfs read-only.
.TP
\fB\fI rw
mounts the rootfs read-write.
.TP
\fB\fI blacklist
disables load of specific modules.
Use blacklist=module1,module2,module3 bootparameter.
.SS Debug
.TP
\fB\fI panic
sets an timeout on panic.
panic=<sec> is a documented security feature: it disables the debug shell.
.TP
\fB\fI debug
generates lots of output. It writes a log to /dev/.initramfs/initramfs.debug.
Instead when invoked with an arbitrary argument output is written to console.
Use for example "debug=vc".
.TP
\fB\fI break
spawns a shell in the initramfs image at chosen run-time
(top, modules, premount, mount, mountroot, bottom, init).
The default is premount without any arg.
Beware that if both "panic" and "break" are present,
initramfs will not spawn any shells but reboot instead.
.TP
\fB\fI netconsole
loads netconsole linux modules with the chosen args.
.TP
\fB\fI all_generic_ide
loads generic IDE/ATA chipset support on boot.
.SH HOOK SCRIPTS
Valid boot and hook scripts names consist solely of alphabetics, numerics,
dashes and underscores. Other scripts are discarded.
.SS Hook scripts
These are used when an initramfs image is created and not included in the
image itself. They can however cause files to be included in the image.
Hook scripts are executed under errexit. Thus a hook script can abort the
mkinitramfs build on possible errors (exitcode != 0).
.SS Boot scripts
These are included in the initramfs image and normally executed during
kernel boot in the early user-space before the root partition has been
mounted.
Hooks can be found in two places: /usr/share/initramfs-tools/hooks and
/etc/initramfs-tools/hooks. They are executed during generation of the
initramfs-image and are responsible for including all the necessary components
in the image itself. No guarantees are made as to the order in which the
different scripts are executed unless the prereqs are setup in the script.
.SS Header
In order to support prereqs, each script should begin with the following lines:
.RS
.nf
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
\fR. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
.fi
.RE
For example, if you are writing a new hook script which relies on lvm, the line
starting with PREREQ should be changed to PREREQ="lvm" which will ensure that
the lvm hook script is run before your custom script.
.SS Help functions
/usr/share/initramfs-tools/hook-functions contains a number of functions which
deal with some common tasks in a hook script:
.TP
\fB\fI
manual_add_modules
adds a module (and any modules which it depends on) to the initramfs image.
.RS
.PP
.B Example:
manual_add_modules isofs
.RE
.TP
\fB\fI
add_modules_from_file
reads a file containing a list of modules (one per line) to be added to the
initramfs image. The file can contain comments (lines starting with #) and
arguments to the modules by writing the arguments on the same line as the name
of the module.
.RS
.PP
.B Example:
add_modules_from_file /tmp/modlist
.RE
.TP
\fB\fI
force_load
adds a module (and its dependencies) to the initramfs image and also
unconditionally loads the module during boot. Also supports passing arguments
to the module by listing them after the module name.
.RS
.PP
.B Example:
force_load cdrom debug=1
.RE
.TP
\fB\fI
copy_modules_dir
copies an entire module directory from /lib/modules/KERNELVERSION/ into the
initramfs image.
.RS
.PP
.B Example:
copy_modules_dir kernel/drivers/ata
.RE
.SS Including binaries
If you need to copy binaries to the initramfs module, a command like this
should be used:
.PP
.RS
copy_exec /sbin/mdadm /sbin
.RE
mkinitramfs will automatically detect which libraries the executable depends on
and copy them to the initramfs. This means that most executables, unless
compiled with klibc, will automatically include glibc in the image which will
increase its size by several hundred kilobytes.
.SS Exported variables
mkinitramfs sets several variables for the hook scripts environment.
.TP
\fB\fI MODULESDIR
corresponds to the linux-2.6 modules dir.
.TP
\fB\fI version
is the $(uname \-r) linux-2.6 version against mkinitramfs is run.
.TP
\fB\fI CONFDIR
is the path of the used initramfs-tools configurations.
.TP
\fB\fI DESTDIR
is the root path of the newly build initramfs.
.TP
\fB\fI DPKG_ARCH
allows arch specific hook additions.
.TP
\fB\fI verbose
corresponds to the verbosity of the update-initramfs run.
.TP
\fB\fI KEYMAP
sets if a keymap needs to be added to initramfs.
.TP
\fB\fI MODULES
specifies which kind of modules should land on initramfs.
This setting shouldn't be overridden by hook script, but can guide them
on how much they need to include on initramfs.
.SH BOOT SCRIPTS
Similarly to hook scripts, boot scripts can be found in two places
/usr/share/initramfs-tools/scripts/ and /etc/initramfs-tools/scripts/. There
are a number of subdirectories to these two directories which control the boot
stage at which the scripts are executed.
.SS Header
Like for hook scripts, there are no guarantees as to the order in which the
different scripts in one subdirectory (see "Subdirectories" below) are
executed. In order to define a certain order, a similar header as for hook
scripts should be used:
.RS
.nf
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
.fi
.RE
Where PREREQ is modified to list other scripts in the same subdirectory if necessary.
.SS Help functions
A number of functions (mostly dealing with output) are provided to boot scripts in
.I /scripts/functions
:
.TP
\fB\fI
log_success_msg
Logs a success message
.RS
.PP
.B Example:
log_success_msg "Frobnication successful"
.RE
.TP
\fB\fI
log_failure_msg
Logs a failure message
.RS
.PP
.B Example:
log_failure_msg "Frobnication component froobz missing"
.RE
.TP
\fB\fI
log_warning_msg
Logs a warning message
.RS
.PP
.B Example:
log_warning_msg "Only partial frobnication possible"
.RE
.TP
\fB\fI
log_begin_msg
Logs a message that some processing step has begun
.TP
\fB\fI
log_end_msg
Logs a message that some processing step is finished
.RS
.PP
.B Example:
.PP
.RS
.nf
log_begin_msg "Frobnication begun"
# Do something
log_end_msg
.fi
.RE
.RE
.TP
\fB\fI
panic
Logs an error message and executes a shell in the initramfs image to allow the
user to investigate the situation.
.RS
.PP
.B Example:
panic "Frobnication failed"
.RE
.SS Subdirectories
Both /usr/share/initramfs-tools/scripts and /etc/initramfs-tools/scripts
contains the following subdirectories.
.TP
\fB\fI
init-top
the scripts in this directory are the first scripts to be executed after sysfs
and procfs have been mounted and /dev/console and /dev/null have been created.
No other device files are present yet.
.TP
\fB\fI
init-premount
runs the udev hooks for populating the /dev tree (udev will keep running until
init-bottom) after modules specified by hooks and /etc/initramfs-tools/modules
have been loaded.
.TP
\fB\fI
local-top OR nfs-top
After these scripts have been executed, the root device node is expected to be
present (local) or the network interface is expected to be usable (NFS).
.TP
\fB\fI
local-premount OR nfs-premount
are run after the sanity of the root device has been verified (local) or the
network interface has been brought up (NFS), but before the actual root fs has
been mounted.
.TP
\fB\fI
local-bottom OR nfs-bottom
are run after the rootfs has been mounted (local) or the NFS root share has
been mounted. udev is stopped.
.TP
\fB\fI
init-bottom
are the last scripts to be executed before procfs and sysfs are moved to the
real rootfs and execution is turned over to the init binary which should now be
found in the mounted rootfs.
.SS Boot parameters
.TP
\fB\fI
/conf/param.conf
allows boot scripts to change exported variables that are listed on top of init. Write the new values to it. It will be sourced after an boot script run if it exists.
.SH EXAMPLES
.SS Hook script
An example hook script would look something like this (and would usually be
placed in /etc/initramfs-tools/hooks/frobnicate):
.RS
.nf
#!/bin/sh
# Example frobnication hook script
PREREQ="lvm"
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
\fR. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
if [ ! \-x "/sbin/frobnicate" ]; then
exit 0
fi
force_load frobnicator interval=10
cp /sbin/frobnicate "${DESTDIR}/sbin"
exit 0
.fi
.RE
.SS Boot script
An example boot script would look something like this (and would usually be placed in /etc/initramfs-tools/scripts/local-top/frobnicate):
.RS
.nf
#!/bin/sh
# Example frobnication boot script
PREREQ="lvm"
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
\fR. /scripts/functions
# Begin real processing below this line
if [ ! \-x "/sbin/frobnicate" ]; then
panic "Frobnication executable not found"
fi
if [ ! \-e "/dev/mapper/frobb" ]; then
panic "Frobnication device not found"
fi
log_begin_msg "Starting frobnication"
/sbin/frobnicate "/dev/mapper/frobb" || panic "Frobnication failed"
log_end_msg
exit 0
.fi
.RE
.SS Exported variables
init sets several variables for the boot scripts environment.
.TP
\fB\fI ROOT
corresponds to the root boot option.
Advanced boot scripts like cryptsetup or live-initramfs need to play tricks.
Otherwise keep it alone.
.TP
\fB\fI ROOTDELAY, ROOTFLAGS, ROOTFSTYPE, IP
corresponds to the rootdelay, rootflags, rootfstype or ip boot option.
.TP
\fB\fI DPKG_ARCH
allows arch specific boot actions.
.TP
\fB\fI blacklist, panic, quiet, resume, noresume, resume_offset
set according relevant boot option.
.TP
\fB\fI break
Useful for manual intervention during setup and coding an boot script.
.TP
\fB\fI REASON
Argument passed to the \fIpanic\fP helper function. Use to find out why
you landed in the initramfs shell.
.TP
\fB\fI init
passes the path to init(8) usually /sbin/init.
.TP
\fB\fI readonly
is the default for mounting the root corresponds to the ro bootarg.
Overridden by rw bootarg.
.TP
\fB\fI rootmnt
is the path where root gets mounted usually /root.
.TP
\fB\fI debug
indicates that a debug log is captured for further investigation.
.SH DEBUG
It is easy to check the generated initramfs for its content. One may need
to double-check if it contains the relevant binaries, libs or modules:
.RS
.nf
mkdir tmp/initramfs
cd tmp/initramfs
gunzip \-c /boot/initrd.img\-2.6.18\-1\-686 | \\
cpio \-i \-d \-H newc \-\-no\-absolute\-filenames
.fi
.RE
.SH AUTHOR
The initramfs-tools are written by Maximilian Attems <maks@debian.org>,
Jeff Bailey <jbailey@raspberryginger.com> and numerous others.
.PP
This manual was written by David H\[:a]rdeman <david@hardeman.nu>,
updated by Maximilian Attems <maks@debian.org>.
.SH SEE ALSO
.BR
.IR initramfs.conf (5),
.IR mkinitramfs (8),
.IR update-initramfs(8).
|