]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- cosmetics
[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#
9# TODO:
c3667d07 10# - make udev start before insmods
e4b07ddc 11# - make proper use of USE_UDEV - don't copy fules if USE_UDEV is off no!
12# - sanitize - one mounting of /proc and /sys at the begining and one umount at the end!
aebe301c 13#
c31050f3 14
28eec2b1 15RCSID='$Id$'
ca2c2012
ER
16R=${RCSID#* * }; VERSION=${R%% *}
17PROGRAM=${0##*/}
bb529f94
JK
18
19. /etc/rc.d/init.d/functions
1cea325b 20. /etc/geninitrd/functions
bb529f94 21
c3667d07
ER
22COMPRESS=yes
23USERAIDSTART=yes
24USEMDADMSTATIC=no
25USEINSMODSTATIC=no
26USE_SUSPEND=yes
27USE_TUXONICE=yes
10c3df06
MM
28# it should be safe to remove scsi_mod from here, but I'm not sure...
29PRESCSIMODS="-scsi_mod unknown -sd_mod"
64497ebb
AM
30PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
31PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
bb529f94
JK
32target=""
33kernel=""
34force=""
35verbose=""
36MODULES=""
37img_vers=""
c3667d07
ER
38fstab=/etc/fstab
39insmod=insmod
40modext=.o
4e9eb79c 41rootdev_nr=0
738c05d8
ER
42# device node for rootfs from fstab
43rootdev=""
5b71959c
AM
44# default bootsplash is off, if it have to be on, install bootsplash package
45BOOT_SPLASH=no
e4b07ddc 46# default same as bootsplash, if on install splashutils and some splashutils theme
47FB_SPLASH=no
48# defualt we don't use udev to make nodes for static modules, as per default
49# PLD loads the modules needed to mount and boot
50PROBESTATICMODULES=no
bb529f94 51
8bd582f1
ER
52# internal variables
53# is /dev on tmpfs
54tmpfs_dev=no
55# is /proc/devices entries already created
56proc_partitions=no
6b013929
ER
57
58# LVM devices that should not be included in vgscan on initrd
f8a1a92c 59lvm_ignore_devices=''
c083ae23 60
69b1e935
ER
61# if we should init NFS at boot
62have_nfs=no
63# if we should init LVM at boot
df738638
ER
64have_lvm=no
65# if we should init md (softraid) at boot
66have_md=no
c083ae23
ER
67# if we should init dmraid at boot
68have_dmraid=no
9baf4f3f 69# if we should init dm-multipath at boot
69b1e935 70have_multipath=no
b4d9d384 71
447ff04b 72if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
c3667d07 73 USE_UDEV=yes
1606e343
AM
74 . /etc/udev/udev.conf
75fi
882472ae
ER
76
77if [ -x /sbin/dmraid-initrd ]; then
c3667d07 78 USE_DMRAID=yes
882472ae 79fi
ac085800 80
2cc3ae8b 81if [ -x /sbin/multipath ]; then
c3667d07 82 USE_MULTIPATH=yes
2cc3ae8b
ER
83fi
84
bb529f94 85usage () {
553786c4 86 uname_r=$(uname -r)
00eaa938 87 echo "usage: $PROGRAM [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
ac085800 88 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
92ed99b6 89 echo " [--initrdfs=rom|initramfs|ext2|cram] [--modules-conf=<modules.conf>]"
ac085800 90 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
ba5d09f0 91 echo " [--with-bootsplash] [--without-bootsplash]"
92 echo " [ --with-fbsplash] [--without-fbsplash]"
e4b07ddc 93 echo " [--lvmtoolsversion=1|2] [--with-udev] [--without-udev]"
ba5d09f0 94 echo " [--with-suspend] [--without-suspend]"
1cd2aabd 95 echo " [--with-tuxonice] [--without-tuxonice]"
2cc3ae8b 96 echo " [--without-dmraid] [--without-multipath]"
ac085800 97 echo " <initrd-image> <kernel-version>"
553786c4
ER
98 echo ""
99 echo "example:"
00eaa938 100 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
7d2fc5eb 101 exit 1
bb529f94
JK
102}
103
94769f11 104debug() {
f155a80b 105 [ -n "$verbose" ] && echo >&2 "$*"
94769f11 106}
aa69da6e 107
bf6c3fcb
ER
108# aborts program abnormally
109die() {
b5f5c089 110 local rc=${2:-1}
bf6c3fcb
ER
111 echo >&2 "$PROGRAM: ERROR: $1"
112 exit $rc
113}
114
9299682f
ER
115# Checks if busybox has support for APPLET(s)
116# Exits from geninitrd if the support is not present.
117#
118# NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
119busybox_applet() {
120 local err=0
121
122 if [ -z "$busybox_functions" ]; then
9b1373fb
ER
123 local tmp=$(/bin/initrd-busybox 2>&1)
124
125 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
126 if [[ "$tmp" = *applet\ not\ found* ]]; then
127 local t=$(mktemp -d)
128 ln -s /bin/initrd-busybox $t/busybox
129 local tmp=$($t/busybox 2>&1)
130 rm -rf $t
131 fi
132
133 busybox_functions=$(echo "$tmp" | \
9299682f
ER
134 sed -ne '/Currently defined functions:/,$p' | \
135 xargs | sed -e 's,.*Currently defined functions: ,,'
136 )
137 fi
138 for applet in $*; do
139 local have
140 # try cache
141 eval have='$'busybox_have_$applet
142 if [ -z "$have" ]; then
143 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
144 if [ "$have" = 0 ]; then
145 echo >&2 "This setup requires busybox-initrd compiled with applet '$applet' support"
146 err=1
147 fi
148 eval busybox_have_$applet=$have
149 fi
150 done
151 if [ $err = 1 ]; then
00eaa938 152 die "Aborted"
9299682f
ER
153 fi
154}
155
10c3df06
MM
156find_depmod () {
157 typeset mods module f level depfile first
158
159 depfile=/lib/modules/$kernel/modules.dep
ac085800 160
00eaa938 161 if [ ! -f $depfile ]; then
9e1ceabe 162 die "No $depfile! Run depmod and rerun $PROGRAM."
f6de9380 163 fi
ac085800 164
0868f49f 165 # prepend / if no path given, append $modext.gz if not given,
10c3df06 166 # quote /
3b00e899 167 origmodule="$2"
10c3df06 168 module=$(echo "$2" | \
ac085800
ER
169 awk '/\// {print;next} {print "/" $0}' | \
170 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
171 awk '{gsub("/","\\/");print}')
10c3df06
MM
172 mods=$(awk '
173BEGIN { here = 0 }
174/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
175/:/ { here = 0 }
176/(.*)/ { gsub(/\\/," "); if (here) print }
4fd11db9
AF
177' $depfile | xargs)
178
0868f49f 179 # fallback to $modext
07b09cf9 180 if [ "$mods" = "" ]; then
00eaa938 181 module=$(echo "$module" | awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
740d6215 182 # ") - vim
ac085800 183 fi
00eaa938 184
4fd11db9
AF
185 mods=$(awk '
186BEGIN { here = 0 }
187/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
188/:/ { here = 0 }
189/(.*)/ { gsub(/\\/," "); if (here) print }
10c3df06
MM
190' $depfile | xargs)
191
07b09cf9
ER
192 if [ "$mods" = "" ]; then
193 if [ "$1" != silent ]; then
94769f11 194 echo >&2 "$origmodule: module not found in $depfile"
10c3df06 195 fi
00eaa938 196 if ! is_no "$EXIT_IF_MISSING"; then
fd2dc249
AF
197 exit 1
198 else
94769f11 199 echo >&2 "If $origmodule isn't compiled in kernel then this initrd may not start your system."
fd2dc249 200 fi
10c3df06 201 fi
ac085800 202
10c3df06 203 level=$3
07b09cf9 204 if [ "$level" = "" ]; then
10c3df06
MM
205 level=0
206 fi
94769f11 207 level=$((level + 1))
07b09cf9 208 if [ $level -gt 20 ]; then
00eaa938 209 die "$origmodule: cycle in $depfile"
10c3df06 210 fi
ac085800 211
10c3df06 212 first=
82474db9 213 for f in $mods; do
07b09cf9 214 if [ "$first" = "" ]; then
10c3df06 215 first=$f
413878f8 216 else
10c3df06 217 find_depmod $1 $f $level
9c9f7cdb 218 fi
aa69da6e 219 done
ac085800 220
10c3df06 221 echo $first
aa69da6e 222}
223
10c3df06 224addmodule() {
c3667d07
ER
225 local fmPath=$1
226 local skiperrors=$2
10c3df06
MM
227
228 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
229 if [ -n "$skiperrors" ]; then
230 return
231 fi
232
00eaa938 233 die "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)"
10c3df06
MM
234 fi
235
236 # only need to add each module once
237 # quote /
c3667d07 238 local tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
82474db9 239 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}'; then
10c3df06
MM
240 MODULES="$MODULES $fmPath"
241 fi
81de8443
AF
242}
243
bb529f94 244findmodule() {
c3667d07
ER
245 local skiperrors=""
246 local modName=$1
10c3df06 247
94769f11 248 if [ ${modName#-} != ${modName} ]; then
413878f8 249 skiperrors=1
94769f11 250 modName=${modName#-}
413878f8 251 fi
bb529f94 252
10c3df06 253 # what's that?
413878f8 254 if [ "$modName" = "pluto" ]; then
255 findmodule fc4
256 findmodule soc
257 fi
258 if [ "$modName" = "fcal" ]; then
259 findmodule fc4
260 findmodule socal
261 fi
bb529f94 262
c3667d07 263 local mod allModulesToFind
10c3df06 264 if [ -n "$skiperrors" ]; then
94769f11 265 allModulesToFind=$(find_depmod silent $modName)
10c3df06 266 else
94769f11
ER
267 allModulesToFind=$(find_depmod normal $modName)
268 if [ $? != 0 ]; then
10c3df06 269 exit 1
413878f8 270 fi
413878f8 271 fi
ac085800 272
94769f11
ER
273 for mod in $allModulesToFind; do
274 mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//, ""); print}')
10c3df06
MM
275 addmodule $mod "$skiperrors"
276 done
bb529f94
JK
277}
278
034fdd5d
ER
279# install a file to temporary mount image.
280# it will operate recursively (copying directories)
281# and will symlink destinations if source is symlink.
bb529f94 282inst() {
dab92b1d 283 if [ "$#" -lt "2" ];then
1775ba37 284 die 'Usage: inst <file> $MNTIMAGE<destination>'
c31050f3 285 fi
1775ba37 286 cp -HR "$1" "$MNTIMAGE$2"
bb529f94
JK
287}
288
dab92b1d 289inst_d() {
034fdd5d 290 if [ "$#" = "0" ];then
dab92b1d 291 die 'Usage: inst_d $MNTIMAGE<destination> $MNTIMAGE<destination>'
034fdd5d
ER
292 fi
293 for dir in "$@"; do
034fdd5d
ER
294 install -d "$MNTIMAGE$dir"
295 done
296}
297
82474db9
ER
298# output modules.conf / modprobe.conf
299modprobe_conf() {
300 echo "$modprobe_conf_cache"
301}
302
303#
304# defaults to modprobe -c if not told otherwise, this means include statements
305# work from there.
306cache_modprobe_conf() {
307 if [ "$pack_version" -lt "002005" ]; then
308 modulefile=/etc/modules.conf
309 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
310 modulefile=/etc/conf.modules
311 fi
312 fi
313
314 if [ -n "$modulefile" ]; then
315 debug "modprobe: using $modulefile"
316 modprobe_conf_cache=$(cat $modulefile)
317 else
318 debug "modprobe: using modprobe -c"
319 modprobe_conf_cache=$(modprobe -c)
320 fi
321}
322
df738638
ER
323find_modules_md() {
324 local found raidlevel
325
ac085800 326 if [ -f /etc/mdadm.conf ]; then
94769f11 327 debug "Finding RAID details using mdadm for rootdev=$1"
ac085800
ER
328 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
329 BEGIN {
330 found = "no";
331 dev_list = "";
332 raidlevel = ""
333 rootdev_devfs = rootdev;
334 if (rootdev ~ /\/dev\/md\/[0-9]/) {
335 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
336 }
514a668a 337 }
ac085800
ER
338
339 /^ARRAY/ {
340 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
341 raidlevel=$3;
342 gsub(/level=/,NUL,raidlevel);
343 if (raidlevel ~ /^raid([0-6]|10)/) {
344 gsub(/raid/,NUL,raidlevel);
345 };
346 found="yes";
347 getline x;
348 if (x ~ /devices=/) {
349 dev_list = x;
350 gsub(".*devices=", NUL, dev_list);
351 gsub(",", " ", dev_list);
352 }
353 }
56946560 354 }
ac085800
ER
355
356 END {
df738638 357 print "have_md=" found;
ac085800
ER
358 print "raidlevel=" raidlevel;
359 print "dev_list=\"" dev_list "\"";
360 }'`
361 fi
7c38b114 362
df738638 363 if [ "$have_md" != "yes" -a -f /etc/raidtab ]; then
00eaa938 364 die "raidtools are not longer supported. Please migrate to mdadm setup!"
809cc4cc 365 fi
ac085800 366
82474db9 367 if is_yes "$have_md"; then
7c38b114 368 case "$raidlevel" in
bf17c86c 369 [01]|10)
7c38b114
AF
370 findmodule "raid$raidlevel"
371 ;;
bf17c86c
AM
372 [456])
373 findmodule "-raid$raidlevel"
374 findmodule "-raid456"
375 ;;
7c38b114
AF
376 linear)
377 findmodule "linear"
378 ;;
379 *)
94769f11 380 echo >&2 "raid level $number (in mdadm config) not recognized"
7c38b114
AF
381 ;;
382 esac
88614cd1 383 else
00eaa938 384 die "RAID devices not found for \"$1\", check your configuration!"
7c38b114 385 fi
4e9eb79c
AM
386
387 rootdev_nr=$(( $rootdev_nr + 1 ))
388 eval "rootdev${rootdev_nr}=\"$1\""
389 eval "dev_list${rootdev_nr}=\"${dev_list}\""
ac085800 390
7c38b114 391 for device in $dev_list; do
a8007847 392 find_modules_for_device $device
7c38b114
AF
393 done
394}
395
396find_modules_scsi() {
c3667d07 397 local n
7c38b114 398 for n in $PRESCSIMODS; do
07b09cf9 399 if [ "X$n" = "Xunknown" ]; then
7c38b114 400 if [ -f "$modulefile" ]; then
82474db9 401 local scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
7c38b114
AF
402 for n in $scsimodules; do
403 # for now allow scsi modules to come from anywhere. There are some
404 # RAID controllers with drivers in block
405 findmodule "$n"
406 done
407 fi
408 else
409 findmodule "$n"
410 fi
411 done
84df18b8 412 findmodule "-scsi_wait_scan"
7c38b114
AF
413}
414
415find_modules_ide() {
c3667d07
ER
416 local devpath=$1
417 # remove partition, if any
418 local disk=${devpath%[0-9]*}
f0615744 419 # set blockdev for rootfs (hda, sdc, ...)
c3667d07 420 local rootblkdev=${disk#/dev/}
ac085800 421
c3667d07 422 local n
ac085800 423 if [ "$pack_version_long" -lt "002004021" ]; then
94769f11 424 debug "Finding IDE modules for kernels <= 2.4.20"
ac085800
ER
425 for n in $PREIDEMODSOLD; do
426 findmodule "$n"
427 done
64497ebb 428 else
c3667d07 429 local tryauto=1
ac085800 430 for n in $PREIDEMODS; do
07b09cf9 431 if [ "X$n" = "Xunknown" ]; then
82474db9
ER
432 debug "Finding IDE modules using ide_hostadapter"
433 local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
434 for mod in $idemodules; do
435 tryauto=0;
436 findmodule "$mod"
437 done
64497ebb 438
ac085800
ER
439 if [ "$tryauto" -eq 1 ]; then
440 # If tryauto {{{
441 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
94769f11 442 debug "Finding IDE modules using PCI ID database"
ac085800
ER
443 # Finding IDE modules using PCI ID database {{{
444 if is_yes "${ide_only_root}"; then
f0615744
ER
445 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
446 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
447 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
ac085800 448 searchpciid="${vendorid}${deviceid}"
f0615744
ER
449 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
450 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
ac085800
ER
451 fi
452 fi
453
454 if [ -z "${searchpciid}" ]; then
455 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
456 fi
457
458 idemodules=""
459
460 for nb in $searchpciid; do
461 eval `awk -v pciid="$nb" '{
462 gsub("\t"," ");
463 gsub(" +", " ");
464 gsub("^ ","");
465 if (/^[\t ]*#/)
466 next;
467 compmod = $1 ""; # make sure comparison type will be string
468 # cause pci IDs are hexadecimal numeric
469 if (compmod == pciid) {
470 module=$2;
471 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
472 # max_kernel=$4; #
473 exit 0;
474 }
475 }
476
477 END {
478 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
479 }' /usr/share/pci-database/ide.pci`
480 [ -n "$module" ] && idemodules="$idemodules $module"
481 done
482 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
483 new_idemodules=""
484 for nc in idemodules; do
485 new_idemodules="$nc $new_idemodules"
486 done
487 idemodules="${new_idemodules}"
488 fi
489
490 if [ -z "$idemodules" ]; then
491 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
492 idemodules="ide-generic"
493 fi
494
495 # }}}
496 for nd in $idemodules; do
497 findmodule "-$nd"
498 done
499 # }}}
500 # else tryauto {{{
501 else
502 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
503 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
504 echo "Automatic IDE modules finding not available."
505 fi
506 # }}}
507 fi
508 else
509 findmodule "$n"
5de40f1f 510 fi
ac085800 511 done
64497ebb 512 fi
7c38b114
AF
513}
514
a7fce633
ER
515# return true if node is lvm node
516_check_lvm() {
517 local node="$1"
518 if [ ! -e "$node" ]; then
94769f11 519 echo >&2 "WARNING: check_lvm(): node $node doesn't exist!"
a7fce633
ER
520 return 1
521 fi
522
523 # block-major-58 is lvm1
524 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
525 rc=$?
526
527 if [ $rc = 0 ]; then
94769f11 528 debug "$node is LVM1 node"
a7fce633
ER
529 # is lvm1
530 return 0
531 fi
532
533 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
534 rc=$?
535 if [ $rc -gt 127 ]; then
536 # lvdisplay terminated by signal! most likely it segfaulted.
00eaa938 537 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
a7fce633
ER
538 fi
539
540 if [ $rc = 0 ]; then
94769f11 541 debug "$node is lvm2 node"
a7fce633 542 else
94769f11 543 debug "$node is not any lvm node"
a7fce633
ER
544 fi
545 return $rc
546}
547
07137fe3
ER
548# find dm-multipath modules for $devpath
549# returns false if $devpath is not dm-multipath
550find_modules_multipath() {
551 local devpath="$1"
552
553 # remove partition, if any
554 local disk=${devpath%p[0-9]*}
555 # need only dm name
556 local id=${disk#/dev/mapper/}
557
558 local info=$(multipath -l $id)
559 if [ -z "$info" ]; then
560 return 1
561 fi
562
563 debug "have multipath"
564 have_multipath=yes
565 local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
566 for dev in $phydevs; do
567 find_modules_for_device $dev
6b013929 568 lvm_ignore_devices="$lvm_ignore_devices $dev"
07137fe3
ER
569 done
570
571 local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
572 for hw in $hwhandlers; do
573 findmodule "dm-$hw"
574 done
575
576 local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
577 for target in $targets; do
578 findmodule "dm-$target"
579 done
580
581 findmodule "dm-mod"
582 return 0
583}
584
c083ae23
ER
585# find dmraid modules for $devpath
586# returns false if $devpath is not on dmraid
587find_modules_dmraid() {
588 local devpath="$1"
589
590 # get blockdev itself (without partition)
591 # /dev/mapper/sil_ahbgadcbchfc3 -> /dev/mapper/sil_ahbgadcbchfc
592 local blockdev=${devpath%%[0-9]*}
593 local raidname=${blockdev#/dev/mapper/}
594 local found=0
595
596 local dev phydevs=$(dmraid -r -cdevpath,raidname | awk -F, -vv="$raidname" '{if ($2 == v) print $1}')
597 for dev in $phydevs; do
598 find_modules_for_device $dev
6b013929 599 lvm_ignore_devices="$lvm_ignore_devices $dev"
c083ae23
ER
600 found=1
601 done
602
603 if [ $found = 0 ]; then
604 return 1
605 fi
606
607 # XXX probably should detect
608 findmodule "dm-mirror"
609 have_dmraid=yes
610 return 0
611}
612
bc0d6f2d 613# find modules for $devpath
a8007847 614find_modules_for_device() {
bc0d6f2d
ER
615 local devpath="$1"
616 if [ -z "$devpath" ]; then
a8007847 617 die "No argument passed to find_modules_for_device() - is your /etc/fstab correct?"
f6536797 618 fi
ac085800 619
bc0d6f2d
ER
620 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
621 case "$devpath" in
622 /dev/dm-*)
623 devpath=$(dm_longname "$devpath")
624 ;;
625 esac
9baf4f3f 626 debug "find_modules_for_device($devpath)"
bc0d6f2d 627
bc0d6f2d 628 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
07b09cf9 629 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ]; then
00eaa938 630 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
6fe19d5b 631 fi
07137fe3 632 local m
5c4cec75
AM
633 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
634 for m in $NFS_ETH_MODULES; do
ac085800 635 findmodule "$m"
6fe19d5b
AM
636 done
637 findmodule "-ipv4"
ac085800 638 findmodule "nfs"
69b1e935 639 have_nfs=yes
9baf4f3f
ER
640 echo >&2 "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
641 echo >&2 "or you will have problems like init(xx) being child process of swapper(1)."
d9179777
ER
642 return
643 fi
644
9baf4f3f 645 if [[ "$devpath" == /dev/md/* ]]; then
df738638 646 find_modules_md "$devpath"
d9179777
ER
647 return
648 fi
649
1a63b128 650 if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then
07137fe3 651 if find_modules_multipath "$devpath"; then
9baf4f3f 652 return
9baf4f3f 653 fi
9baf4f3f
ER
654 # fallback
655 fi
656
c083ae23
ER
657 if is_yes "$USE_DMRAID" && is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then
658 if find_modules_dmraid "$devpath"; then
659 return
660 fi
661 # fallback
662 fi
663
82474db9 664 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
7c38b114 665 find_modules_scsi
d9179777
ER
666 return
667 fi
668
82474db9 669 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then
bc0d6f2d 670 find_modules_ide "$devpath"
d9179777
ER
671 return
672 fi
673
07b09cf9 674 if [[ "$devpath" == /dev/rd/* ]]; then
7c38b114 675 findmodule "DAC960"
d9179777
ER
676 return
677 fi
678
07b09cf9 679 if [[ "$devpath" == /dev/ida/* ]]; then
7c38b114 680 findmodule "cpqarray"
d9179777
ER
681 return
682 fi
683
07b09cf9 684 if [[ "$devpath" == /dev/ccis/* ]]; then
7c38b114 685 findmodule "cciss"
d9179777
ER
686 return
687 fi
688
07b09cf9 689 if [[ "$devpath" == /dev/ataraid/* ]]; then
ac085800 690 find_modules_ide
7c38b114 691 findmodule "ataraid"
82474db9 692 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
9ae446b9 693 if [ -n "$ataraidmodules" ]; then
7c38b114 694 # FIXME: think about modules compiled in kernel
82474db9 695 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
7c38b114
AF
696 fi
697 for n in $ataraidmodules; do
698 findmodule "$n"
699 done
d9179777
ER
700 return
701 fi
702
7c38b114 703 # check to see if we need to set up a loopback filesystem
07b09cf9 704 if [[ "$devpath" == /dev/loop* ]]; then
00eaa938 705 die "Sorry, root on loop device isn't supported."
7c38b114
AF
706 # TODO: rewrite for bsp and make nfs ready
707 if [ ! -x /sbin/losetup ]; then
00eaa938 708 die "losetup is missing"
7c38b114 709 fi
bc0d6f2d 710 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
82474db9 711 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
bc0d6f2d 712 die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the geninitrd man page for more information"
7c38b114
AF
713 fi
714
715 line="`awk '/'$key'/ { print $0; }' $fstab`"
716 loopDev="$(echo $line | awk '{print $3}')"
717 loopFs="$(echo $line | awk '{print $4}')"
718 loopFile="$(echo $line | awk '{print $5}')"
719
720 BASICMODULES="$BASICMODULES -loop"
721 findmodule "-$loopFs"
722 BASICMODULES="$BASICMODULES -${loopFs}"
d9179777
ER
723 return
724 fi
725
726 if _check_lvm "$devpath"; then
bc0d6f2d 727 node="$devpath"
f6536797 728
07b09cf9 729 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
00eaa938 730 die "root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found. Please install lvm(2) and lvm(2)-initrd package and rerun $PROGRAM."
7c38b114 731 fi
07b09cf9 732 if [ -z "$LVMTOOLSVERSION" ]; then
ac085800 733 LVMTOOLSVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgchange: Logical Volume Manager ",NIL); gsub("LVM version: ",NIL); gsub(/\..*/,NIL); print $1}')
07b09cf9 734 if [ -z "$LVMTOOLSVERSION" ]; then
00eaa938 735 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
ac085800 736 fi
77bcfc68 737 fi
07b09cf9 738 if [ -z "$PVDEVICES" ]; then
f6536797 739 VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
d2dc16e9 740 PVDEVICES=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
decd277c 741 fi
07b09cf9 742 if [ -n "$PVDEVICES" ]; then
7c38b114 743 for device in $PVDEVICES; do
a8007847 744 find_modules_for_device $device
7c38b114
AF
745 done
746 else
00eaa938 747 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
7c38b114 748 fi
e0c502bb 749 if [ "$LVMTOOLSVERSION" = "2" ]; then
ac085800 750 findmodule "-dm-mod"
e0c502bb 751 elif [ "$LVMTOOLSVERSION" = "1" ]; then
ac085800
ER
752 findmodule "-lvm"
753 findmodule "-lvm-mod"
93d781d1 754 else
00eaa938 755 die "LVM version $LVMTOOLSVERSION is not supported yet."
93d781d1 756 fi
94769f11 757 debug "LVM $LVMTOOLSVERSION enabled"
69b1e935 758 have_lvm=yes
d9179777 759 return
7c38b114
AF
760 fi
761}
762
9ed6e1db 763firmware_install_module_pre() {
c3667d07
ER
764 local module="$1"
765 local linuxrc="$2"
766 local firmware_files="$3"
9ed6e1db 767
94769f11 768 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
034fdd5d
ER
769 inst_d /proc
770 inst_d /sys
9ed6e1db
AM
771 # firmware not yet installed
772 if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then
034fdd5d 773 inst_d /lib/firmware
9ed6e1db
AM
774cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh"
775#!/bin/sh -e
8639f99a
AM
776echo 1 > /sys$DEVPATH/loading
777cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
778echo 0 > /sys$DEVPATH/loading
779exit 0
9ed6e1db 780EOF
94769f11 781 chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh"
9ed6e1db
AM
782 fi
783
784 for firmware in $firmware_files; do
dcc1b914 785 inst /lib/firmware/$firmware /lib/firmware/$firmware
9ed6e1db
AM
786 done
787
788 echo "mount -t proc none /proc" >> "$linuxrc"
789 echo "mount -t sysfs none /sys" >> "$linuxrc"
0867ab75 790 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc"
9ed6e1db
AM
791}
792
793firmware_install_module_post() {
c3667d07
ER
794 local module="$1"
795 local linuxrc="$2"
796 local firmware_files="$3"
9ed6e1db
AM
797 echo "umount /sys" >> "$linuxrc"
798 echo "umount /proc" >> "$linuxrc"
799}
800
2a5bcca9 801modules_install() {
c3667d07
ER
802 local modules="$1"
803 local mod
2a5bcca9
AM
804
805 for mod in $modules; do
034fdd5d
ER
806 MODULEDIR=$(dirname "$mod")
807 inst_d "/lib/modules/$kernel/$MODULEDIR"
dd87738f 808 cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
ac085800 809 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
2a5bcca9
AM
810 done
811}
812
813modules_add_linuxrc() {
c3667d07
ER
814 local modules="$1"
815 local linuxrc="$2"
816 local mod
ac085800 817
2a5bcca9 818 for mod in $modules; do
87d21026 819 MODULE2="`dirname "$mod"`"
ac085800
ER
820 NAME2=`basename "$mod" .gz`
821 MODULE2=$MODULE2/$NAME2
822 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
82474db9 823 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
ffa1b198 824
9ed6e1db
AM
825 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
826 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
94769f11 827 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
2a5bcca9 828
ac085800
ER
829 if [ -n "$verbose" ]; then
830 echo -n "Loading module [$module] "
07b09cf9 831 if [ -n "$options" ]; then
ac085800
ER
832 echo -n "with options [$options]"
833 else
834 echo -n "without options"
835 fi
8e598759 836 if [ -n "$sleep_var" ]; then
ba0552ce 837 echo " and $sleep_var usleep."
8e598759
AM
838 else
839 echo "."
840 fi
ac085800
ER
841 fi
842
9ed6e1db
AM
843 if [ -n "$firmware_var" ]; then
844 firmware_install_module_pre "$module" "$linuxrc" "$firmware_var"
845 fi
ac085800 846 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
8e598759
AM
847 if [ -n "${sleep_var}" ]; then
848 echo "usleep $sleep_var" >> "$linuxrc"
849 fi
9ed6e1db
AM
850 if [ -n "$firmware_var" ]; then
851 firmware_install_module_post "$module" "$linuxrc" "$firmware_var"
852 fi
2a5bcca9
AM
853 done
854}
855
07b09cf9 856if [ -r /etc/sysconfig/geninitrd ]; then
5dc785c7 857 . /etc/sysconfig/geninitrd
858fi
859
07b09cf9 860if [ -r /etc/sysconfig/bootsplash ]; then
5b71959c
AM
861 . /etc/sysconfig/bootsplash
862fi
863
07b09cf9 864if [ -r /etc/sysconfig/fbsplash ]; then
e4b07ddc 865 . /etc/sysconfig/fbsplash
866fi
867
07b09cf9 868if [ ! -x /bin/initrd-busybox ]; then
00eaa938 869 die "/bin/initrd-busybox is missing!"
5dc785c7 870fi
901afd79 871
7591cd37 872# backwards compatible
07b09cf9 873if [ "$USE_SUSPEND2" ]; then
7591cd37
ER
874 USE_TUXONICE=$USE_SUSPEND2
875 echo >&2 "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
876fi
877
bb529f94 878while [ $# -gt 0 ]; do
413878f8 879 case $1 in
6bd433bc 880 --fstab=*)
c3667d07 881 fstab=${1#--fstab=}
6bd433bc
AF
882 ;;
883 --fstab)
c3667d07 884 fstab=$2
6bd433bc 885 shift
413878f8 886 ;;
cd670d83 887 --modules-conf=*)
c3667d07 888 modulefile=${1#--modules-conf=}
cd670d83 889 ;;
57188d60 890 --modules-conf)
c3667d07 891 modulefile=$2
cd670d83
AF
892 shift
893 ;;
6bd433bc 894 --use-raidstart|--with-raidstart)
c3667d07 895 USERAIDSTART=yes
6bd433bc
AF
896 ;;
897 --without-raidstart)
c3667d07 898 USERAIDSTART=no
6bd433bc 899 ;;
57227e0a 900 --use-insmod-static|--with-insmod-static)
c3667d07 901 USEINSMODSTATIC=yes
57227e0a
AF
902 ;;
903 --without-insmod-static)
c3667d07 904 USEINSMODSTATIC=no
57227e0a 905 ;;
ba5d09f0 906 --with-bootsplash)
c3667d07 907 BOOT_SPLASH=yes
ba5d09f0 908 ;;
5b71959c 909 --without-bootsplash)
c3667d07 910 BOOT_SPLASH=no
5b71959c 911 ;;
ba5d09f0 912 --with-fbsplash)
c3667d07 913 FB_SPLASH=yes
ba5d09f0 914 ;;
e4b07ddc 915 --without-fbsplash)
c3667d07 916 FB_SPLASH=no
e4b07ddc 917 ;;
ba5d09f0 918 --with-suspend)
c3667d07 919 USE_SUSPEND=yes
ba5d09f0 920 ;;
4ef98747 921 --without-suspend)
c3667d07 922 USE_SUSPEND=no
ba5d09f0 923 ;;
1cd2aabd 924 --with-suspend2 | --with-tuxonice)
c3667d07 925 USE_TUXONICE=yes
22b0c9f4 926 ;;
1cd2aabd 927 --without-suspend2 | --without-tuxonice)
c3667d07 928 USE_TUXONICE=no
2c52f208 929 ;;
e0c502bb
AM
930 --lvmtoolsversion=|--lvmversion=)
931 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
77bcfc68 932 ;;
e0c502bb 933 --lvmtoolsversion|--lvmversion)
c3667d07 934 LVMTOOLSVERSION=$2
77bcfc68
AF
935 shift
936 ;;
1606e343 937 --without-udev)
c3667d07 938 USE_UDEV=no
1606e343 939 ;;
d7d5530e 940 --with-udev)
c3667d07 941 USE_UDEV=yes
d7d5530e 942 ;;
882472ae 943 --without-dmraid)
c3667d07 944 USE_DMRAID=no
882472ae 945 ;;
2cc3ae8b 946 --without-multipath)
c3667d07 947 USE_MULTPATH=no
2cc3ae8b 948 ;;
6bd433bc 949 --with=*)
c3667d07 950 BASICMODULES="$BASICMODULES ${1#--with=}"
6bd433bc
AF
951 ;;
952 --with)
953 BASICMODULES="$BASICMODULES $2"
954 shift
413878f8 955 ;;
bb529f94 956 --version)
9e1ceabe 957 echo "$PROGRAM: version $VERSION"
413878f8 958 exit 0
959 ;;
bb529f94 960 -v)
413878f8 961 verbose=-v
962 ;;
bb529f94 963 --nocompress)
c3667d07 964 COMPRESS=no
413878f8 965 ;;
bb529f94 966 --ifneeded)
413878f8 967 ifneeded=1
968 ;;
bb529f94 969 -f)
413878f8 970 force=1
971 ;;
6bd433bc 972 --preload=*)
c3667d07 973 PREMODS="$PREMODS ${1#--preload=}"
6bd433bc
AF
974 ;;
975 --preload)
72623c13 976 PREMODS="$PREMODS $2"
6bd433bc 977 shift
413878f8 978 ;;
2ad94d8a 979 --fs=*)
94769f11 980 echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead"
c3667d07 981 INITRDFS=${1#--fs=}
2ad94d8a 982 ;;
2ad94d8a 983 --fs)
94769f11 984 echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead"
c3667d07 985 INITRDFS=$2
2ad94d8a 986 shift
cd670d83 987 ;;
6bd433bc 988 --initrdfs=*)
c3667d07 989 INITRDFS=${1#--initrdfs=}
6bd433bc 990 ;;
fd2dc249 991 --initrdfs)
c3667d07 992 INITRDFS=$2
413878f8 993 shift
994 ;;
bb529f94 995 --image-version)
413878f8 996 img_vers=yes
997 ;;
4f4e832d
AM
998 --ide-only-root)
999 ide_only_root="yes"
1000 ;;
bb529f94 1001 *)
413878f8 1002 if [ -z "$target" ]; then
1003 target="$1"
1004 elif [ -z "$kernel" ]; then
1005 kernel="$1"
1006 else
1007 usage
1008 fi
1009 ;;
1010 esac
1011
1012 shift
bb529f94
JK
1013done
1014
06ac05d6 1015if [ -z "$target" -o -z "$kernel" ]; then
413878f8 1016 usage
06ac05d6
AF
1017fi
1018
0868f49f 1019pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
64497ebb 1020pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
0868f49f 1021
07b09cf9
ER
1022if [ "x" = "x$INITRDFS" ]; then
1023 if [ "x" = "x$FS" ]; then
48413b7f 1024 # default value
07b09cf9 1025 if [ "$pack_version" -ge "002005" ]; then
8d6cdf87 1026 INITRDFS="initramfs"
1027 else
ac085800 1028 INITRDFS="rom"
8d6cdf87 1029 fi
48413b7f 1030 else
94769f11 1031 echo >&2 "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
48413b7f
AM
1032 INITRDFS="$FS"
1033 fi
1034fi
1035
07b09cf9 1036if [ "$pack_version" -lt "002006" ]; then
c3667d07
ER
1037 USE_UDEV=no
1038 USE_DMRAID=no
1606e343 1039fi
ac085800 1040
07b09cf9 1041if [ "$pack_version" -ge "002005" ]; then
0868f49f 1042 modext=".ko"
0b6536f5 1043 insmod="insmod"
0868f49f
AF
1044fi
1045
82474db9 1046if is_yes "$USEINSMODSTATIC"; then
57227e0a 1047 insmod="insmod.static"
b2e62ae1 1048 INSMOD="/sbin/insmod.static"
07b09cf9 1049 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
f7c18703 1050 INSMOD="/sbin/insmod.static.modutils"
b2e62ae1 1051 fi
07b09cf9 1052 if [ ! -f "$INSMOD" ]; then
00eaa938 1053 die "insmod.static requested but /sbin/insmod.static not found!"
b2e62ae1 1054 fi
57227e0a
AF
1055fi
1056
2ad94d8a 1057case "$INITRDFS" in
8b1e4ac7 1058 ext2)
f5d71bb2 1059 if [ ! -x /sbin/mke2fs ]; then
00eaa938 1060 die "/sbin/mke2fs is missing"
8b1e4ac7
AF
1061 fi
1062 ;;
1063 rom)
1064 if [ ! -x /sbin/genromfs ]; then
00eaa938 1065 die "/sbin/genromfs is missing"
8b1e4ac7
AF
1066 fi
1067 ;;
1068 cram)
1069 if [ ! -x /sbin/mkcramfs ]; then
00eaa938 1070 die "/sbin/mkcramfs is missing"
8b1e4ac7 1071 fi
c31050f3 1072 ;;
48413b7f
AM
1073 initramfs)
1074 if [ ! -x /bin/cpio ]; then
00eaa938 1075 die "/bin/cpio is missing"
48413b7f
AM
1076 fi
1077 if [ ! -x /usr/bin/find ]; then
00eaa938 1078 die "/usr/bin/find is missing"
48413b7f
AM
1079 fi
1080 ;;
8b1e4ac7 1081 *)
00eaa938 1082 die "Filesystem $INITRDFS on initrd is not supported"
8b1e4ac7
AF
1083 ;;
1084esac
bb529f94 1085
bb529f94 1086if [ -n "$img_vers" ]; then
413878f8 1087 target="$target-$kernel"
bb529f94
JK
1088fi
1089
35164381 1090if [ -z "$force" -a -f "$target" ]; then
00eaa938 1091 die "$target already exists."
bb529f94
JK
1092fi
1093
35164381 1094if [ ! -d "/lib/modules/$kernel" ]; then
00eaa938 1095 die "/lib/modules/$kernel is not a directory."
bb529f94
JK
1096fi
1097
1cd2aabd
ER
1098if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1099 die "Tuxonice shouldn't be used in parallel with mainline suspend!."
22b0c9f4
AM
1100fi
1101
e4b07ddc 1102if is_yes "$FB_SPLASH"; then
1103 if is_yes "$BOOT_SPLASH"; then
00eaa938 1104 die "You can't use both bootsplash and fbsplash! Please choose one."
e4b07ddc 1105 elif [ "$INITRDFS" != "initramfs" ]; then
00eaa938 1106 die "FB_SPLASH works only if INITRDFS is initramfs!."
e4b07ddc 1107 fi
1108fi
1109
48762878 1110if [ ! -f /proc/mounts ]; then
94769f11 1111 echo >&2 "WARNING: /proc filesystem not mounted, may cause wrong results or failure."
48762878 1112fi
f121024f 1113
82474db9 1114cache_modprobe_conf
ac085800 1115
bb529f94 1116for n in $PREMODS; do
35164381 1117 findmodule "$n"
bb529f94
JK
1118done
1119
7c38b114 1120# allow forcing loading SCSI and/or IDE modules
82474db9 1121if is_yes "$ADDSCSI"; then
7c38b114 1122 find_modules_scsi
bb529f94
JK
1123fi
1124
82474db9 1125if is_yes "$ADDIDE"; then
7c38b114 1126 find_modules_ide
cd670d83
AF
1127fi
1128
1cea325b
ER
1129find_root "$fstab" || exit
1130debug "Using $rootdev as device for rootfs"
1131
a8007847
ER
1132find_modules_for_device "$rootdev"
1133[ -n "$rootdev_add" ] && find_modules_for_device "$rootdev_add"
cd670d83 1134
7c38b114 1135findmodule "-$rootFs"
bb529f94 1136
c31050f3 1137for n in $BASICMODULES; do
7d2fc5eb 1138 findmodule "$n"
bb529f94
JK
1139done
1140
1cd2aabd 1141if is_yes "$USE_TUXONICE"; then
335cd101
JR
1142 findmodule "-lzf"
1143fi
1144
e4b07ddc 1145if is_yes "$FB_SPLASH"; then
1146 findmodule "-evdev"
1147fi
2cc3ae8b 1148
bb529f94 1149if [ -n "$ifneeded" -a -z "$MODULES" ]; then
94769f11 1150 debug "No modules are needed -- not building initrd image."
7d2fc5eb 1151 exit 0
bb529f94 1152fi
94769f11 1153debug "Using modules: $MODULES"
bb529f94 1154
35164381
SZ
1155MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
1156IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
1157MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
1158RCFILE="$MNTIMAGE/linuxrc"
bb529f94 1159
35164381 1160if [ -f "$MNTIMAGE" ]; then
00eaa938 1161 die "$MNTIMAGE already exists. Remove it and try again"
bb529f94
JK
1162fi
1163
35164381 1164if [ -f "$IMAGE" ]; then
00eaa938 1165 die "$IMAGE already exists. Remove it and try again"
bb529f94
JK
1166fi
1167
73edc0c1 1168mkdir -p "$MNTPOINT"
bb529f94 1169# We don't need this directory, so let's save space
35164381 1170rm -rf "$MNTPOINT"/lost+found
bb529f94 1171
034fdd5d
ER
1172inst_d /{lib,bin,etc,dev,loopfs,var}
1173
2a5bcca9 1174modules_install "$MODULES"
bb529f94
JK
1175
1176# mknod'ing the devices instead of copying them works both with and
1177# without devfs...
35164381 1178mknod "$MNTIMAGE/dev/console" c 5 1
eb6e37ff
MM
1179mknod "$MNTIMAGE/dev/null" c 1 3
1180mknod "$MNTIMAGE/dev/zero" c 1 5
034fdd5d 1181inst_d /dev/pts /dev/shm
bb529f94 1182
84670990 1183s="$RCFILE"
566ad08b 1184ln -s /linuxrc $MNTIMAGE/init
ef66f232 1185
dcc1b914 1186inst /bin/initrd-busybox /bin/initrd-busybox
dab92b1d
ER
1187ln -s initrd-busybox $MNTIMAGE/bin/sh
1188ln -s initrd-busybox $MNTIMAGE/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
ef66f232 1189
1775ba37
ER
1190if is_yes "$USEINSMODSTATIC"; then
1191 inst "$INSMOD" /bin/insmod.static
57227e0a
AF
1192fi
1193
f116bd42 1194cat > "$s" <<'EOF'
84670990 1195#! /bin/sh
f116bd42 1196mount -t proc none /proc
c3e2550c
AM
1197if [ "$(awk ' /debuginitrd/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1198 export DEBUG=yes
1199 set -x
1200fi
1201umount /proc
84670990
MM
1202EOF
1203chmod 755 "$s"
c31050f3 1204
2a5bcca9 1205modules_add_linuxrc "$MODULES" "$s"
fd2dc249 1206
4e9eb79c 1207# TODO: rewrite for busybox
fd2dc249
AF
1208#if [ -n "$loopDev" ]; then
1209# if [ ! -d /initrd ]; then
1210# mkdir /initrd
1211# fi
1212#
1213# cp -a "$loopDev" "$MNTIMAGE/dev"
738c05d8 1214# cp -a "$rootdev" "$MNTIMAGE/dev"
fd2dc249
AF
1215# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1216# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
738c05d8
ER
1217# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1218# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
fd2dc249 1219#fi
bb529f94 1220
22b0c9f4
AM
1221initrd_gen_suspend() {
1222 if [ ! -x /usr/sbin/resume ]; then
00eaa938 1223 die "/usr/sbin/resume is missing!"
22b0c9f4 1224 fi
034fdd5d 1225 inst_d /etc /dev
22b0c9f4 1226 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1775ba37
ER
1227 inst /dev/snapshot /dev
1228 inst $resume_dev /dev
1229 inst /etc/suspend.conf /etc/suspend.conf
dcc1b914 1230 inst /usr/sbin/resume /bin/resume
22b0c9f4
AM
1231 echo "resume" >> "$s"
1232}
1233
1cd2aabd 1234initrd_gen_tuxonice() {
034fdd5d 1235 inst_d /sys /proc
5a61a17c 1236cat << 'EOF' >> "$s"
2b1a3707 1237mount -t proc none /proc
050198fa 1238mount -t sysfs none /sys
5a61a17c 1239if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
2b1a3707 1240EOF
2b1a3707 1241cat << EOF >> "$s"
050198fa 1242 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1243 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
5b26c57b 1244 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
2b1a3707 1245fi
050198fa 1246umount /sys
2b1a3707
AM
1247umount /proc
1248EOF
2df2e995 1249}
2c52f208 1250
7915c8b1 1251# generate code to mount /dev on tmpfs and create initial nodes
4ca8a6c5
ER
1252# can be called multiple times. /dev is cleaned up (umounted) automatically at
1253# the end of script.
b4d9d384 1254initrd_gen_tmpfs_dev() {
dd856379
AG
1255 if [ "$INITRDFS" = "initramfs" ]; then
1256 # initramfs is read-write filesystem, no need for tmpfs
1257 return
1258 fi
7915c8b1
ER
1259
1260 # we already generated tmpfs code; return
1261 if is_yes "$tmpfs_dev"; then
1262 return
1263 fi
1264
b4d9d384 1265 tmpfs_dev=yes
9299682f
ER
1266
1267 busybox_applet mount mknod mkdir
d07b92a4 1268 cat >> "$s" <<-EOF
b4d9d384
ER
1269: 'Creating /dev'
1270mount -o mode=0755 -t tmpfs none /dev
1271mknod /dev/console c 5 1
1272mknod /dev/null c 1 3
1273mknod /dev/zero c 1 5
1274mkdir /dev/pts
1275mkdir /dev/shm
1276EOF
1277}
1278
1606e343 1279initrd_gen_udev() {
94769f11 1280 debug "Setting up udev..."
034fdd5d 1281 inst_d /sbin /proc /etc/udev /sys
ac085800 1282
9299682f 1283 if [ ! -x /sbin/initrd-udevd ]; then
00eaa938 1284 die "/sbin/initrd-udevd not present"
9299682f
ER
1285 fi
1286
1775ba37
ER
1287 inst /sbin/initrd-udevd /sbin/udevd
1288 inst /etc/udev/udev.conf /etc/udev/udev.conf
1606e343 1289
1606e343 1290 if is_yes "$USE_UDEV"; then
d07b92a4 1291 initrd_gen_tmpfs_dev
e4b07ddc 1292 cat >> "$s" <<- 'EOF'
1293 mount -t proc none /proc
1294 mount -t sysfs none /sys
1295 : 'Starting udev'
fdc8f895 1296 /sbin/udevd --daemon
7915c8b1 1297 EOF
e4b07ddc 1298 if is_yes "$PROBESTATICMODS"; then
1775ba37
ER
1299 inst /sbin/initrd-udevtrigger /sbin/udevtrigger
1300 inst /sbin/initrd-udevsettle /sbin/udevsettle
7915c8b1 1301 cat >> "$s" <<-'EOF'
e4b07ddc 1302 /sbin/udevtrigger
1303 /sbin/udevsettle
7915c8b1 1304 EOF
e4b07ddc 1305 fi
9299682f
ER
1306
1307 busybox_applet killall
1308 cat >> "$s" <<-'EOF'
93f2f7c3 1309 killall udevd
e4b07ddc 1310 umount /proc
1311 umount /sys
7915c8b1 1312 EOF
1606e343
AM
1313 fi
1314}
1315
2cc3ae8b 1316initrd_gen_multipath() {
2cc3ae8b
ER
1317 inst_d /proc /sys /sbin /lib/udev
1318# inst /sbin/multipathd /sbin
1319 inst /sbin/kpartx /sbin
1320# inst /bin/mountpoint /bin
1321# inst /sbin/devmap_name /sbin
1322 inst /sbin/multipath /sbin
1323 # for udev callouts
1324 inst /sbin/scsi_id /lib/udev
1325 for a in /sbin/mpath*; do
1326 inst $a /sbin
1327 done
1328
1329 if [ -d /lib64 ]; then
1330 lib=/lib64
1331 else
1332 lib=/lib
1333 fi
1334 inst_d $lib
1335 inst /lib64/ld-linux-x86-64.so.2 $lib
aabf157c 1336 for a in $(ldd /sbin/kpartx /sbin/multipath | grep -v linux-gate.so | sort -u | awk '{print $3}'); do
2cc3ae8b
ER
1337 inst $a $lib
1338 done
aabf157c 1339 for a in $(ldd $MNTIMAGE$lib/lib* | grep -v linux-gate.so | sort -u | awk '{print $3}'); do
2cc3ae8b
ER
1340 inst $a $lib
1341 done
1342
1343 cat <<-'EOF' >> "$s"
1344 mount -t proc none /proc
1345 mount -t sysfs none /sys
1346EOF
1347
1348 initrd_gen_tmpfs_dev
1349 initrd_gen_devices
1350
1351 cat <<-'EOF' >> "$s"
1352 /sbin/multipath -v 0
1353
1354 for a in /dev/mapper/*; do
1355 [ $a = /dev/mapper/control ] && continue
1356 kpartx -a $a
1357 done
2cc3ae8b
ER
1358
1359 umount /sys
1360 umount /proc
1361EOF
1362}
1363
882472ae 1364initrd_gen_dmraid() {
07b09cf9 1365 if [ ! -x /sbin/dmraid-initrd ]; then
6b013929 1366 die "/sbin/dmraid-initrd is missing!"
ac085800
ER
1367 fi
1368
661cd523 1369 # always make /dev on tmpfs
7915c8b1 1370 initrd_gen_tmpfs_dev
ac085800 1371
034fdd5d 1372 inst_d /sbin /sys
1775ba37 1373 inst /sbin/dmraid-initrd /sbin/dmraid
9bb6d02a 1374 cat <<-EOF >> "$s"
882472ae
ER
1375 mount -t proc none /proc
1376 mount -t sysfs none /sys
2ffb1734
ER
1377EOF
1378
1379 initrd_gen_devices
1380
1381 cat <<-EOF >> "$s"
882472ae
ER
1382 # 2 secs was enough for my system to initialize. but really this is udev issue?
1383 usleep 2000000
e5d02b56 1384 : 'Activating Device-Mapper RAID(s)'
882472ae
ER
1385 /sbin/dmraid -ay -i
1386 umount /sys
1387 umount /proc
1388EOF
1389}
1390
8bd582f1
ER
1391# Generates /dev nodes based on /proc/partitions information.
1392# Needs /proc mounted.
1393# Can be called multiple times.
2ffb1734 1394initrd_gen_devices() {
8bd582f1
ER
1395 if is_yes "$proc_partitions"; then
1396 return
1397 fi
1398 proc_partitions=yes
1399
06ae4e5a 1400 cat <<-'EOF' >> "$s"
2ffb1734
ER
1401 : 'Making device nodes'
1402 # ignore first two lines, header, empty line and process rest
1403 cat /proc/partitions | (read b; read b; while read major minor blocks dev rest; do
06ae4e5a
ER
1404 node=/dev/$dev
1405 mkdir -p ${node%/*}
1406 mknod $node b $major $minor
2ffb1734
ER
1407 done
1408 )
1409EOF
1410}
1411
df738638 1412initrd_gen_md() {
94769f11 1413 debug "Setting up mdadm..."
ac085800 1414
00eaa938
ER
1415 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1416 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
d3fa6ec7 1417 fi
994eb509 1418
dcc1b914 1419 inst /sbin/initrd-mdassemble /bin/mdassemble
6cca3165 1420
4e9eb79c 1421 # LVM on RAID case
6cca3165
AM
1422 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1423 for ex_dev in $dev_list_extra; do
1424 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1425 done
ac085800 1426 do_md0=1
4e9eb79c 1427 for nr in `seq 1 $rootdev_nr`; do
ac085800
ER
1428 eval cr_rootdev="\$rootdev${nr}"
1429 eval cr_dev_list="\$dev_list${nr}"
94769f11 1430 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
ac085800
ER
1431
1432 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1433
1434 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1435 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
a46f8bda 1436 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
ac085800
ER
1437 if [ -n "$cr_md_conf" ]; then
1438 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1439 else
1440 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1441 fi
1442
1443 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1444 # mkdir in case of devfs name
034fdd5d 1445 inst_d $(dirname $f)
ac085800 1446 [ -e "$MNTIMAGE/$f" ] && continue
ac085800 1447 # this works fine with and without devfs
1775ba37 1448 inst $f $f
ac085800 1449 done
ef66f232 1450 done
4e9eb79c 1451
6cca3165 1452 echo "mdassemble" >> "$s"
33d24e12 1453
4e9eb79c 1454 # needed to determine md-version
07b09cf9 1455 if [ "$do_md0" -eq 1 ]; then
4e9eb79c
AM
1456 mknod $MNTIMAGE/dev/md0 b 9 0
1457 fi
2df2e995 1458}
2968c9dd 1459
2df2e995 1460initrd_gen_nfs() {
5a61a17c 1461 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
51447ab3 1462 # have problems like init(XX) being child process of swapper(1).
94769f11 1463 debug "Adding rootfs on NFS support to initrd (dhcp)"
7fc1e5bd 1464 mknod "$MNTIMAGE/dev/urandom" c 1 9
5c4cec75 1465 mkdir "$MNTIMAGE/newroot"
7d400dbe 1466 mkdir "$MNTIMAGE/proc"
5c4cec75
AM
1467 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1468 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1469 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
ac085800 1470 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
5a61a17c 1471 cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
5c4cec75 1472#!/bin/sh
5a61a17c
ER
1473[ "$1" != "bound" ] && exit
1474[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1475[ -n "$subnet" ] && NETMASK="netmask $subnet"
5a61a17c 1476ifconfig $interface $ip $BROADCAST $NETMASK up
5a61a17c 1477if [ -n "$router" ]; then
ac085800 1478 for r in $router; do
ac085800 1479 route add default gw $r dev $interface
ac085800 1480 done
5c4cec75 1481fi
7d400dbe
ER
1482
1483mount -t proc none /proc
5a61a17c
ER
1484for o in $(cat /proc/cmdline); do
1485 case $o in
7d400dbe 1486 nfsroot=*)
5a61a17c 1487 rootpath=${o#nfsroot=}
7d400dbe
ER
1488 ;;
1489 esac
1490done
1491umount /proc
1492
5a61a17c 1493if [ -n "$rootpath" ]; then
ac085800 1494 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
5c4cec75 1495else
ac085800
ER
1496 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1497 echo "All seen variables are listed below:"
1498 set
5c4cec75
AM
1499fi
1500EOF
1501 chmod 755 "$MNTIMAGE/bin/setdhcp"
1502 echo "cd /newroot" >> "$s"
c52ba2fe 1503 echo "pivot_root . initrd" >> "$s"
d4a8e40e 1504 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
c52ba2fe 1505 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
2df2e995 1506}
6fe19d5b 1507
2df2e995 1508initrd_gen_lvm() {
94769f11 1509 debug "Adding LVM support to initrd"
1775ba37 1510 inst /sbin/initrd-lvm /bin/lvm
034fdd5d 1511 inst_d /etc /tmp /proc /newroot
e8d178ff
ER
1512
1513 # always make /dev on tmpfs for LVM2
7915c8b1 1514 if [ "$LVMTOOLSVERSION" = "2" ]; then
d07b92a4 1515 initrd_gen_tmpfs_dev
e8d178ff
ER
1516 fi
1517
b4d9d384 1518 if ! is_yes "$tmpfs_dev"; then
034fdd5d 1519 inst_d /dev/mapper
afaefcb5 1520 mknod $MNTIMAGE/dev/mapper/control c 10 63
b007399c 1521 for device in $PVDEVICES; do
df738638 1522 # if LVM on RAID then device might be copied already in gen_md
13b29c8f 1523 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1775ba37 1524 inst $device /dev
b007399c 1525 done
afaefcb5 1526 fi
84670990 1527 echo "mount -t proc none /proc" >> "$s"
b78e6497 1528 echo "mount -t tmpfs none /tmp" >> "$s"
07b09cf9 1529 if [ "$LVMTOOLSVERSION" = "1" ]; then
cff3058d 1530 echo "lvm vgscan -T" >> "$s"
90b5b05a 1531 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
4e1e40bd 1532 echo "umount /tmp" >> "$s"
ac085800 1533 # fail to umount
ac085800 1534 echo "umount /proc" >> "$s"
cff3058d 1535 else
ac085800
ER
1536 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1537 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
f34c76a3
AM
1538 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1539 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1540 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
ac085800 1541 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
8fb0a4d2 1542 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
df738638 1543 if is_yes "$have_md"; then
ac085800 1544 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
f34c76a3 1545 fi
c083ae23 1546 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
3938fd10 1547 echo ' types = [ "device-mapper", 254 ]' >> "$MNTIMAGE/etc/lvm.conf"
2cc3ae8b 1548 fi
6b013929
ER
1549 if [ "$lvm_ignore_devices" ]; then
1550 # TODO: think of merging with lvm dumpconfig output
2cc3ae8b 1551 echo ' filter = [' >> "$MNTIMAGE/etc/lvm.conf"
6b013929
ER
1552 local dev
1553 for dev in $lvm_ignore_devices; do
1554 debug "LVM2: ignore device $dev"
2cc3ae8b
ER
1555 printf ' "r|^%s.*|",\n' $dev
1556 done >> "$MNTIMAGE/etc/lvm.conf"
1557 echo ']' >> "$MNTIMAGE/etc/lvm.conf"
3938fd10 1558 fi
6b013929 1559 # XXX filter= must be on one line!
f34c76a3
AM
1560 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1561 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
be2f3ecc 1562
2ffb1734
ER
1563 initrd_gen_devices
1564
c79b26a6 1565 cat <<-EOF >> "$s"
e8d178ff 1566
dd87738f
ER
1567 # disable noise from lvm accessing devices that aren't ready.
1568 printk=\$(cat /proc/sys/kernel/printk)
e8d178ff 1569 echo 0 > /proc/sys/kernel/printk
dd87738f 1570
2cc3ae8b 1571 export LVM_SYSTEM_DIR=/tmp
dd87738f 1572 : 'Scanning for Volume Groups'
2cc3ae8b 1573 lvm vgscan --mknodes --ignorelockingfailure 2>/dev/null
e8d178ff 1574
c79b26a6 1575 : 'Activating Volume Groups'
2cc3ae8b 1576 lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
be2f3ecc 1577
dd87738f
ER
1578 echo "\$printk" > /proc/sys/kernel/printk
1579
91ed0242 1580 # Find out major/minor
2cc3ae8b 1581 majmin="\$(lvm lvdisplay --ignorelockingfailure -c $rootdev 2>/dev/null)"
c79b26a6
ER
1582 majmin="\${majmin#*/}"
1583 majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
1584 major="\${majmin%:*}"
1585 minor="\${majmin#*:}"
91ed0242 1586 # Pass it to kernel
c79b26a6
ER
1587 val=\$((256 * \$major + \$minor))
1588 echo \$val > /proc/sys/kernel/real-root-dev
1589 umount /tmp
1590 umount /proc
1591EOF
cff3058d 1592 fi
2df2e995
AM
1593}
1594
2b1a3707 1595initrd_gen_procdata() {
94769f11 1596 debug "Adding rootfs finding based on root= option support."
034fdd5d 1597 inst_d /proc
5a61a17c 1598cat << 'EOF' >> "$s"
2b1a3707 1599mount -t proc none /proc
5a61a17c
ER
1600root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
1601if [ -n "$root" ]; then
ac085800
ER
1602 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1603 if [ -n "$rootnr" ]; then
1604 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1605 fi
2b1a3707 1606fi
9d949203 1607umount /proc
2b1a3707
AM
1608EOF
1609}
1610
2df2e995 1611# main generation
1606e343
AM
1612
1613if is_yes "$USE_UDEV"; then
1614 initrd_gen_udev
1615fi
1616
2ce7656a 1617if is_yes "$USE_SUSPEND"; then
22b0c9f4
AM
1618 initrd_gen_suspend
1619fi
1620
1cd2aabd
ER
1621if is_yes "$USE_TUXONICE"; then
1622 initrd_gen_tuxonice
2df2e995
AM
1623fi
1624
c083ae23 1625if is_yes "$have_dmraid" ]; then
882472ae
ER
1626 initrd_gen_dmraid
1627fi
1628
c083ae23 1629if is_yes "$have_multipath"; then
2cc3ae8b
ER
1630 initrd_gen_multipath
1631fi
1632
69b1e935 1633if is_yes "$have_nfs"; then
2df2e995 1634 initrd_gen_nfs
df738638
ER
1635elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1636 initrd_gen_md
69b1e935 1637 if is_yes "$have_lvm"; then
2df2e995 1638 initrd_gen_lvm
bfea009a
AM
1639 else
1640 initrd_gen_procdata
2df2e995 1641 fi
69b1e935 1642elif is_yes "$have_lvm"; then
2df2e995 1643 initrd_gen_lvm
2b1a3707
AM
1644else
1645 initrd_gen_procdata
7c38b114
AF
1646fi
1647
737d5a0e 1648# finally umount /dev if it was on tmpfs
661cd523
ER
1649if is_yes "$tmpfs_dev"; then
1650 cat <<-EOF >> "$s"
1651 umount /dev
1652EOF
1653 tmpfs_dev=no
1654fi
1655
5101a385 1656# additional devs always needed
1775ba37 1657[ ! -e "$MNTIMAGE/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1658
f8f9e56d 1659if [ "$INITRDFS" = "initramfs" ]; then
034fdd5d 1660 inst_d /newroot
1775ba37 1661 [ ! -e "$MNTIMAGE/$rootdev" ] && inst $rootdev /dev
e4b07ddc 1662 # Parsing root parameter
81d53704 1663 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
e4b07ddc 1664 cat << 'EOF' >> "$s"
e4b07ddc 1665mount -t proc none /proc
df391e6f 1666
1667CMDLINE="$(busybox cat /proc/cmdline)"
1668eval "$(busybox awk -v c="$CMDLINE" '
1669BEGIN {
92ed99b6 1670 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1671 num_pattern = "[0-9a-f]" num_pattern_short;
df391e6f 1672 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1673 partition = "no_partition_found";
1674 min = -1; maj = -1;
1675
1676 gsub(/.*root=/,NIL,c);
1677 gsub(/ .*/,NIL,c);
1678
1679 sub("^0x", "", c);
1680 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1681 if (c ~ "^" num_pattern "$") {
92ed99b6 1682 maj = sprintf("%s",substr(c,1,2));
1683 min = sprintf("%s",substr(c,3));
df391e6f 1684 }
1685 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1686 if (c ~ "^" dev_pattern "$") partition = c;
1687}
1688
1689$4 ~ partition { maj = $1; min = $2; }
1690$1 ~ maj && $2 ~ min { partition = $4; }
1691
1692END {
92ed99b6 1693 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
df391e6f 1694 partition, maj, min);
1695}
1696' /proc/partitions)"
e620b426 1697if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
e4b07ddc 1698 mknod $device b $maj $min
1699fi
1700EOF
92a4990b
ER
1701
1702 busybox_applet switch_root
e4b07ddc 1703 cat << EOF >> "$s"
07b09cf9 1704if [ "\$device" = '/dev/no_partition_found' ]; then
e620b426
AG
1705 device="$rootdev"
1706fi
1707
51dc11ca 1708mount -t $rootFs -r \$device /newroot
a020063b 1709init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline )"
1710if [ -z "\$init" -o ! -x "/newroot\$init" ]; then
1711 init=/sbin/init
1712fi
e4b07ddc 1713umount /proc
a020063b 1714exec switch_root /newroot \$init
f1a5a1b0 1715
1716echo "Error ! initramfs should not reach this place."
1717echo "It probably means you've got old version of busybox, with broken"
1718echo "initramfs support. Trying to boot anyway, but won't promise anything."
1719
1720exec chroot /newroot \$init
1721
1722echo "Failed to chroot !"
e4b07ddc 1723EOF
f8f9e56d
AM
1724 # we need real file, not symlink
1725 rm -f $MNTIMAGE/init
1726 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1727fi
1728
35164381 1729chmod +x "$RCFILE"
bb529f94 1730
35164381 1731(cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
bb529f94 1732
2ad94d8a 1733case "$INITRDFS" in
8b1e4ac7 1734 ext2)
94d430a8 1735 IMAGESIZE=$(du -ks $MNTPOINT | awk '{print int(($1+1023+512)/1024)*1024}')
94769f11 1736 debug "ext2 image size: $IMAGESIZE ($MNTPOINT)"
73edc0c1 1737 if [ "$IMAGESIZE" -gt 4096 ]; then
7758e45c 1738 echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
73edc0c1
ER
1739 fi
1740
1741 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1742 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1743 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1744
1745 tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`"
1746 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1747
1748 (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -)
1749
35164381 1750 umount "$IMAGE"
8b1e4ac7
AF
1751 ;;
1752 rom)
1753 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
cdf1e7c9 1754 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
a8b63949
ER
1755 debug "romfs image size: $IMAGESIZE ($IMAGE)"
1756 if [ "$IMAGESIZE" -gt 4096 ]; then
7758e45c 1757 echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
a8b63949 1758 fi
8b1e4ac7
AF
1759 ;;
1760 cram)
1761 mkcramfs "$MNTPOINT" "$IMAGE"
8b1e4ac7 1762 ;;
48413b7f 1763 initramfs)
82474db9 1764 (cd $MNTPOINT; find . | cpio --quiet -H newc -o > "$IMAGE")
48413b7f 1765 ;;
8b1e4ac7 1766 *)
7758e45c 1767 echo "Filesystem $INITRDFS not supported by $PROGRAM";
c31050f3 1768esac
bb529f94 1769
82474db9 1770if is_yes "$COMPRESS"; then
7d2fc5eb 1771 gzip -9 < "$IMAGE" > "$target"
bb529f94 1772else
7d2fc5eb 1773 cp -a "$IMAGE" "$target"
bb529f94 1774fi
5b71959c
AM
1775
1776if is_yes "$BOOT_SPLASH"; then
1777 if [ ! -x /bin/splash.bin ]; then
94769f11 1778 echo >&2 "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
5b71959c 1779 elif [ -z "$THEME" ]; then
94769f11
ER
1780 echo >&2 "Please configure your /etc/sysconfig/bootsplash first."
1781 echo >&2 "Generating bootsplashes skipped."
5b71959c 1782 else
ac085800
ER
1783 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1784 for res in $BOOT_SPLASH_RESOLUTIONS; do
1785 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1786 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
94769f11 1787 debug "Added $res $THEME theme to initrd."
ac085800 1788 else
94769f11 1789 echo >&2 "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
ac085800
ER
1790 fi
1791 done
1792 else
94769f11
ER
1793 echo >&2 "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1794 echo >&2 "Not adding bootsplash to initrd."
ac085800 1795 fi
5b71959c
AM
1796 fi
1797fi
1798
e4b07ddc 1799if is_yes "$FB_SPLASH"; then
1800 if [ ! -x /usr/bin/splash_geninitramfs ]; then
1801 echo >&2 "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?"
1802 elif [ -z "$SPLASH_THEME" ]; then
1803 echo >&2 "Please configure your /etc/sysconfig/fbsplash first."
1804 echo >&2 "Generating fbsplashes skipped."
1805 else
1806 if [ -n "$FB_SPLASH_RESOLUTIONS" ]; then
1807 for res in $FB_SPLASH_RESOLUTIONS; do
1808 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1809 /usr/bin/splash_geninitramfs -a $target -r $res $SPLASH_THEME && \
1810 debug "Added $res $SPLASH_THEME theme to initramfs."
1811 else
1812 echo >&2 "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1813 fi
1814 done
1815 else
1816 echo >&2 "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1817 echo >&2 "Not adding fbsplash to initramfs."
1818 fi
1819 fi
1820fi
1821
35164381 1822rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
ac085800
ER
1823
1824# vim:ts=4:sw=4:noet:fdm=marker
This page took 0.519649 seconds and 4 git commands to generate.