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