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