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