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