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