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