]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- target compression detection is done
[projects/geninitrd.git] / geninitrd
CommitLineData
bb529f94
JK
1#!/bin/sh
2
3# geninitrd
4#
45d4d8cb 5# by PLD Linux Team
bb529f94 6#
9e1ceabe 7# based on mkinitrd from RedHat Linux
e4b07ddc 8#
c31050f3 9
897acff9 10RCSID='$Revision$ $Date$'
c5fea685 11R=${RCSID#* *}; VERSION=${R%% *}
ca2c2012 12PROGRAM=${0##*/}
bb529f94
JK
13
14. /etc/rc.d/init.d/functions
ded87775 15. /lib/geninitrd/functions
e2405b29 16. /etc/sysconfig/system
bb529f94 17
c124d0cf
ER
18# list of geninitrd modules which need setup routine after commandline args parsing
19GENINITRD_MODS=""
c3667d07 20COMPRESS=yes
bb529f94
JK
21target=""
22kernel=""
23force=""
24verbose=""
25MODULES=""
26img_vers=""
c3667d07 27fstab=/etc/fstab
c3667d07 28modext=.o
4e9eb79c 29rootdev_nr=0
738c05d8
ER
30# device node for rootfs from fstab
31rootdev=""
bb529f94 32
8bd582f1
ER
33# internal variables
34# is /dev on tmpfs
b64f015b
ER
35dev_mounted=no
36# is /proc mounted
37proc_mounted=no
38# is /sys mounted
39sys_mounted=no
40# is /tmp mounted on tmpfs
41tmp_mounted=no
42
43# are /dev nodes already created from /proc/devices info?
8bd582f1 44proc_partitions=no
6b013929 45
b64f015b 46usage() {
553786c4 47 uname_r=$(uname -r)
00eaa938 48 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
ac085800 49 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
29f7d622 50 echo " [--compress=yes|xz|lzma|bzip2|gzip]"
92ed99b6 51 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
ba5d09f0 52 echo " [--with-bootsplash] [--without-bootsplash]"
6c69a2d4
ER
53 echo " [--with-fbsplash] [--without-fbsplash]"
54 echo " [--with-fbcondecor] [--without-fbcondecor]"
e4b07ddc 55 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
ba5d09f0 56 echo " [--with-suspend] [--without-suspend]"
1cd2aabd 57 echo " [--with-tuxonice] [--without-tuxonice]"
ecd7bf46
ER
58 echo " [--without-dmraid]"
59 echo " [--with-multipath=DEVPATH] [--without-multipath]"
3ef3d717 60 echo " [--without-blkid] [--without-luks]"
ac085800 61 echo " <initrd-image> <kernel-version>"
553786c4
ER
62 echo ""
63 echo "example:"
00eaa938 64 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
36523626 65 exit 0
bb529f94
JK
66}
67
779a218a 68msg() {
f4010f7f
AM
69 echo "$PROGRAM: $*"
70}
71
72warn() {
4a60c01f 73 msg "WARNING: $*" >&2
779a218a
AM
74}
75
94769f11 76debug() {
4a60c01f 77 [ -n "$verbose" ] && msg "$*" >&2
94769f11 78}
aa69da6e 79
bf6c3fcb
ER
80# aborts program abnormally
81die() {
b5f5c089 82 local rc=${2:-1}
046c68c9 83 msg "ERROR: $1" >&2
bf6c3fcb
ER
84 exit $rc
85}
86
684d5d2a
ER
87# find program from specified paths
88find_tool() {
89 local x
90 for x in "$@"; do
91 if [ -x "$x" ]; then
92 echo $x
93 debug "find_tool: found $x"
94 return 0
95 fi
96 done
97 debug "find_tool: did not found any of: $@"
98 return 1
99}
100
c124d0cf
ER
101# loads geninitrd modules
102geninitrd_load_mods() {
103 local mod
104 for mod in "$@"; do
105 if [ ! -f /lib/geninitrd/mod-$mod.sh ]; then
106 die "$mod geninitrd module can't be loaded"
107 fi
108 . /lib/geninitrd/mod-$mod.sh
109
110 if type setup_mod_$mod > /dev/null; then
111 # add to list which need init
112 GENINITRD_MODS="$GENINITRD_MODS $mod"
113 fi
114 done
115}
116
117# setup geninitrd modules
118geninitrd_setup_mods() {
119 local mod
120
121 for mod in $GENINITRD_MODS; do
122 eval setup_mod_$mod
123 done
124}
125
c6c6ce01
ER
126# append text to /linuxrc
127# takes STDIN as input
128add_linuxrc() {
b64f015b 129 cat >> "$RCFILE"
c6c6ce01
ER
130}
131
b64f015b
ER
132# generate code to mount /dev on tmpfs and create initial nodes
133# can be called multiple times. /dev is cleaned up (umounted) automatically at
134# the end of script.
135mount_dev() {
136 if [ "$INITRDFS" = "initramfs" ]; then
137 # initramfs is read-write filesystem, no need for tmpfs
138 return
139 fi
140
141 # we already generated tmpfs code; return
142 if is_yes "$dev_mounted"; then
143 return
144 fi
145
146 dev_mounted=yes
147
148 busybox_applet mount mknod mkdir
149 add_linuxrc <<-EOF
150 : 'Creating /dev'
151 mount -o mode=0755 -t tmpfs none /dev
152 mknod /dev/console c 5 1
153 mknod /dev/null c 1 3
154 mknod /dev/zero c 1 5
8b7ac737 155 mknod /dev/urandom c 1 9
b64f015b
ER
156 mkdir /dev/pts
157 mkdir /dev/shm
158 EOF
159}
160
161# generate code to mount /proc on initrd
162# can be called multiple times
163mount_proc() {
164 if is_yes "$proc_mounted"; then
165 return
166 fi
167
168 proc_mounted=yes
2bface63
ER
169 if [ "$INITRDFS" = "initramfs" ]; then
170 # /proc is mounted with initramfs 2.6.22.14 kernel
171 # XXX: remove when it is clear why proc was already mounted
172 echo "[ -f /proc/cmdline ] || mount -t proc none /proc" | add_linuxrc
173 else
174 echo "mount -t proc none /proc" | add_linuxrc
175 fi
b64f015b
ER
176}
177
178# generate code to mount /sys on initrd
179# can be called multiple times
180mount_sys() {
181 if is_yes "$sys_mounted"; then
182 return
183 fi
184
185 sys_mounted=yes
186 echo "mount -t sysfs none /sys" | add_linuxrc
187}
188
189# generate code to mount /tmp on initrd
190# can be called multiple times
191mount_tmp() {
192 if [ "$INITRDFS" = "initramfs" ]; then
193 # initramfs is read-write filesystem, no need for tmpfs
194 return
195 fi
196
197 if is_yes "$tmp_mounted"; then
198 return
199 fi
200
201 tmp_mounted=yes
202 echo "mount -t tmpfs none /tmp" | add_linuxrc
203}
204
205# unmount all mountpoints mounted by geninitrd
206umount_all() {
ec49b7e6
ER
207
208 add_linuxrc <<-'EOF'
903f21ea 209 : Last shell before umounting all and giving control over to real init.
ec49b7e6
ER
210 debugshell
211 EOF
5b70f84d 212
b64f015b
ER
213 if is_yes "$dev_mounted"; then
214 echo 'umount /dev' | add_linuxrc
215 dev_mounted=no
216 fi
b64f015b
ER
217 if is_yes "$sys_mounted"; then
218 echo 'umount /sys' | add_linuxrc
219 sys_mounted=no
220 fi
221 if is_yes "$tmp_mounted"; then
222 echo 'umount /tmp' | add_linuxrc
223 tmp_mounted=no
224 fi
3c42f0a4
ER
225 if is_yes "$proc_mounted"; then
226 echo 'umount /proc' | add_linuxrc
227 proc_mounted=no
228 fi
b64f015b
ER
229}
230
231
9299682f
ER
232# Checks if busybox has support for APPLET(s)
233# Exits from geninitrd if the support is not present.
234#
235# NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
236busybox_applet() {
30495bbf 237 local err=0 applet
9299682f
ER
238
239 if [ -z "$busybox_functions" ]; then
684d5d2a 240 local tmp=$($busybox 2>&1)
9b1373fb
ER
241
242 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
243 if [[ "$tmp" = *applet\ not\ found* ]]; then
244 local t=$(mktemp -d)
684d5d2a 245 ln -s $busybox $t/busybox
9b1373fb
ER
246 local tmp=$($t/busybox 2>&1)
247 rm -rf $t
248 fi
249
250 busybox_functions=$(echo "$tmp" | \
9299682f
ER
251 sed -ne '/Currently defined functions:/,$p' | \
252 xargs | sed -e 's,.*Currently defined functions: ,,'
253 )
254 fi
255 for applet in $*; do
256 local have
257 # try cache
258 eval have='$'busybox_have_$applet
259 if [ -z "$have" ]; then
260 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
261 if [ "$have" = 0 ]; then
f4010f7f 262 warn "This setup requires busybox-initrd compiled with applet '$applet' support"
9299682f
ER
263 err=1
264 fi
265 eval busybox_have_$applet=$have
266 fi
267 done
268 if [ $err = 1 ]; then
00eaa938 269 die "Aborted"
9299682f
ER
270 fi
271}
272
25cb53df
ER
273# extract-ikconfig - Extract the .config file from a kernel image
274#
275# The obscure use of the "tr" filter is to work around older versions of
276# "grep" that report the byte offset of the line instead of the pattern.
277#
278# (c) 2009, Dick Streefland <dick@streefland.net>
279# Licensed under the terms of the GNU General Public License.
280#
281# Ripped and adjusted for geninitrd from linux-2.6.34/scripts/extract-ikconfig
282extract-ikconfig() {
283 local img=$(mktemp)
284 local kofile=$(modinfo -k $kernel -n configs)
285 case "$kofile" in
286 '')
287 return
288 ;;
289 *.gz)
290 gzip -dc "$kofile" > $img
291 ;;
292 *)
293 cat "$kofile" > $img
294 ;;
295 esac
296
297 local cf1='IKCFG_ST\037\213\010'
298 local cf2='0123456789'
299 local pos
300
301 if pos=$(tr "$cf1\n$cf2" "\n$cf2=" < "$img" | grep -abo "^$cf2"); then
302 pos=${pos%%:*}
303 tail -c+$(($pos+8)) "$img" | gzip -dcq
304 fi
305 rm -f $img
306}
307
7ffba534
ER
308# Finds module dependencies
309#
7ffba534
ER
310# @param $module
311#
046c68c9 312# Outputs full path to module and it's dependencies
7ffba534 313find_depmod() {
fe280785 314 local module="$1"
046c68c9
ER
315 local skiperrors=0
316
317 # if module is prefixed with dash, we should ignore errors if the module
318 # can't be found.
319 if [ ${module#-} != $module ]; then
320 skiperrors=1
321 module=${module#-}
322 fi
323
046c68c9
ER
324 # This works when user has module-init-tools installed even on 2.4 kernels
325 local modprobe
326 modprobe=$(modprobe --set-version $kernel --show-depends $module --ignore-install 2>&1)
327
328 if [ $? != 0 ]; then
329 if [ $skiperrors = 1 ]; then
7cac5014
ER
330 return
331 fi
046c68c9 332 echo >&2 "$modprobe"
7cac5014 333
7ffba534 334 if ! is_no "$EXIT_IF_MISSING"; then
046c68c9 335 die "$module: module not found for $kernel kernel"
7ffba534 336 fi
046c68c9
ER
337
338 warn "$module: module not found for $kernel kernel"
339 warn "If $module isn't compiled in kernel then this initrd may not start your system."
7ffba534
ER
340 fi
341
046c68c9 342 echo "$modprobe" | \
c25765ed 343 while read insmod modpath options; do
59a68735 344 [ "$insmod" = "insmod" ] && echo $modpath
7ffba534
ER
345 done
346}
347
4a60c01f
AM
348find_firmware() {
349 local module="$1"
601127ea
ER
350
351 # no firmware support in 2.4 kernels
352 if [ "$kernel_version_long" -lt "002005048" ]; then
353 return
354 fi
355 echo -n $(NEW_MODINFO=1 modinfo -k $kernel -F firmware $module 2>/dev/null | xargs)
4a60c01f
AM
356}
357
046c68c9
ER
358# @param $module
359find_module() {
360 local mod depmod module=$1
ac085800 361
046c68c9 362 depmod=$(find_depmod $module) || exit 1
fe280785 363 for mod in $depmod; do
7ffba534 364 mod=${mod#/lib/modules/$kernel/}
fe280785
ER
365
366 # add each module only once
367 local m have=0
368 for m in $MODULES; do
369 [ $m = $mod ] && have=1
370 done
371 if [ $have = 0 ]; then
c2eb7d4f 372 MODULES="$MODULES $mod"
fe280785 373 fi
10c3df06 374 done
bb529f94
JK
375}
376
034fdd5d
ER
377# install a file to temporary mount image.
378# it will operate recursively (copying directories)
379# and will symlink destinations if source is symlink.
bb529f94 380inst() {
17e97aec 381 if [ $# -lt 2 ]; then
a9ace64a 382 die 'Usage: inst <file> [<file>] <destination>'
c31050f3 383 fi
17e97aec
ER
384
385 local src i=0 c=$(($# - 1))
386 while [ $i -lt $c ]; do
387 src="$src $1"
388 i=$((i + 1))
389 shift
390 done
391 local dest=$1
392 set -- $src
242f2358
PZ
393 parentDir=$(dirname $DESTDIR$dest)
394 [ ! -d "$parentDir" ] && (debug "+ mkdir -p $parentDir"; mkdir -p $parentDir)
d8056591 395 debug "+ cp $* $DESTDIR$dest"
9b557a09 396 cp -HR "$@" "$DESTDIR$dest"
bb529f94
JK
397}
398
dab92b1d 399inst_d() {
17e97aec 400 if [ $# = 0 ]; then
a9ace64a 401 die 'Usage: inst_d <destination> <destination>'
034fdd5d
ER
402 fi
403 for dir in "$@"; do
9b557a09 404 install -d "$DESTDIR$dir"
034fdd5d
ER
405 done
406}
407
209061e3
ER
408# install executable and it's shared libraries
409inst_exec() {
17e97aec 410 if [ $# -lt 2 ]; then
3601c2fa 411 die "Invalid params ($@), Usage: inst_exec <file>[, <file>] <destination>"
17e97aec 412 fi
209061e3
ER
413 local src i=0 c=$(($# - 1))
414 while [ $i -lt $c ]; do
415 src="$src $1"
416 i=$((i + 1))
417 shift
418 done
9b532fe6 419 local dest=$1
209061e3
ER
420 set -- $src
421
9b532fe6
ER
422 inst "$@" $dest
423
5265962d 424 local lib libs=$(ldd "$@" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
9b532fe6 425 for lib in $libs; do
9b557a09 426 if [ ! -f "$DESTDIR/$_lib/${lib##*/}" ]; then
7efbe841
ER
427 inst_d /$_lib
428 inst_exec $lib /$_lib
17e97aec 429 fi
209061e3 430 done
c7ade647
ER
431
432 # hack for uclibc linked binaries requiring this fixed path
433 # XXX: shouldn't rpath be used here instead so th
434 if [ -f $DESTDIR/$_lib/libc.so.0 ]; then
435 local lib=$DESTDIR/$_lib/libc.so.0
436 lib=$(ldd "$lib" | awk '/statically|linux-(gate|vdso)\.so/{next} NF == 2 {print $1} /=/{print $3}' | sort -u)
437 local libdir=$(cd $(dirname "$lib"); pwd)
438 if [ ! -e $DESTDIR$libdir ]; then
439 libdir=$(dirname "$libdir")
440 inst_d $libdir
441 debug "+ ln -s /$_lib $DESTDIR$libdir"
442 ln -s /$_lib $DESTDIR$libdir
443 fi
444 fi
209061e3
ER
445}
446
82474db9
ER
447# output modules.conf / modprobe.conf
448modprobe_conf() {
449 echo "$modprobe_conf_cache"
450}
451
452#
453# defaults to modprobe -c if not told otherwise, this means include statements
454# work from there.
455cache_modprobe_conf() {
707f5e60 456 if [ "$kernel_version" -lt "002005" ]; then
82474db9
ER
457 modulefile=/etc/modules.conf
458 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
459 modulefile=/etc/conf.modules
460 fi
461 fi
462
463 if [ -n "$modulefile" ]; then
d8056591 464 debug "Using $modulefile for modules config"
82474db9
ER
465 modprobe_conf_cache=$(cat $modulefile)
466 else
d8056591 467 debug "Using modprobe -c to get modules config"
520412e9 468 modprobe_conf_cache=$(modprobe -c --set-version $kernel)
82474db9
ER
469 fi
470}
471
bc0d6f2d 472# find modules for $devpath
d8056591 473find_modules_for_devpath() {
bc0d6f2d
ER
474 local devpath="$1"
475 if [ -z "$devpath" ]; then
d8056591 476 die "No argument passed to find_modules_for_devpath() - is your /etc/fstab correct?"
f6536797 477 fi
ac085800 478
c2eb7d4f
ER
479 if [[ "$devpath" = /dev/dm-* ]]; then
480 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
bc0d6f2d 481 devpath=$(dm_longname "$devpath")
c2eb7d4f
ER
482 fi
483
67aa84bd 484 if [ -L "$devpath" ] && ! is_lvm "$devpath"; then
c2eb7d4f
ER
485 # sanitize things like:
486 # /dev/block/104:2 -> /dev/cciss/c0d0p2
487 devpath=$(readlink -f "$devpath")
488 fi
489
d8056591 490 debug "Finding modules for device path $devpath"
bc0d6f2d 491
3ef3d717
ER
492 if is_luks "$devpath"; then
493 find_modules_luks "$devpath"
494 return
495 fi
496
74d45ce1
ER
497 if is_nfs "$devpath"; then
498 find_modules_nfs "$devpath"
d9179777
ER
499 return
500 fi
501
e16414d9 502 if is_md "$devpath"; then
df738638 503 find_modules_md "$devpath"
d9179777
ER
504 return
505 fi
506
c3b54060 507 if is_multipath "$devpath"; then
07137fe3 508 if find_modules_multipath "$devpath"; then
9baf4f3f 509 return
9baf4f3f 510 fi
ecd7bf46 511
9baf4f3f
ER
512 # fallback
513 fi
514
36523626 515 if is_dmraid "$devpath"; then
c083ae23
ER
516 if find_modules_dmraid "$devpath"; then
517 return
518 fi
519 # fallback
520 fi
521
35043b20
ER
522 if is_scsi "$devpath"; then
523 find_modules_scsi "$devpath"
d9179777
ER
524 return
525 fi
526
30ca4815 527 if is_ide "$devpath"; then
bc0d6f2d 528 find_modules_ide "$devpath"
d9179777
ER
529 return
530 fi
531
07b09cf9 532 if [[ "$devpath" == /dev/rd/* ]]; then
046c68c9 533 find_module "DAC960"
c3313cd6 534 rootdev_add=/dev/rd/
d9179777
ER
535 return
536 fi
537
07b09cf9 538 if [[ "$devpath" == /dev/ida/* ]]; then
046c68c9 539 find_module "cpqarray"
c3313cd6 540 rootdev_add=/dev/ida/
d9179777
ER
541 return
542 fi
543
08651ad1 544 if [[ "$devpath" == /dev/cciss/* ]]; then
046c68c9 545 find_module "cciss"
c3313cd6 546 rootdev_add=/dev/cciss/
d9179777
ER
547 return
548 fi
549
07b09cf9 550 if [[ "$devpath" == /dev/ataraid/* ]]; then
ac085800 551 find_modules_ide
046c68c9 552 find_module "ataraid"
82474db9 553 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
9ae446b9 554 if [ -n "$ataraidmodules" ]; then
7c38b114 555 # FIXME: think about modules compiled in kernel
82474db9 556 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
7c38b114
AF
557 fi
558 for n in $ataraidmodules; do
046c68c9 559 find_module "$n"
7c38b114 560 done
c3313cd6 561 rootdev_add=/dev/ataraid/
d9179777
ER
562 return
563 fi
564
7c38b114 565 # check to see if we need to set up a loopback filesystem
07b09cf9 566 if [[ "$devpath" == /dev/loop* ]]; then
00eaa938 567 die "Sorry, root on loop device isn't supported."
7c38b114
AF
568 # TODO: rewrite for bsp and make nfs ready
569 if [ ! -x /sbin/losetup ]; then
00eaa938 570 die "losetup is missing"
7c38b114 571 fi
bc0d6f2d 572 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
82474db9 573 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
42820142 574 die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the $PROGRAM man page for more information"
7c38b114
AF
575 fi
576
577 line="`awk '/'$key'/ { print $0; }' $fstab`"
578 loopDev="$(echo $line | awk '{print $3}')"
579 loopFs="$(echo $line | awk '{print $4}')"
580 loopFile="$(echo $line | awk '{print $5}')"
581
582 BASICMODULES="$BASICMODULES -loop"
046c68c9 583 find_module "-$loopFs"
7c38b114 584 BASICMODULES="$BASICMODULES -${loopFs}"
d9179777
ER
585 return
586 fi
587
67aa84bd
ER
588 if is_lvm "$devpath"; then
589 find_modules_lvm "$devpath"
d9179777 590 return
7c38b114
AF
591 fi
592}
593
b64f015b 594firmware_install_module() {
c3667d07 595 local module="$1"
c6c6ce01 596 local firmware_files="$2"
9ed6e1db 597
94769f11 598 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
9ed6e1db 599 # firmware not yet installed
9b557a09 600 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
034fdd5d 601 inst_d /lib/firmware
9b557a09 602cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db 603#!/bin/sh -e
8639f99a
AM
604echo 1 > /sys$DEVPATH/loading
605cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
606echo 0 > /sys$DEVPATH/loading
607exit 0
9ed6e1db 608EOF
9b557a09 609 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db
AM
610 fi
611
612 for firmware in $firmware_files; do
80b23733 613 if [ -f "/lib/firmware/$kernel/$firmware" ]; then
486d26a5 614 FIRMWAREDIR=${firmware%/*}
4a9920e7 615 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
80b23733
ER
616 inst /lib/firmware/$kernel/$firmware /lib/firmware/$firmware
617 elif [ -f "/lib/firmware/$firmware" ]; then
c661b23c 618 FIRMWAREDIR=${firmware%/*}
619 [ "$FIRMWAREDIR" != "$firmware" ] && inst_d /lib/firmware/$FIRMWAREDIR
80b23733 620 inst /lib/firmware/$firmware /lib/firmware/$firmware
c661b23c 621 else
80b23733 622 die "firmware file /lib/firmware/$firmware nor /lib/firmware/$kernel/$firmware found."
4a60c01f 623 fi
9ed6e1db
AM
624 done
625
b64f015b 626 mount_sys
c6c6ce01 627 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
9ed6e1db
AM
628}
629
2a5bcca9 630modules_install() {
c3667d07
ER
631 local modules="$1"
632 local mod
2a5bcca9
AM
633
634 for mod in $modules; do
fe280785 635 MODULEDIR=${mod%/*}
4a9920e7 636 inst_d "/lib/modules/$kernel/$MODULEDIR"
9b557a09
ER
637 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
638 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
2a5bcca9
AM
639 done
640}
641
642modules_add_linuxrc() {
fe280785 643 local mod modpath
ac085800 644
fe280785
ER
645 for mod in "$@"; do
646 # module path without optional compression
647 modpath=${mod%.gz}
648
649 # name of the module
8011a76c
ER
650 local module=${modpath##*/}; module=${module%$modext}
651 local options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}' | xargs)
652 local genericname=$(echo $module | tr - _)
653 local usleep=$(eval echo \$MODULE_${genericname}_USLEEP)
654 local firmware=$(eval echo \$MODULE_${genericname}_FIRMWARE)
2a5bcca9 655
3e1d0df9
AM
656 if [ "$module" = "scsi_mod" -a "$kernel_version_long" -ge "002006030" ]; then
657 options="scan=sync $options"
658 fi
659
ac085800 660 if [ -n "$verbose" ]; then
8a47b72c
ER
661 s=""
662 if [ "$options" ]; then
663 s="$s with options [$options]"
664 fi
8011a76c
ER
665 if [ "$usleep" ]; then
666 s="$s and $usleep usleep"
8a47b72c 667 fi
4a60c01f 668 debug "Loading module [$module]$s"
ac085800
ER
669 fi
670
8011a76c
ER
671 if [ -n "$firmware" ]; then
672 firmware_install_module "$module" "$firmware"
4a60c01f 673 else
06e481d7
ER
674 for file in $(find_firmware "$module"); do
675 firmware_install_module "$module" "$file"
676 done
9ed6e1db 677 fi
4a60c01f 678
18ece493 679 echo "insmod /lib/modules/$kernel/$modpath $options" | add_linuxrc
8011a76c
ER
680 if [ -n "$usleep" ]; then
681 echo "usleep $usleep" | add_linuxrc
8e598759 682 fi
e00dcfcb 683 if [ "$module" = "scsi_wait_scan" ]; then
d29583e0
ER
684 if [ "$(busybox_applet rmmod 2>/dev/null; echo $?)" = 0 ]; then
685 echo "rmmod scsi_wait_scan" | add_linuxrc
686 fi
e00dcfcb
AM
687 fi
688
2a5bcca9
AM
689 done
690}
691
82b2dba2
ER
692# Generates /dev nodes based on /proc/partitions information.
693# Needs /proc mounted.
694# Can be called multiple times.
695initrd_gen_devices() {
696 if is_yes "$proc_partitions"; then
697 return
698 fi
699 proc_partitions=yes
335cd101 700
82b2dba2
ER
701 mount_dev
702 add_linuxrc <<-'EOF'
703 : 'Making device nodes'
704 cat /proc/partitions | (
8d4aba01 705 # ignore first two lines: header, empty line
82b2dba2 706 read b; read b
2cc3ae8b 707
82b2dba2
ER
708 while read major minor blocks dev rest; do
709 node=/dev/$dev
710 mkdir -p ${node%/*}
8d4aba01 711 [ -e $node ] || mknod $node b $major $minor
82b2dba2
ER
712 done
713 )
714 EOF
715}
bb529f94 716
82b2dba2 717
4828c787 718initrd_gen_setrootdev() {
5a761721 719 debug "Adding rootfs finding based on kernel cmdline root= option support."
82b2dba2 720 add_linuxrc <<-'EOF'
dcdf6b49
ER
721 if [ "${ROOT##/dev/}" != "${ROOT}" ]; then
722 rootnr="$(busybox awk -v rootnode="${ROOT##/dev/}" '$4 == rootnode { print 256 * $1 + $2 }' /proc/partitions)"
82b2dba2
ER
723 if [ -n "$rootnr" ]; then
724 echo "$rootnr" > /proc/sys/kernel/real-root-dev
725 fi
726 fi
b64f015b 727 EOF
1606e343
AM
728}
729
4671d086
ER
730initrd_gen_initramfs_switchroot() {
731 inst_d /newroot
732 if [ "$rootdev" = "/dev/nfs" ]; then
733 echo "rootfs on NFS root=/dev/nfs"
734 else
735 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev $rootdev
736 fi
5845b321
ER
737
738 # parse 'root=xxx' kernel commandline
4671d086
ER
739 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
740 add_linuxrc <<-'EOF'
741 device=/dev/no_partition_found
742 eval "$(busybox awk -v c="$ROOT" '
743 BEGIN {
744 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
745 num_pattern = "[0-9a-f]" num_pattern_short;
746 dev_pattern = "[hms][a-z][a-z]([0-9])+";
747 partition = "no_partition_found";
748 min = -1; maj = -1;
749
750 sub("^0x", "", c);
751 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
752 if (c ~ "^" num_pattern "$") {
753 maj = sprintf("%s",substr(c,1,2));
754 min = sprintf("%s",substr(c,3));
755 }
756 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
757 if (c ~ "^" dev_pattern "$") partition = c;
758 }
759
760 $4 ~ partition { maj = $1; min = $2; }
761 $1 ~ maj && $2 ~ min { partition = $4; }
762
763 END {
fa3a5452
ER
764 if (maj >= 0 && min >= 0) {
765 printf("device=/dev/%s; maj=%s; min=%s;\n", partition, maj, min);
766 }
4671d086
ER
767 }
768 ' /proc/partitions)"
769 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
770 mknod $device b $maj $min
771 fi
772 EOF
773
774 add_linuxrc <<-EOF
775 rootdev=$rootdev
776 rootfs=$rootFs
777 EOF
778
779 add_linuxrc <<-'EOF'
780 if [ "$device" = '/dev/no_partition_found' ]; then
781 device=$rootdev
782 fi
783
784 mount -t $rootfs -r $device /newroot
785 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
786 if [ -z "$init" -o ! -x "/newroot$init" ]; then
787 init=/sbin/init
788 fi
789 EOF
790
791 umount_all
792 busybox_applet switch_root
793 add_linuxrc <<-'EOF'
f8ea6a63 794 exec switch_root /newroot $init ${1:+"$@"}
4671d086
ER
795
796 echo "Error! initramfs should not reach this place."
797 echo "It probably means you've got old version of busybox, with broken"
798 echo "initramfs support. Trying to boot anyway, but won't promise anything."
799
f8ea6a63 800 exec chroot /newroot $init ${1:+"$@"}
4671d086
ER
801
802 echo "Failed to chroot!"
803 EOF
804 # we need /init being real file, not symlink, otherwise the initramfs will
805 # not be ran by pid 1 which is required for switch_root
806 mv $DESTDIR/linuxrc $DESTDIR/init
807 ln -s init $DESTDIR/linuxrc
808}
809
c552503c
ER
810# find if $symbol exists in System.map $mapfile
811sym_exists() {
812 local mapfile="$1"
813 local symbol="$2"
814 if [ ! -f $mapfile ]; then
815 # missing mapfile (not a pld kernel?)
816 return 1
817 fi
818
819 awk -vc=1 -vsymbol="$symbol" '$2 == "T" && $3 == symbol {c = 0} END {exit c}' $mapfile
820}
821
822# find best compressor (or forced one) for initrd
823find_compressor() {
824 local mode="$1"
825 # the best compressor list
29f7d622 826 local compressors='xz lzma bzip2 gzip'
c552503c
ER
827
828 # a specified one, take it
55aaf2fe
AM
829 if ! is_yes "$mode"; then
830 compressors="$mode"
c552503c
ER
831 fi
832
833 debug "finding compressor: $compressors (via $mode)"
834 # check for compressor validity
835 local c prog map=/boot/System.map-$kernel
836 for c in $compressors; do
837 case $c in
66d146a5 838 xz)
29f7d622
AM
839 sym=unxz
840 prog=/usr/bin/xz
841 ;;
842 lzma)
c552503c 843 sym=unlzma
66d146a5 844 prog=/usr/bin/xz
c552503c
ER
845 ;;
846 bzip2)
847 sym=bzip2
c42692d4 848 prog=/usr/bin/bzip2
c552503c
ER
849 ;;
850 gzip)
851 sym=gunzip
c42692d4 852 prog=/bin/gzip
c552503c
ER
853 ;;
854 *)
855 die "Unknown compressor $c"
856 ;;
857 esac
c454c66e 858 if sym_exists $map $sym && [ -x $prog ]; then
c552503c
ER
859 echo $c
860 return
861 fi
862 done
863
864 debug "using gzip for compressor (fallback)"
865 echo gzip
866}
867
82b2dba2
ER
868if [ -r /etc/sysconfig/geninitrd ]; then
869 . /etc/sysconfig/geninitrd
870fi
2cc3ae8b 871
c215292c
AG
872if [ ! -f /proc/mounts ]; then
873 warn "/proc filesystem not mounted, may cause wrong results or failure."
874fi
875
35043b20 876geninitrd_load_mods ide luks multipath dmraid lvm md blkid udev tuxonice suspend fbsplash condecor bootsplash uvesafb nfs scsi
c124d0cf 877
82b2dba2
ER
878while [ $# -gt 0 ]; do
879 case $1 in
880 --fstab=*)
881 fstab=${1#--fstab=}
882 ;;
883 --fstab)
884 fstab=$2
885 shift
886 ;;
887 --modules-conf=*)
888 modulefile=${1#--modules-conf=}
889 ;;
890 --modules-conf)
891 modulefile=$2
892 shift
893 ;;
82b2dba2
ER
894 --with-bootsplash)
895 BOOT_SPLASH=yes
896 ;;
897 --without-bootsplash)
898 BOOT_SPLASH=no
899 ;;
900 --with-fbsplash)
901 FB_SPLASH=yes
902 ;;
903 --without-fbsplash)
904 FB_SPLASH=no
905 ;;
6c69a2d4
ER
906 --with-fbcondecor)
907 FB_CON_DECOR=yes
908 ;;
909 --without-fbcondecor)
910 FB_CON_DECOR=no
911 ;;
82b2dba2
ER
912 --with-suspend)
913 USE_SUSPEND=yes
914 ;;
915 --without-suspend)
916 USE_SUSPEND=no
917 ;;
918 --with-suspend2 | --with-tuxonice)
919 USE_TUXONICE=yes
920 ;;
921 --without-suspend2 | --without-tuxonice)
922 USE_TUXONICE=no
923 ;;
80b1ed79 924 --lvmversion=*)
7308edee 925 LVMTOOLSVERSION=${1#--lvmversion=}
82b2dba2 926 ;;
80b1ed79 927 --lvmtoolsversion=*)
928 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
929 ;;
82b2dba2
ER
930 --lvmtoolsversion|--lvmversion)
931 LVMTOOLSVERSION=$2
932 shift
933 ;;
934 --without-udev)
935 USE_UDEV=no
936 ;;
937 --with-udev)
938 USE_UDEV=yes
939 ;;
940 --without-dmraid)
941 USE_DMRAID=no
942 ;;
943 --without-multipath)
ecd7bf46
ER
944 USE_MULTIPATH=no
945 ;;
946 --with-multipath=*)
947 USE_MULTIPATH=${1#--with-multipath=}
82b2dba2 948 ;;
af075488 949 --without-blkid)
950 USE_BLKID=no
289fbc9b 951 ;;
3ef3d717
ER
952 --without-luks)
953 USE_LUKS=no
954 ;;
82b2dba2
ER
955 --with=*)
956 BASICMODULES="$BASICMODULES ${1#--with=}"
957 ;;
958 --with)
959 BASICMODULES="$BASICMODULES $2"
960 shift
961 ;;
962 --version)
963 echo "$PROGRAM: version $VERSION"
964 exit 0
965 ;;
966 -v)
967 verbose=-v
968 ;;
c552503c
ER
969 --compress)
970 COMPRESS=$2
971 ;;
972 --compress=*)
973 COMPRESS="${1#--compress=}"
974 ;;
82b2dba2
ER
975 --nocompress)
976 COMPRESS=no
977 ;;
978 --ifneeded)
979 ifneeded=1
980 ;;
981 -f)
982 force=1
983 ;;
984 --preload=*)
985 PREMODS="$PREMODS ${1#--preload=}"
986 ;;
987 --preload)
988 PREMODS="$PREMODS $2"
989 shift
990 ;;
2965cab9 991 --fs=* | --fs)
bbbc32d0 992 die "--fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
993 ;;
994 --initrdfs=*)
995 INITRDFS=${1#--initrdfs=}
996 ;;
997 --initrdfs)
998 INITRDFS=$2
999 shift
1000 ;;
1001 --image-version)
1002 img_vers=yes
1003 ;;
1004 --ide-only-root)
1005 ide_only_root="yes"
1006 ;;
1007 *)
1008 if [ -z "$target" ]; then
1009 target="$1"
1010 elif [ -z "$kernel" ]; then
1011 kernel="$1"
1012 else
36523626
ER
1013 usage >&2
1014 exit 1
82b2dba2
ER
1015 fi
1016 ;;
1017 esac
f5db170b 1018
82b2dba2
ER
1019 shift
1020done
1021
1022if [ -z "$target" -o -z "$kernel" ]; then
36523626
ER
1023 usage >&2
1024 exit 1
82b2dba2
ER
1025fi
1026
93a38d1a
ER
1027# main()
1028if [ "$(id -u)" != 0 ]; then
1029 die "You need to be root to generate initrd"
1030fi
1031
a48c38c7 1032if [ -d /lib64 -a -d /usr/lib64 ]; then
c124d0cf
ER
1033 _lib=lib64
1034else
1035 _lib=lib
130aadc1
ER
1036fi
1037
c124d0cf 1038initrd_dir=/usr/$_lib/initrd
707f5e60
ER
1039kernel_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1040kernel_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
82b2dba2 1041
c124d0cf
ER
1042debug "# $RCSID"
1043debug "Using _lib: $_lib"
1044debug "Using initrd_dir: $initrd_dir"
1045
6ec4aea6 1046busybox=$(find_tool $initrd_dir/busybox $initrd_dir/initrd-busybox /bin/initrd-busybox) || die "Couldn't find busybox suitable for initrd"
c124d0cf
ER
1047
1048# we setup mods after parsing command line args
1049geninitrd_setup_mods
1050
1051if [ ! -f /boot/vmlinuz-"$kernel" ]; then
1052 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
1053fi
1054
82b2dba2 1055if [ -z "$INITRDFS" ]; then
bbbc32d0
ER
1056 if [ -n "$FS" ]; then
1057 # FS= can came only via /etc/sysconfig/geninitrd likely?
1058 die "FS configuration option is obsoleted. Use INITRDFS instead"
f5db170b 1059 fi
f5db170b 1060
bbbc32d0
ER
1061 # default value
1062 if [ "$kernel_version" -ge "002005" ]; then
1063 INITRDFS="initramfs"
1064 else
1065 INITRDFS="rom"
1066 fi
82b2dba2 1067fi
966c32cc 1068
82b2dba2 1069case "$INITRDFS" in
4877276e
ER
1070 ext2)
1071 [ -x /sbin/mke2fs ] || die "/sbin/mke2fs is missing"
1072 ;;
1073 rom|romfs)
1074 [ -x /sbin/genromfs ] || die "/sbin/genromfs is missing"
1075 ;;
1076 cram|cramfs)
1077 [ -x /sbin/mkcramfs ] || die "/sbin/mkcramfs is missing"
1078 ;;
1079 initramfs)
1080 [ -x /bin/cpio ] || die "/bin/cpio is missing"
1081 [ -x /usr/bin/find ] || die "/usr/bin/find is missing"
1082 ;;
1083 *)
1084 die "Filesystem $INITRDFS on initrd is not supported"
1085 ;;
82b2dba2 1086esac
f5db170b 1087
9323ada3 1088if [ -L "$target" ]; then
1089 target=$(readlink -f "$target")
1090fi
1091
82b2dba2
ER
1092if [ -n "$img_vers" ]; then
1093 target="$target-$kernel"
1094fi
8bd582f1 1095
82b2dba2
ER
1096if [ -z "$force" -a -f "$target" ]; then
1097 die "$target already exists."
1098fi
c6c6ce01 1099
82b2dba2
ER
1100if [ ! -d "/lib/modules/$kernel" ]; then
1101 die "/lib/modules/$kernel is not a directory."
1102fi
2ffb1734 1103
bbbc32d0
ER
1104if [ "$kernel_version" -ge "002005" ]; then
1105 modext=".ko"
1106fi
1107
82b2dba2
ER
1108cache_modprobe_conf
1109
1110for n in $PREMODS; do
046c68c9 1111 find_module "$n"
82b2dba2
ER
1112done
1113
ed30e3a8 1114if [ "$FBMODULE" ]; then
046c68c9 1115 find_module "$FBMODULE"
ed30e3a8
ER
1116fi
1117
82b2dba2 1118# allow forcing loading SCSI and/or IDE modules
35043b20 1119# XXX: where ADDSCSI cames from? drop?
82b2dba2
ER
1120if is_yes "$ADDSCSI"; then
1121 find_modules_scsi
1122fi
1123
e2d6ca6c 1124# autodetect XATA modules
1125# autodetect_xata
1126
35043b20 1127# XXX: where ADDIDE cames from? drop?
82b2dba2
ER
1128if is_yes "$ADDIDE"; then
1129 find_modules_ide
1130fi
1131
4c16dac4
ER
1132if is_yes "$USE_SUSPEND"; then
1133 find_modules_suspend
1134fi
1135
82b2dba2
ER
1136find_root "$fstab" || exit
1137debug "Using $rootdev as device for rootfs"
1138
d8056591 1139find_modules_for_devpath "$rootdev"
ac085800 1140
ecd7bf46
ER
1141# if USE_MULTIPATH is path to device, scan that too
1142# this is to bootstrap multipath setup into initrd.
1143if ! is_no "$USE_MULTIPATH" && ! is_yes "$USE_MULTIPATH"; then
1144 find_modules_multipath $USE_MULTIPATH
1145fi
1146
046c68c9 1147find_module "-$rootFs"
ac085800 1148
82b2dba2 1149for n in $BASICMODULES; do
046c68c9 1150 find_module "$n"
82b2dba2 1151done
4e9eb79c 1152
82b2dba2 1153if is_yes "$USE_TUXONICE"; then
046c68c9 1154 find_module "-lzf"
82b2dba2 1155fi
33d24e12 1156
bf6d9c64 1157find_modules_fbsplash
2968c9dd 1158
82b2dba2
ER
1159if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1160 debug "No modules are needed -- not building initrd image."
1161 exit 0
1162fi
c6c6ce01 1163
6fc274fb 1164debug "Building initrd..."
d8056591 1165DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
9b557a09 1166RCFILE="$DESTDIR/linuxrc"
82b2dba2
ER
1167> "$RCFILE"
1168chmod a+rx "$RCFILE"
9b557a09 1169ln -s linuxrc $DESTDIR/init
e8d178ff 1170
82b2dba2
ER
1171# create dirs that we really need
1172inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
e8d178ff 1173
82b2dba2 1174modules_install "$MODULES"
b64f015b 1175
82b2dba2
ER
1176# mknod'ing the devices instead of copying them works both with and
1177# without devfs...
9b557a09
ER
1178mknod "$DESTDIR/dev/console" c 5 1
1179mknod "$DESTDIR/dev/null" c 1 3
1180mknod "$DESTDIR/dev/zero" c 1 5
94dce45c 1181mknod "$DESTDIR/dev/urandom" c 1 9
be2f3ecc 1182
6ec4aea6
JR
1183inst_exec $busybox /bin/busybox
1184ln -s busybox $DESTDIR/bin/sh
1185# for older busyboxes who had /bin/initrd-busybox as EXEPATH
1186ln -s busybox $DESTDIR/bin/initrd-busybox
2ffb1734 1187
82b2dba2
ER
1188add_linuxrc <<EOF
1189#!/bin/sh
1190# initrd generated by:
1191# $RCSID
c6c6ce01 1192
82b2dba2
ER
1193EOF
1194mount_proc
1195add_linuxrc <<-'EOF'
3a1d3d88 1196 read CMDLINE < /proc/cmdline; export CMDLINE
c6c6ce01 1197
82b2dba2
ER
1198 for arg in $CMDLINE; do
1199 if [ "${arg}" = "debuginitrd" ]; then
1200 DEBUGINITRD=yes
1201 fi
1202 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1203 DEBUGINITRD=${arg##debuginitrd=}
1204 fi
fc787d45 1205 if [ "${arg##root=}" != "${arg}" ]; then
1206 ROOT=${arg##root=}
1207 fi
82b2dba2 1208 done
c6c6ce01 1209
82b2dba2
ER
1210 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1211 if [ "$DEBUGINITRD" = "sh" ]; then
1212 debugshell() {
e2405b29
AM
1213EOF
1214if is_yes "$RUN_SULOGIN_ON_ERR"; then
1215add_linuxrc <<-'EOF'
1216 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1217EOF
1218else
1219add_linuxrc <<-'EOF'
1220 sh
1221EOF
1222fi
1223add_linuxrc <<-'EOF'
82b2dba2
ER
1224 }
1225 else
1226 debugshell() {
1227 :
1228 }
1229 fi
e934d044 1230
82b2dba2
ER
1231 if [ "$DEBUGINITRD" ]; then
1232 set -x
cff3058d 1233 fi
82b2dba2 1234EOF
2df2e995 1235
fe280785 1236modules_add_linuxrc $MODULES
82b2dba2
ER
1237
1238# TODO: rewrite for busybox
1239#if [ -n "$loopDev" ]; then
1240# if [ ! -d /initrd ]; then
1241# mkdir /initrd
1242# fi
1243#
9b557a09
ER
1244# cp -a "$loopDev" "$DESTDIR/dev"
1245# cp -a "$rootdev" "$DESTDIR/dev"
82b2dba2
ER
1246# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1247# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1248# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1249# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1250#fi
2b1a3707 1251
1606e343
AM
1252if is_yes "$USE_UDEV"; then
1253 initrd_gen_udev
1254fi
1255
1cd2aabd
ER
1256if is_yes "$USE_TUXONICE"; then
1257 initrd_gen_tuxonice
2df2e995
AM
1258fi
1259
3dd50160
ER
1260find_modules_uvesafb
1261initrd_gen_uvesafb
43258faf 1262
3ef3d717
ER
1263if is_yes "$have_luks"; then
1264 initrd_gen_luks
1265fi
1266
cc8e8a99 1267if is_yes "$have_dmraid"; then
882472ae
ER
1268 initrd_gen_dmraid
1269fi
1270
c083ae23 1271if is_yes "$have_multipath"; then
2cc3ae8b
ER
1272 initrd_gen_multipath
1273fi
1274
cc8e8a99 1275if is_yes "$USE_BLKID"; then
289fbc9b 1276 initrd_gen_blkid
1277fi
1278
69b1e935 1279if is_yes "$have_nfs"; then
2df2e995 1280 initrd_gen_nfs
8dadb607 1281elif is_yes "$have_md"; then
df738638 1282 initrd_gen_md
69b1e935 1283 if is_yes "$have_lvm"; then
2df2e995 1284 initrd_gen_lvm
bfea009a 1285 else
4828c787 1286 initrd_gen_setrootdev
2df2e995 1287 fi
69b1e935 1288elif is_yes "$have_lvm"; then
2df2e995 1289 initrd_gen_lvm
2b1a3707 1290else
4828c787 1291 initrd_gen_setrootdev
7c38b114
AF
1292fi
1293
4c16dac4
ER
1294if is_yes "$USE_SUSPEND"; then
1295 initrd_gen_suspend
1296fi
1297
5101a385 1298# additional devs always needed
9b557a09 1299[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1300
82de999f
ER
1301if is_yes "$USE_UDEV"; then
1302 initrd_gen_stop_udevd
1303fi
1304
f8f9e56d 1305if [ "$INITRDFS" = "initramfs" ]; then
4671d086 1306 initrd_gen_initramfs_switchroot
b64f015b 1307else
b64f015b 1308 umount_all
f8f9e56d
AM
1309fi
1310
b7feffb3
ER
1311if is_yes "$FB_SPLASH"; then
1312 initrd_gen_fbsplash
1313fi
1314
6c69a2d4
ER
1315if is_yes "$FB_CON_DECOR"; then
1316 initrd_gen_fbcondecor
1317fi
1318
d8056591 1319IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
51dc1fe6
AM
1320
1321debug "Creating $INITRDFS image $IMAGE"
2ad94d8a 1322case "$INITRDFS" in
4877276e 1323 ext2)
4877276e
ER
1324 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1325 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1326 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1327
1328 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
1329 debug "Mounting ext2 image $IMAGE to $tmpmnt"
1330 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1331 # We don't need this directory, so let's save space
1332 rm -rf "$tmpmnt"/lost+found
1333
1334 debug "Copy recursively $DESTDIR -> $tmpmnt"
1335 cp -a $DESTDIR/* $tmpmnt
1336 umount "$IMAGE"
1337 rmdir "$tmpmnt"
1338
1339 ;;
1340 rom|romfs)
1341 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
4877276e
ER
1342 ;;
1343 cram|cramfs)
1344 mkcramfs "$DESTDIR" "$IMAGE"
1345 ;;
1346 initramfs)
1347 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
1348 ;;
1349 *)
93a38d1a 1350 die "Filesystem $INITRDFS not supported by $PROGRAM"
c31050f3 1351esac
bb529f94 1352
25cb53df
ER
1353CONFIG_BLK_DEV_RAM_SIZE=$(extract-ikconfig | awk -F= '/^CONFIG_BLK_DEV_RAM_SIZE/{print $2}')
1354if [ -z "$CONFIG_BLK_DEV_RAM_SIZE" ]; then
1355 CONFIG_BLK_DEV_RAM_SIZE=4096
1356fi
e3bc44e2
ER
1357
1358IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
1359debug "image size: $IMAGESIZE KiB ($DESTDIR)"
1360if [ "$IMAGESIZE" -gt $CONFIG_BLK_DEV_RAM_SIZE ]; then
1361 warn "Your image size is larger than $CONFIG_BLK_DEV_RAM_SIZE, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
1362fi
1363
c552503c 1364if ! is_no "$COMPRESS"; then
aecfd33d 1365 tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
c552503c
ER
1366 compressor=$(find_compressor "$COMPRESS")
1367 debug "Compressing $target with $compressor"
1368
1369 # TODO: the image name (specified from kernel.spec) already contains
1370 # extension, which is .gz most of the time.
1371 case "$compressor" in
66d146a5 1372 xz)
a9a98c64
AM
1373 # don't use -9 here since kernel won't understand it
1374 xz --format=xz --check=crc32 --lzma2=preset=6e,dict=1MiB < "$IMAGE" > "$tmp"
29f7d622
AM
1375 ;;
1376 lzma)
b738ab0d 1377 xz --format=lzma -9 < "$IMAGE" > "$tmp"
c552503c
ER
1378 ;;
1379 bzip2)
1380 bzip2 -9 < "$IMAGE" > "$tmp"
1381 ;;
1382 gzip)
1383 gzip -9 < "$IMAGE" > "$tmp"
1384 ;;
1385 esac
d8056591 1386 mv -f "$tmp" "$target"
bb529f94 1387else
7d2fc5eb 1388 cp -a "$IMAGE" "$target"
bb529f94 1389fi
5b71959c 1390
7992356a 1391# XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
5b71959c 1392if is_yes "$BOOT_SPLASH"; then
f5db170b 1393 initrd_gen_bootsplash "$target"
5b71959c
AM
1394fi
1395
d8056591 1396rm -rf "$DESTDIR" "$IMAGE"
ac085800
ER
1397
1398# vim:ts=4:sw=4:noet:fdm=marker
This page took 0.560277 seconds and 4 git commands to generate.