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