]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- nfsroot patch from wolverine
[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
07137fe3 858 local m
5c4cec75
AM
859 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
860 for m in $NFS_ETH_MODULES; do
ac085800 861 findmodule "$m"
6fe19d5b
AM
862 done
863 findmodule "-ipv4"
ac085800 864 findmodule "nfs"
69b1e935 865 have_nfs=yes
f4010f7f
AM
866 warn "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
867 warn "or you will have problems like init(xx) being child process of swapper(1)."
d9179777
ER
868 return
869 fi
870
26698ab2 871 if [[ "$devpath" == /dev/md* ]]; then
df738638 872 find_modules_md "$devpath"
d9179777
ER
873 return
874 fi
875
1a63b128 876 if is_yes "$USE_MULTIPATH" && [[ "$devpath" == /dev/mapper/* ]]; then
07137fe3 877 if find_modules_multipath "$devpath"; then
9baf4f3f 878 return
9baf4f3f 879 fi
9baf4f3f
ER
880 # fallback
881 fi
882
c083ae23
ER
883 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
884 if find_modules_dmraid "$devpath"; then
885 return
886 fi
887 # fallback
888 fi
889
82474db9 890 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
7c38b114 891 find_modules_scsi
d9179777
ER
892 return
893 fi
894
82474db9 895 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')"; then
bc0d6f2d 896 find_modules_ide "$devpath"
d9179777
ER
897 return
898 fi
899
07b09cf9 900 if [[ "$devpath" == /dev/rd/* ]]; then
7c38b114 901 findmodule "DAC960"
d9179777
ER
902 return
903 fi
904
07b09cf9 905 if [[ "$devpath" == /dev/ida/* ]]; then
7c38b114 906 findmodule "cpqarray"
d9179777
ER
907 return
908 fi
909
07b09cf9 910 if [[ "$devpath" == /dev/ccis/* ]]; then
7c38b114 911 findmodule "cciss"
d9179777
ER
912 return
913 fi
914
07b09cf9 915 if [[ "$devpath" == /dev/ataraid/* ]]; then
ac085800 916 find_modules_ide
7c38b114 917 findmodule "ataraid"
82474db9 918 ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
9ae446b9 919 if [ -n "$ataraidmodules" ]; then
7c38b114 920 # FIXME: think about modules compiled in kernel
82474db9 921 die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
7c38b114
AF
922 fi
923 for n in $ataraidmodules; do
924 findmodule "$n"
925 done
d9179777
ER
926 return
927 fi
928
7c38b114 929 # check to see if we need to set up a loopback filesystem
07b09cf9 930 if [[ "$devpath" == /dev/loop* ]]; then
00eaa938 931 die "Sorry, root on loop device isn't supported."
7c38b114
AF
932 # TODO: rewrite for bsp and make nfs ready
933 if [ ! -x /sbin/losetup ]; then
00eaa938 934 die "losetup is missing"
7c38b114 935 fi
bc0d6f2d 936 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
82474db9 937 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
42820142 938 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
939 fi
940
941 line="`awk '/'$key'/ { print $0; }' $fstab`"
942 loopDev="$(echo $line | awk '{print $3}')"
943 loopFs="$(echo $line | awk '{print $4}')"
944 loopFile="$(echo $line | awk '{print $5}')"
945
946 BASICMODULES="$BASICMODULES -loop"
947 findmodule "-$loopFs"
948 BASICMODULES="$BASICMODULES -${loopFs}"
d9179777
ER
949 return
950 fi
951
952 if _check_lvm "$devpath"; then
bc0d6f2d 953 node="$devpath"
f6536797 954
07b09cf9 955 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ]; then
00eaa938 956 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 957 fi
07b09cf9 958 if [ -z "$LVMTOOLSVERSION" ]; then
ac085800 959 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 960 if [ -z "$LVMTOOLSVERSION" ]; then
00eaa938 961 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
ac085800 962 fi
77bcfc68 963 fi
07b09cf9 964 if [ -z "$PVDEVICES" ]; then
f6536797 965 VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
d2dc16e9 966 PVDEVICES=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
decd277c 967 fi
07b09cf9 968 if [ -n "$PVDEVICES" ]; then
7c38b114 969 for device in $PVDEVICES; do
d8056591 970 find_modules_for_devpath $device
7c38b114
AF
971 done
972 else
00eaa938 973 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
7c38b114 974 fi
e0c502bb 975 if [ "$LVMTOOLSVERSION" = "2" ]; then
ac085800 976 findmodule "-dm-mod"
e0c502bb 977 elif [ "$LVMTOOLSVERSION" = "1" ]; then
ac085800
ER
978 findmodule "-lvm"
979 findmodule "-lvm-mod"
93d781d1 980 else
00eaa938 981 die "LVM version $LVMTOOLSVERSION is not supported yet."
93d781d1 982 fi
d8056591 983 debug "LVM v$LVMTOOLSVERSION enabled"
69b1e935 984 have_lvm=yes
d9179777 985 return
7c38b114
AF
986 fi
987}
988
b64f015b 989firmware_install_module() {
c3667d07 990 local module="$1"
c6c6ce01 991 local firmware_files="$2"
9ed6e1db 992
94769f11 993 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
9ed6e1db 994 # firmware not yet installed
9b557a09 995 if [ ! -f "$DESTDIR/lib/firmware/firmware.sh" ]; then
034fdd5d 996 inst_d /lib/firmware
9b557a09 997cat << 'EOF' >> "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db 998#!/bin/sh -e
8639f99a
AM
999echo 1 > /sys$DEVPATH/loading
1000cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
1001echo 0 > /sys$DEVPATH/loading
1002exit 0
9ed6e1db 1003EOF
9b557a09 1004 chmod 755 "$DESTDIR/lib/firmware/firmware.sh"
9ed6e1db
AM
1005 fi
1006
1007 for firmware in $firmware_files; do
dcc1b914 1008 inst /lib/firmware/$firmware /lib/firmware/$firmware
9ed6e1db
AM
1009 done
1010
b64f015b 1011 mount_sys
c6c6ce01 1012 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" | add_linuxrc
9ed6e1db
AM
1013}
1014
2a5bcca9 1015modules_install() {
c3667d07
ER
1016 local modules="$1"
1017 local mod
2a5bcca9
AM
1018
1019 for mod in $modules; do
034fdd5d
ER
1020 MODULEDIR=$(dirname "$mod")
1021 inst_d "/lib/modules/$kernel/$MODULEDIR"
9b557a09
ER
1022 cp -a "/lib/modules/$kernel/$mod" "$DESTDIR/lib/modules/$kernel/$mod"
1023 gunzip "$DESTDIR/lib/modules/$kernel/$mod" 2> /dev/null
2a5bcca9
AM
1024 done
1025}
1026
1027modules_add_linuxrc() {
c3667d07 1028 local modules="$1"
c3667d07 1029 local mod
ac085800 1030
2a5bcca9 1031 for mod in $modules; do
87d21026 1032 MODULE2="`dirname "$mod"`"
ac085800
ER
1033 NAME2=`basename "$mod" .gz`
1034 MODULE2=$MODULE2/$NAME2
1035 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
82474db9 1036 options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
ffa1b198 1037
9ed6e1db
AM
1038 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
1039 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
94769f11 1040 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
2a5bcca9 1041
ac085800 1042 if [ -n "$verbose" ]; then
f4010f7f 1043 warn "Loading module [$module]${options:+ with options [$options]}${options:- without options}${sleep_var:+ and $sleep_var usleep}."
ac085800
ER
1044 fi
1045
9ed6e1db 1046 if [ -n "$firmware_var" ]; then
b64f015b 1047 firmware_install_module "$module" "$firmware_var"
9ed6e1db 1048 fi
c6c6ce01 1049 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" | add_linuxrc
8e598759 1050 if [ -n "${sleep_var}" ]; then
c6c6ce01 1051 echo "usleep $sleep_var" | add_linuxrc
8e598759 1052 fi
2a5bcca9
AM
1053 done
1054}
1055
82b2dba2
ER
1056initrd_gen_suspend() {
1057 if [ ! -x /usr/${_lib}/suspend/resume -a ! -x /usr/sbin/resume ]; then
1058 die "/usr/${_lib}/suspend/resume is missing!"
1059 fi
1060 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
9b557a09 1061 mknod $DESTDIR/dev/snapshot c 10 231
82b2dba2
ER
1062 inst $resume_dev /dev
1063 inst /etc/suspend.conf /etc/suspend.conf
1064 if [ -x /usr/${_lib}/suspend/resume ]; then
1065 inst /usr/${_lib}/suspend/resume /bin/resume
1066 else
1067 inst /usr/sbin/resume /bin/resume
1068 fi
55884ae2
ER
1069
1070 add_linuxrc <<-'EOF'
1071 resume
1072 EOF
82b2dba2 1073}
7591cd37 1074
82b2dba2
ER
1075initrd_gen_tuxonice() {
1076 mount_sys
1077 add_linuxrc <<-'EOF'
55884ae2
ER
1078 resume2=no
1079 for arg in $CMDLINE; do
1080 if [ "${arg##resume2=}" != "${arg}" ]; then
1081 resume2=yes
1082 fi
1083 done
1084 if [ "$resume2" = "yes" ]; then
82b2dba2
ER
1085 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1086 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
55884ae2 1087 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
413878f8 1088 fi
82b2dba2
ER
1089 EOF
1090}
413878f8 1091
82b2dba2
ER
1092initrd_gen_udev() {
1093 debug "Setting up udev..."
1094 inst_d /sbin /etc/udev
bb529f94 1095
82b2dba2
ER
1096 if [ ! -x /sbin/initrd-udevd ]; then
1097 die "/sbin/initrd-udevd not present"
1098 fi
06ac05d6 1099
82b2dba2
ER
1100 inst /sbin/initrd-udevd /sbin/udevd
1101 inst /etc/udev/udev.conf /etc/udev/udev.conf
0868f49f 1102
82b2dba2
ER
1103 mount_dev
1104 mount_sys
1105 add_linuxrc <<-'EOF'
1106 : 'Starting udev'
1107 /sbin/udevd --daemon
1108 EOF
1109 if is_yes "$PROBESTATICMODS"; then
1110 inst /sbin/initrd-udevtrigger /sbin/udevtrigger
1111 inst /sbin/initrd-udevsettle /sbin/udevsettle
1112 add_linuxrc <<-'EOF'
1113 /sbin/udevtrigger
1114 /sbin/udevsettle
1115 EOF
48413b7f 1116 fi
48413b7f 1117
82b2dba2
ER
1118 busybox_applet killall
1119 add_linuxrc <<-'EOF'
1120 killall udevd
1121 EOF
1122}
ac085800 1123
82b2dba2 1124initrd_gen_multipath() {
6d02dd34 1125 inst_d /sbin /lib/udev /etc/multipath
82b2dba2
ER
1126 inst_exec /sbin/kpartx /sbin
1127 inst_exec /sbin/multipath /sbin
1128 # for udev callouts
1129 inst_exec /sbin/scsi_id /lib/udev
1130 inst_exec /sbin/mpath* /sbin
7548b210 1131 egrep -v '^([ ]*$|#)' /etc/multipath.conf > $DESTDIR/etc/multipath.conf
6d02dd34
ER
1132
1133 if [ -f /etc/multipath/bindings ]; then
1134 egrep -v '^([ ]*$|#)' /etc/multipath/bindings > $DESTDIR/etc/multipath/bindings
9b557a09 1135 else
6d02dd34 1136 touch $DESTDIR/etc/multipath/bindings
82b2dba2 1137 fi
0868f49f 1138
82b2dba2
ER
1139 mount_dev
1140 initrd_gen_devices
bb529f94 1141
82b2dba2 1142 mount_sys
7548b210 1143 echo "export MPATH_WWID=$MPATH_WWID" | add_linuxrc
82b2dba2 1144 add_linuxrc <<-'EOF'
7548b210 1145 # parse mpath_wwid= from kernel commandline
d23ec84f 1146 for arg in $CMDLINE; do
7548b210
ER
1147 if [ "${arg##mpath_wwid=}" != "${arg}" ]; then
1148 MPATH_WWID=${arg##mpath_wwid=}
1149 if [ "$MPATH_WWID" = "*" ]; then
d23ec84f 1150 # '*' would mean activate all WWID-s
7548b210 1151 MPATH_WWID=
d23ec84f
ER
1152 echo "multipath: Activating all WWID-s"
1153 else
1154 echo "multipath: Activating WWID=$WWID"
1155 fi
1156 fi
1157 done
1158
82b2dba2 1159 debugshell
7548b210 1160 /sbin/multipath -v 0 $MPATH_WWID
bb529f94 1161
82b2dba2
ER
1162 for a in /dev/mapper/*; do
1163 [ $a = /dev/mapper/control ] && continue
d23ec84f 1164 /sbin/kpartx -a -p p $a
82b2dba2
ER
1165 done
1166 debugshell
1167 EOF
1168}
22b0c9f4 1169
82b2dba2
ER
1170initrd_gen_dmraid() {
1171 if [ ! -x /sbin/dmraid-initrd ]; then
1172 die "/sbin/dmraid-initrd is missing!"
e4b07ddc 1173 fi
e4b07ddc 1174
82b2dba2
ER
1175 inst_d /sbin
1176 inst /sbin/dmraid-initrd /sbin/dmraid
f121024f 1177
82b2dba2
ER
1178 mount_dev
1179 mount_sys
1180 initrd_gen_devices
1181 add_linuxrc <<-EOF
1182 # 2 secs was enough for my system to initialize. but really this is udev issue?
1183 usleep 2000000
1184 : 'Activating Device-Mapper RAID(s)'
1185 /sbin/dmraid -ay -i
551c3b3e 1186
82b2dba2
ER
1187 debugshell
1188 EOF
1189}
ac085800 1190
82b2dba2
ER
1191initrd_gen_bootsplash() {
1192 local target="$1"
bb529f94 1193
d8056591 1194 debug "Generating bootsplash"
7992356a
ER
1195
1196 if [ "$INITRDFS" != "initramfs" ]; then
9f1cb7c2
ER
1197 warn "Using bootsplash requires INITRDFS=initramfs; skipping bootsplash generation"
1198 return
7992356a
ER
1199 fi
1200
82b2dba2 1201 if [ ! -x /bin/splash.bin ]; then
f4010f7f 1202 warn "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
7992356a
ER
1203 return
1204 fi
1205
1206 if [ -r /etc/sysconfig/bootsplash ]; then
1207 . /etc/sysconfig/bootsplash
1208 fi
1209
1210 if [ -z "$THEME" ]; then
f4010f7f
AM
1211 warn "Please configure your /etc/sysconfig/bootsplash first."
1212 warn "Generating bootsplashes skipped."
7992356a
ER
1213 return
1214 fi
1215
1216 if [ -z "$BOOT_SPLASH_RESOLUTIONS" ]; then
1217 warn "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1218 warn "Not adding bootsplash to initrd."
1219 fi
1220
1221 for res in $BOOT_SPLASH_RESOLUTIONS; do
1222 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1223 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1224 debug "Added $res $THEME theme to initrd."
82b2dba2 1225 else
7992356a 1226 warn "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
82b2dba2 1227 fi
7992356a 1228 done
82b2dba2 1229}
bb529f94 1230
82b2dba2 1231initrd_gen_fbsplash() {
d8056591 1232 debug "Generating fbsplash"
cd670d83 1233
7992356a 1234 if [ "$INITRDFS" != "initramfs" ]; then
9f1cb7c2
ER
1235 warn "Using fbsplash requires INITRDFS=initramfs; skipping fbsplash generation"
1236 return
7992356a
ER
1237 fi
1238
82b2dba2 1239 if [ ! -x /usr/bin/splash_geninitramfs ]; then
f4010f7f 1240 warn "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?"
82b2dba2
ER
1241 return
1242 fi
1cea325b 1243
7992356a
ER
1244 if [ -r /etc/sysconfig/fbsplash ]; then
1245 . /etc/sysconfig/fbsplash
1246 fi
1247
82b2dba2 1248 if [ -z "$SPLASH_THEME" ]; then
f4010f7f
AM
1249 warn "Please configure your /etc/sysconfig/fbsplash first."
1250 warn "Generating fbsplashes skipped."
82b2dba2
ER
1251 return
1252 fi
cd670d83 1253
82b2dba2 1254 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
f4010f7f
AM
1255 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1256 warn "Not adding fbsplash to initramfs."
82b2dba2
ER
1257 return
1258 fi
bb529f94 1259
82b2dba2
ER
1260 for res in $FB_SPLASH_RESOLUTIONS; do
1261 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
9b557a09 1262 /usr/bin/splash_geninitramfs -c $DESTDIR -r $res $SPLASH_THEME && \
82b2dba2
ER
1263 debug "Added $res $SPLASH_THEME theme to initramfs."
1264 else
f4010f7f 1265 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
82b2dba2
ER
1266 fi
1267 done
1268}
bb529f94 1269
82b2dba2
ER
1270# Generates /dev nodes based on /proc/partitions information.
1271# Needs /proc mounted.
1272# Can be called multiple times.
1273initrd_gen_devices() {
1274 if is_yes "$proc_partitions"; then
1275 return
1276 fi
1277 proc_partitions=yes
335cd101 1278
82b2dba2
ER
1279 mount_dev
1280 add_linuxrc <<-'EOF'
1281 : 'Making device nodes'
1282 cat /proc/partitions | (
1283 # ignore first two lines, header, empty line and process rest
1284 read b; read b
2cc3ae8b 1285
82b2dba2
ER
1286 while read major minor blocks dev rest; do
1287 node=/dev/$dev
1288 mkdir -p ${node%/*}
1289 mknod $node b $major $minor
1290 done
1291 )
1292 EOF
1293}
bb529f94 1294
82b2dba2
ER
1295initrd_gen_md() {
1296 debug "Setting up mdadm..."
bb529f94 1297
82b2dba2
ER
1298 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1299 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1300 fi
bb529f94 1301
82b2dba2 1302 inst /sbin/initrd-mdassemble /bin/mdassemble
bb529f94 1303
82b2dba2
ER
1304 # LVM on RAID case
1305 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1306 for ex_dev in $dev_list_extra; do
9b557a09 1307 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2
ER
1308 done
1309 do_md0=1
1310 for nr in `seq 1 $rootdev_nr`; do
1311 eval cr_rootdev="\$rootdev${nr}"
1312 eval cr_dev_list="\$dev_list${nr}"
1313 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
bb529f94 1314
82b2dba2 1315 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
f5db170b 1316
9b557a09 1317 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2
ER
1318 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1319 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1320 if [ -n "$cr_md_conf" ]; then
9b557a09 1321 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2 1322 else
9b557a09 1323 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2 1324 fi
034fdd5d 1325
82b2dba2
ER
1326 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1327 # mkdir in case of devfs name
1328 inst_d $(dirname $f)
9b557a09 1329 [ -e "$DESTDIR/$f" ] && continue
82b2dba2
ER
1330 # this works fine with and without devfs
1331 inst $f $f
1332 done
1333 done
bb529f94 1334
82b2dba2 1335 echo "mdassemble" | add_linuxrc
bb529f94 1336
82b2dba2
ER
1337 # needed to determine md-version
1338 if [ "$do_md0" -eq 1 ]; then
9b557a09 1339 mknod $DESTDIR/dev/md0 b 9 0
82b2dba2
ER
1340 fi
1341}
ef66f232 1342
82b2dba2
ER
1343initrd_gen_nfs() {
1344 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1345 # have problems like init(XX) being child process of swapper(1).
1346 debug "Adding rootfs on NFS support to initrd (dhcp)"
9b557a09
ER
1347 mknod "$DESTDIR/dev/urandom" c 1 9
1348 mkdir "$DESTDIR/newroot"
1349 mkdir "$DESTDIR/proc"
82b2dba2
ER
1350 echo "ifconfig lo 127.0.0.1 up" | add_linuxrc
1351 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" | add_linuxrc
1352 echo "ifconfig eth0 0.0.0.0 up" | add_linuxrc
1353 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" | add_linuxrc
57227e0a 1354
9b557a09 1355 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
82b2dba2
ER
1356 #!/bin/sh
1357 [ "$1" != "bound" ] && exit
1358 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1359 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1360 ifconfig $interface $ip $BROADCAST $NETMASK up
1361 if [ -n "$router" ]; then
1362 for r in $router; do
1363 route add default gw $r dev $interface
1364 done
1365 fi
1366 EOF
aeb75537 1367
9b557a09 1368 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
3a1d3d88 1369 for o in $CMDLINE; do
82b2dba2
ER
1370 case $o in
1371 nfsroot=*)
1372 rootpath=${o#nfsroot=}
1373 ;;
1374 esac
1375 done
e7751933 1376
82b2dba2
ER
1377 if [ -n "$rootpath" ]; then
1378 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1379 else
1380 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1381 echo "All seen variables are listed below:"
1382 set
e934d044 1383 fi
82b2dba2 1384 EOF
e7751933 1385
9b557a09 1386 chmod 755 "$DESTDIR/bin/setdhcp"
82b2dba2
ER
1387 add_linuxrc <<-'EOF'
1388 cd /newroot
1389 pivot_root . initrd
1390 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1391 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1392 EOF
1393}
1394
1395initrd_gen_lvm() {
1396 debug "Adding LVM support to initrd"
1397 inst_d /tmp /newroot
1398 inst /sbin/initrd-lvm /bin/lvm.static
1399
1400 # always make /dev on tmpfs for LVM2
1401 if [ "$LVMTOOLSVERSION" = "2" ]; then
1402 mount_dev
c6c6ce01 1403 fi
e7751933 1404
82b2dba2
ER
1405 if ! is_yes "$dev_mounted"; then
1406 inst_d /dev/mapper
9b557a09 1407 mknod $DESTDIR/dev/mapper/control c 10 63
82b2dba2
ER
1408 for device in $PVDEVICES; do
1409 # if LVM on RAID then device might be copied already in gen_md
9b557a09 1410 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
82b2dba2
ER
1411 inst $device /dev
1412 done
e7751933 1413 fi
c31050f3 1414
82b2dba2
ER
1415 mount_tmp
1416 if [ "$LVMTOOLSVERSION" = "1" ]; then
1417 add_linuxrc <<-EOF
1418 lvm vgscan -T
1419 lvm vgchange -T -a y $VGVOLUME
1420 EOF
1421 else
1422 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
9b557a09
ER
1423 echo "global {" > "$DESTDIR/etc/lvm.conf"
1424 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1425 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1426 echo "}" >> "$DESTDIR/etc/lvm.conf"
1427 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1428 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
82b2dba2 1429 if is_yes "$have_md"; then
9b557a09 1430 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1431 fi
1432 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
9b557a09 1433 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1434 fi
1435 if [ "$lvm_ignore_devices" ]; then
1436 # TODO: think of merging with lvm dumpconfig output
9b557a09 1437 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1438 local dev
1439 for dev in $lvm_ignore_devices; do
d8056591 1440 debug "LVM v2: ignore device $dev"
82b2dba2 1441 printf ' "r|^%s.*|",\n' $dev
9b557a09
ER
1442 done >> "$DESTDIR/etc/lvm.conf"
1443 echo ']' >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1444 fi
1445 # XXX filter= must be on one line!
9b557a09
ER
1446 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1447 echo "}" >> "$DESTDIR/etc/lvm.conf"
fd2dc249 1448
82b2dba2 1449 initrd_gen_devices
bb529f94 1450
82b2dba2 1451 add_linuxrc <<-EOF
6bdc2eeb
ER
1452 export ROOTDEV=$rootdev
1453 export VGVOLUME=$VGVOLUME
82b2dba2
ER
1454 EOF
1455 add_linuxrc <<-'EOF'
6bdc2eeb
ER
1456 # parse rootdev from kernel commandline
1457 for arg in $CMDLINE; do
1458 if [ "${arg##root=}" != "${arg}" ]; then
bab4bc2b
ER
1459 local rdev=${arg##root=}
1460 if [ "$rdev" != "$ROOTDEV" ]; then
1461 ROOTDEV=$rdev
1462 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1463 local tmp=${ROOTDEV#/dev/}
1464 if [ "$tmp" != "$ROOTDEV" ]; then
1465 VGVOLUME=${tmp%/*}
1466 echo "LVM: Using Volume Group '$VGVOLUME'"
1467 fi
6bdc2eeb
ER
1468 fi
1469 fi
1470 done
1471
3a1d3d88 1472 # disable noise from LVM accessing devices that aren't ready.
f258d870 1473 read printk < /proc/sys/kernel/printk
82b2dba2 1474 echo 0 > /proc/sys/kernel/printk
22b0c9f4 1475
82b2dba2
ER
1476 export LVM_SYSTEM_DIR=/tmp
1477 : 'Scanning for Volume Groups'
1478 lvm.static vgscan --mknodes --ignorelockingfailure 2>/dev/null
b4d9d384 1479
82b2dba2 1480 : 'Activating Volume Groups'
6bdc2eeb 1481 lvm.static vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
ac085800 1482
82b2dba2 1483 echo "$printk" > /proc/sys/kernel/printk
9299682f 1484
82b2dba2 1485 # Find out major/minor
6bdc2eeb 1486 attrs="$(lvm.static lvdisplay --ignorelockingfailure -c $ROOTDEV 2>/dev/null)"
82b2dba2 1487 if [ "$attrs" ]; then
6bdc2eeb 1488 majmin="${attrs#*$ROOTDEV*:*:*:*:*:*:*:*:*:*:*:*}"
82b2dba2
ER
1489 if [ "$majmin" != "$attrs" ]; then
1490 major="${majmin%:*}"
1491 minor="${majmin#*:}"
1492 fi
1493 fi
1606e343 1494
82b2dba2
ER
1495 if [ "$major" -a "$minor" ]; then
1496 # Pass it to kernel
1497 echo $((256 * $major + $minor)) > /proc/sys/kernel/real-root-dev
1498 else
6bdc2eeb 1499 echo 2>&1 "Error figuring out real root device for $ROOTDEV!"
82b2dba2
ER
1500 echo 2>&1 "System will not most likely boot up! So dropping you to a shell!"
1501 echo 2>&1 ""
1502 sh
1503 fi
7915c8b1 1504 EOF
1606e343 1505 fi
82b2dba2 1506}
b64f015b 1507
82b2dba2 1508initrd_gen_procdata() {
5a761721 1509 debug "Adding rootfs finding based on kernel cmdline root= option support."
82b2dba2 1510 add_linuxrc <<-'EOF'
55884ae2 1511 root="$(echo "$CMDLINE" | busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ')"
82b2dba2
ER
1512 if [ -n "$root" ]; then
1513 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1514 if [ -n "$rootnr" ]; then
1515 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1516 fi
1517 fi
b64f015b 1518 EOF
1606e343
AM
1519}
1520
034056fd
ER
1521# main()
1522if [ "$(id -u)" != 0 ]; then
1523 die "You need to be root to generate initrd"
1524fi
1525
82b2dba2
ER
1526if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1527 USE_UDEV=yes
1528 . /etc/udev/udev.conf
1529fi
2cc3ae8b 1530
82b2dba2
ER
1531if [ -x /sbin/dmraid-initrd ]; then
1532 USE_DMRAID=yes
1533fi
2cc3ae8b 1534
82b2dba2
ER
1535if [ -x /sbin/multipath ]; then
1536 USE_MULTIPATH=yes
1537fi
2cc3ae8b 1538
82b2dba2
ER
1539if [ -r /etc/sysconfig/geninitrd ]; then
1540 . /etc/sysconfig/geninitrd
1541fi
2cc3ae8b 1542
82b2dba2
ER
1543if [ ! -x /bin/initrd-busybox ]; then
1544 die "/bin/initrd-busybox is missing!"
1545fi
c6c6ce01 1546
82b2dba2
ER
1547# backwards compatible
1548if [ "$USE_SUSPEND2" ]; then
1549 USE_TUXONICE=$USE_SUSPEND2
f4010f7f 1550 warn "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
82b2dba2 1551fi
882472ae 1552
82b2dba2
ER
1553while [ $# -gt 0 ]; do
1554 case $1 in
1555 --fstab=*)
1556 fstab=${1#--fstab=}
1557 ;;
1558 --fstab)
1559 fstab=$2
1560 shift
1561 ;;
1562 --modules-conf=*)
1563 modulefile=${1#--modules-conf=}
1564 ;;
1565 --modules-conf)
1566 modulefile=$2
1567 shift
1568 ;;
1569 --use-raidstart|--with-raidstart)
1570 USERAIDSTART=yes
1571 ;;
1572 --without-raidstart)
1573 USERAIDSTART=no
1574 ;;
1575 --use-insmod-static|--with-insmod-static)
1576 USEINSMODSTATIC=yes
1577 ;;
1578 --without-insmod-static)
1579 USEINSMODSTATIC=no
1580 ;;
1581 --with-bootsplash)
1582 BOOT_SPLASH=yes
1583 ;;
1584 --without-bootsplash)
1585 BOOT_SPLASH=no
1586 ;;
1587 --with-fbsplash)
1588 FB_SPLASH=yes
1589 ;;
1590 --without-fbsplash)
1591 FB_SPLASH=no
1592 ;;
1593 --with-suspend)
1594 USE_SUSPEND=yes
1595 ;;
1596 --without-suspend)
1597 USE_SUSPEND=no
1598 ;;
1599 --with-suspend2 | --with-tuxonice)
1600 USE_TUXONICE=yes
1601 ;;
1602 --without-suspend2 | --without-tuxonice)
1603 USE_TUXONICE=no
1604 ;;
1605 --lvmtoolsversion=|--lvmversion=)
1606 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
1607 ;;
1608 --lvmtoolsversion|--lvmversion)
1609 LVMTOOLSVERSION=$2
1610 shift
1611 ;;
1612 --without-udev)
1613 USE_UDEV=no
1614 ;;
1615 --with-udev)
1616 USE_UDEV=yes
1617 ;;
1618 --without-dmraid)
1619 USE_DMRAID=no
1620 ;;
1621 --without-multipath)
1622 USE_MULTPATH=no
1623 ;;
1624 --with=*)
1625 BASICMODULES="$BASICMODULES ${1#--with=}"
1626 ;;
1627 --with)
1628 BASICMODULES="$BASICMODULES $2"
1629 shift
1630 ;;
1631 --version)
1632 echo "$PROGRAM: version $VERSION"
1633 exit 0
1634 ;;
1635 -v)
1636 verbose=-v
1637 ;;
1638 --nocompress)
1639 COMPRESS=no
1640 ;;
1641 --ifneeded)
1642 ifneeded=1
1643 ;;
1644 -f)
1645 force=1
1646 ;;
1647 --preload=*)
1648 PREMODS="$PREMODS ${1#--preload=}"
1649 ;;
1650 --preload)
1651 PREMODS="$PREMODS $2"
1652 shift
1653 ;;
1654 --fs=*)
f4010f7f 1655 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1656 INITRDFS=${1#--fs=}
1657 ;;
1658 --fs)
f4010f7f 1659 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1660 INITRDFS=$2
1661 shift
1662 ;;
1663 --initrdfs=*)
1664 INITRDFS=${1#--initrdfs=}
1665 ;;
1666 --initrdfs)
1667 INITRDFS=$2
1668 shift
1669 ;;
1670 --image-version)
1671 img_vers=yes
1672 ;;
1673 --ide-only-root)
1674 ide_only_root="yes"
1675 ;;
1676 *)
1677 if [ -z "$target" ]; then
1678 target="$1"
1679 elif [ -z "$kernel" ]; then
1680 kernel="$1"
1681 else
1682 usage
1683 fi
1684 ;;
1685 esac
f5db170b 1686
82b2dba2
ER
1687 shift
1688done
1689
1690if [ -z "$target" -o -z "$kernel" ]; then
1691 usage
1692fi
1693
130aadc1 1694if [ ! -f /boot/vmlinuz-"$kernel" ]; then
f4010f7f 1695 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
130aadc1
ER
1696fi
1697
82b2dba2
ER
1698pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
1699pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
1700
1701if [ -z "$INITRDFS" ]; then
326dd4ad 1702 if [ -z "$FS" ]; then
82b2dba2
ER
1703 # default value
1704 if [ "$pack_version" -ge "002005" ]; then
1705 INITRDFS="initramfs"
f5db170b 1706 else
82b2dba2 1707 INITRDFS="rom"
f5db170b 1708 fi
82b2dba2 1709 else
f4010f7f 1710 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
82b2dba2 1711 INITRDFS="$FS"
f5db170b 1712 fi
82b2dba2 1713fi
f5db170b 1714
82b2dba2
ER
1715if [ "$pack_version" -lt "002006" ]; then
1716 USE_UDEV=no
1717 USE_DMRAID=no
1718fi
f5db170b 1719
82b2dba2
ER
1720if [ "$pack_version" -ge "002005" ]; then
1721 modext=".ko"
1722 insmod="insmod"
1723fi
966c32cc 1724
82b2dba2
ER
1725if is_yes "$USEINSMODSTATIC"; then
1726 insmod="insmod.static"
1727 INSMOD="/sbin/insmod.static"
1728 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1729 INSMOD="/sbin/insmod.static.modutils"
966c32cc 1730 fi
82b2dba2
ER
1731 if [ ! -f "$INSMOD" ]; then
1732 die "insmod.static requested but /sbin/insmod.static not found!"
966c32cc 1733 fi
82b2dba2 1734fi
966c32cc 1735
82b2dba2
ER
1736case "$INITRDFS" in
1737 ext2)
1738 if [ ! -x /sbin/mke2fs ]; then
1739 die "/sbin/mke2fs is missing"
f5db170b 1740 fi
82b2dba2
ER
1741 ;;
1742 rom|romfs)
1743 if [ ! -x /sbin/genromfs ]; then
1744 die "/sbin/genromfs is missing"
1745 fi
1746 ;;
1747 cram|cramfs)
1748 if [ ! -x /sbin/mkcramfs ]; then
1749 die "/sbin/mkcramfs is missing"
1750 fi
1751 ;;
1752 initramfs)
1753 if [ ! -x /bin/cpio ]; then
1754 die "/bin/cpio is missing"
1755 fi
1756 if [ ! -x /usr/bin/find ]; then
1757 die "/usr/bin/find is missing"
1758 fi
1759 ;;
1760 *)
1761 die "Filesystem $INITRDFS on initrd is not supported"
1762 ;;
1763esac
f5db170b 1764
82b2dba2
ER
1765if [ -n "$img_vers" ]; then
1766 target="$target-$kernel"
1767fi
8bd582f1 1768
82b2dba2
ER
1769if [ -z "$force" -a -f "$target" ]; then
1770 die "$target already exists."
1771fi
c6c6ce01 1772
82b2dba2
ER
1773if [ ! -d "/lib/modules/$kernel" ]; then
1774 die "/lib/modules/$kernel is not a directory."
1775fi
2ffb1734 1776
82b2dba2 1777if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
9f1cb7c2
ER
1778 warn "Tuxonice can't be used in parallel with mainline suspend! Disabling both inclustion to initrd"
1779 USE_SUSPEND=no
1780 USE_TUXONICE=no
82b2dba2 1781fi
ac085800 1782
7992356a 1783if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
9f1cb7c2
ER
1784 warn "You can't use bootsplash and fbsplash together! Disabling both inclusion to initrd"
1785 FB_SPLASH=no
1786 BOOT_SPLASH=no
82b2dba2 1787fi
994eb509 1788
82b2dba2 1789if [ ! -f /proc/mounts ]; then
f4010f7f 1790 warn "WARNING: /proc filesystem not mounted, may cause wrong results or failure."
82b2dba2 1791fi
6cca3165 1792
82b2dba2
ER
1793if [ -d /usr/lib64 ]; then
1794 _lib=lib64
1795else
1796 _lib=lib
1797fi
d8056591 1798debug "Using libdir: $_lib"
ac085800 1799
82b2dba2
ER
1800cache_modprobe_conf
1801
1802for n in $PREMODS; do
1803 findmodule "$n"
1804done
1805
1806# allow forcing loading SCSI and/or IDE modules
1807if is_yes "$ADDSCSI"; then
1808 find_modules_scsi
1809fi
1810
1811if is_yes "$ADDIDE"; then
1812 find_modules_ide
1813fi
1814
1815find_root "$fstab" || exit
1816debug "Using $rootdev as device for rootfs"
1817
d8056591
ER
1818find_modules_for_devpath "$rootdev"
1819[ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
ac085800 1820
82b2dba2 1821findmodule "-$rootFs"
ac085800 1822
82b2dba2
ER
1823for n in $BASICMODULES; do
1824 findmodule "$n"
1825done
4e9eb79c 1826
82b2dba2
ER
1827if is_yes "$USE_TUXONICE"; then
1828 findmodule "-lzf"
1829fi
33d24e12 1830
82b2dba2
ER
1831if is_yes "$FB_SPLASH"; then
1832 findmodule "-evdev"
1833fi
2968c9dd 1834
82b2dba2
ER
1835if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1836 debug "No modules are needed -- not building initrd image."
1837 exit 0
1838fi
c6c6ce01 1839
d8056591 1840DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
9b557a09 1841RCFILE="$DESTDIR/linuxrc"
82b2dba2
ER
1842> "$RCFILE"
1843chmod a+rx "$RCFILE"
9b557a09 1844ln -s linuxrc $DESTDIR/init
e8d178ff 1845
82b2dba2
ER
1846# create dirs that we really need
1847inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
e8d178ff 1848
82b2dba2 1849modules_install "$MODULES"
b64f015b 1850
82b2dba2
ER
1851# mknod'ing the devices instead of copying them works both with and
1852# without devfs...
9b557a09
ER
1853mknod "$DESTDIR/dev/console" c 5 1
1854mknod "$DESTDIR/dev/null" c 1 3
1855mknod "$DESTDIR/dev/zero" c 1 5
be2f3ecc 1856
82b2dba2 1857inst /bin/initrd-busybox /bin/initrd-busybox
9b557a09
ER
1858ln -s initrd-busybox $DESTDIR/bin/sh
1859ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
2ffb1734 1860
82b2dba2
ER
1861if is_yes "$USEINSMODSTATIC"; then
1862 inst "$INSMOD" /bin/insmod.static
1863fi
c6c6ce01 1864
82b2dba2
ER
1865add_linuxrc <<EOF
1866#!/bin/sh
1867# initrd generated by:
1868# $RCSID
c6c6ce01 1869
82b2dba2
ER
1870EOF
1871mount_proc
1872add_linuxrc <<-'EOF'
3a1d3d88 1873 read CMDLINE < /proc/cmdline; export CMDLINE
c6c6ce01 1874
82b2dba2
ER
1875 for arg in $CMDLINE; do
1876 if [ "${arg}" = "debuginitrd" ]; then
1877 DEBUGINITRD=yes
1878 fi
1879 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1880 DEBUGINITRD=${arg##debuginitrd=}
1881 fi
1882 done
c6c6ce01 1883
82b2dba2
ER
1884 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1885 if [ "$DEBUGINITRD" = "sh" ]; then
1886 debugshell() {
1887 sh
1888 }
1889 else
1890 debugshell() {
1891 :
1892 }
1893 fi
e934d044 1894
82b2dba2
ER
1895 if [ "$DEBUGINITRD" ]; then
1896 set -x
cff3058d 1897 fi
82b2dba2 1898EOF
2df2e995 1899
82b2dba2
ER
1900modules_add_linuxrc "$MODULES"
1901
1902# TODO: rewrite for busybox
1903#if [ -n "$loopDev" ]; then
1904# if [ ! -d /initrd ]; then
1905# mkdir /initrd
1906# fi
1907#
9b557a09
ER
1908# cp -a "$loopDev" "$DESTDIR/dev"
1909# cp -a "$rootdev" "$DESTDIR/dev"
82b2dba2
ER
1910# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1911# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1912# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1913# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1914#fi
2b1a3707 1915
1606e343
AM
1916if is_yes "$USE_UDEV"; then
1917 initrd_gen_udev
1918fi
1919
2ce7656a 1920if is_yes "$USE_SUSPEND"; then
22b0c9f4
AM
1921 initrd_gen_suspend
1922fi
1923
1cd2aabd
ER
1924if is_yes "$USE_TUXONICE"; then
1925 initrd_gen_tuxonice
2df2e995
AM
1926fi
1927
c083ae23 1928if is_yes "$have_dmraid" ]; then
882472ae
ER
1929 initrd_gen_dmraid
1930fi
1931
c083ae23 1932if is_yes "$have_multipath"; then
2cc3ae8b
ER
1933 initrd_gen_multipath
1934fi
1935
69b1e935 1936if is_yes "$have_nfs"; then
2df2e995 1937 initrd_gen_nfs
df738638
ER
1938elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1939 initrd_gen_md
69b1e935 1940 if is_yes "$have_lvm"; then
2df2e995 1941 initrd_gen_lvm
bfea009a
AM
1942 else
1943 initrd_gen_procdata
2df2e995 1944 fi
69b1e935 1945elif is_yes "$have_lvm"; then
2df2e995 1946 initrd_gen_lvm
2b1a3707
AM
1947else
1948 initrd_gen_procdata
7c38b114
AF
1949fi
1950
5101a385 1951# additional devs always needed
9b557a09 1952[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1953
f8f9e56d 1954if [ "$INITRDFS" = "initramfs" ]; then
034fdd5d 1955 inst_d /newroot
6d2c63ed
ER
1956 if [ "$rootdev" = "/dev/nfs" ]; then
1957 echo "rootfs on NFS root=/dev/nfs"
1958 else
1959 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev /dev
1960 fi
e4b07ddc 1961 # Parsing root parameter
81d53704 1962 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
c6c6ce01 1963 add_linuxrc <<-'EOF'
c6c6ce01
ER
1964 eval "$(busybox awk -v c="$CMDLINE" '
1965 BEGIN {
1966 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1967 num_pattern = "[0-9a-f]" num_pattern_short;
1968 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1969 partition = "no_partition_found";
1970 min = -1; maj = -1;
1971
1972 gsub(/.*root=/,NIL,c);
1973 gsub(/ .*/,NIL,c);
1974
1975 sub("^0x", "", c);
1976 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1977 if (c ~ "^" num_pattern "$") {
1978 maj = sprintf("%s",substr(c,1,2));
1979 min = sprintf("%s",substr(c,3));
1980 }
1981 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1982 if (c ~ "^" dev_pattern "$") partition = c;
1983 }
df391e6f 1984
c6c6ce01
ER
1985 $4 ~ partition { maj = $1; min = $2; }
1986 $1 ~ maj && $2 ~ min { partition = $4; }
1987
1988 END {
1989 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
1990 partition, maj, min);
1991 }
1992 ' /proc/partitions)"
1993 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1994 mknod $device b $maj $min
1995 fi
1996 EOF
92a4990b 1997
c6c6ce01 1998 add_linuxrc <<-EOF
f5db170b
ER
1999 rootdev=$rootdev
2000 rootfs=$rootFs
2001 EOF
2002
2003 add_linuxrc <<-'EOF'
2004 if [ "$device" = '/dev/no_partition_found' ]; then
2005 device=$rootdev
c6c6ce01 2006 fi
e620b426 2007
f5db170b
ER
2008 mount -t $rootfs -r $device /newroot
2009 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
2010 if [ -z "$init" -o ! -x "/newroot$init" ]; then
c6c6ce01
ER
2011 init=/sbin/init
2012 fi
b64f015b 2013 EOF
f1a5a1b0 2014
f5db170b
ER
2015 umount_all
2016 busybox_applet switch_root
2017 add_linuxrc <<-'EOF'
2018 exec switch_root /newroot $init
2019
2020 echo "Error! initramfs should not reach this place."
c6c6ce01
ER
2021 echo "It probably means you've got old version of busybox, with broken"
2022 echo "initramfs support. Trying to boot anyway, but won't promise anything."
f1a5a1b0 2023
f5db170b 2024 exec chroot /newroot $init
f1a5a1b0 2025
f5db170b 2026 echo "Failed to chroot!"
c6c6ce01 2027 EOF
f5db170b
ER
2028 # we need /init being real file, not symlink, otherwise the initramfs will
2029 # not be ran by pid 1 which is required for switch_root
9b557a09 2030 mv $DESTDIR/linuxrc $DESTDIR/init
d8056591 2031 ln -s init $DESTDIR/linuxrc
b64f015b
ER
2032else
2033 # other than initramfs
2034 umount_all
f8f9e56d
AM
2035fi
2036
b7feffb3
ER
2037if is_yes "$FB_SPLASH"; then
2038 initrd_gen_fbsplash
2039fi
2040
d8056591 2041IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
2ad94d8a 2042case "$INITRDFS" in
8b1e4ac7 2043 ext2)
d8056591
ER
2044 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2045 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
73edc0c1 2046 if [ "$IMAGESIZE" -gt 4096 ]; then
19afb117 2047 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
73edc0c1
ER
2048 fi
2049
d8056591 2050 debug "Creating ext2 image $IMAGE"
73edc0c1
ER
2051 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2052 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2053 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2054
d8056591
ER
2055 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2056 debug "Mounting ext2 image $IMAGE to $tmpmnt"
73edc0c1 2057 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
d8056591
ER
2058 # We don't need this directory, so let's save space
2059 rm -rf "$tmpmnt"/lost+found
73edc0c1 2060
d8056591
ER
2061 debug "Copy recursively $DESTDIR -> $tmpmnt"
2062 cp -a $DESTDIR/* $tmpmnt
35164381 2063 umount "$IMAGE"
d8056591
ER
2064 rmdir "$tmpmnt"
2065
8b1e4ac7 2066 ;;
c1548a54 2067 rom|romfs)
d8056591
ER
2068 debug "Generating romfs image: $IMAGE"
2069 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
cdf1e7c9 2070 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
d8056591 2071 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
a8b63949 2072 if [ "$IMAGESIZE" -gt 4096 ]; then
19afb117 2073 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
a8b63949 2074 fi
8b1e4ac7 2075 ;;
c1548a54 2076 cram|cramfs)
d8056591 2077 mkcramfs "$DESTDIR" "$IMAGE"
8b1e4ac7 2078 ;;
48413b7f 2079 initramfs)
d8056591 2080 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
48413b7f 2081 ;;
8b1e4ac7 2082 *)
7758e45c 2083 echo "Filesystem $INITRDFS not supported by $PROGRAM";
c31050f3 2084esac
bb529f94 2085
82474db9 2086if is_yes "$COMPRESS"; then
d8056591
ER
2087 local tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2088 debug "Compressing $target"
2089 gzip -9 < "$IMAGE" > "$tmp"
2090 mv -f "$tmp" "$target"
bb529f94 2091else
7d2fc5eb 2092 cp -a "$IMAGE" "$target"
bb529f94 2093fi
5b71959c 2094
7992356a 2095# XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
5b71959c 2096if is_yes "$BOOT_SPLASH"; then
f5db170b 2097 initrd_gen_bootsplash "$target"
5b71959c
AM
2098fi
2099
d8056591 2100rm -rf "$DESTDIR" "$IMAGE"
ac085800
ER
2101
2102# vim:ts=4:sw=4:noet:fdm=marker
This page took 0.492143 seconds and 4 git commands to generate.