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