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