]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- fixed creating udevsettle and udevtrigger symlinks
[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'
55884ae2
ER
1009 resume2=no
1010 for arg in $CMDLINE; do
1011 if [ "${arg##resume2=}" != "${arg}" ]; then
1012 resume2=yes
1013 fi
1014 done
1015 if [ "$resume2" = "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
82b2dba2 1170 if [ ! -x /usr/bin/splash_geninitramfs ]; then
f4010f7f 1171 warn "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?"
82b2dba2
ER
1172 return
1173 fi
1cea325b 1174
7992356a
ER
1175 if [ -r /etc/sysconfig/fbsplash ]; then
1176 . /etc/sysconfig/fbsplash
1177 fi
1178
82b2dba2 1179 if [ -z "$SPLASH_THEME" ]; then
f4010f7f
AM
1180 warn "Please configure your /etc/sysconfig/fbsplash first."
1181 warn "Generating fbsplashes skipped."
82b2dba2
ER
1182 return
1183 fi
cd670d83 1184
82b2dba2 1185 if [ -z "$FB_SPLASH_RESOLUTIONS" ]; then
f4010f7f
AM
1186 warn "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1187 warn "Not adding fbsplash to initramfs."
82b2dba2
ER
1188 return
1189 fi
bb529f94 1190
82b2dba2
ER
1191 for res in $FB_SPLASH_RESOLUTIONS; do
1192 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
9b557a09 1193 /usr/bin/splash_geninitramfs -c $DESTDIR -r $res $SPLASH_THEME && \
82b2dba2
ER
1194 debug "Added $res $SPLASH_THEME theme to initramfs."
1195 else
f4010f7f 1196 warn "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
82b2dba2
ER
1197 fi
1198 done
1199}
bb529f94 1200
82b2dba2
ER
1201# Generates /dev nodes based on /proc/partitions information.
1202# Needs /proc mounted.
1203# Can be called multiple times.
1204initrd_gen_devices() {
1205 if is_yes "$proc_partitions"; then
1206 return
1207 fi
1208 proc_partitions=yes
335cd101 1209
82b2dba2
ER
1210 mount_dev
1211 add_linuxrc <<-'EOF'
1212 : 'Making device nodes'
1213 cat /proc/partitions | (
1214 # ignore first two lines, header, empty line and process rest
1215 read b; read b
2cc3ae8b 1216
82b2dba2
ER
1217 while read major minor blocks dev rest; do
1218 node=/dev/$dev
1219 mkdir -p ${node%/*}
1220 mknod $node b $major $minor
1221 done
1222 )
1223 EOF
1224}
bb529f94 1225
82b2dba2
ER
1226initrd_gen_md() {
1227 debug "Setting up mdadm..."
bb529f94 1228
82b2dba2
ER
1229 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1230 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
1231 fi
bb529f94 1232
82b2dba2 1233 inst /sbin/initrd-mdassemble /bin/mdassemble
bb529f94 1234
82b2dba2
ER
1235 # LVM on RAID case
1236 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
666778eb
AM
1237 if [ "$dev_list_extra" = "partitions" ]; then
1238 # FIXME: handle this case (see man mdadm.conf)
1239 echo "DEVICE partitions" >> "$DESTDIR/etc/mdadm.conf"
1240 dev_list_extra=""
1241 else
1242 for ex_dev in $dev_list_extra; do
1243 echo "DEVICE $ex_dev" >> "$DESTDIR/etc/mdadm.conf"
1244 done
1245 fi
82b2dba2
ER
1246 do_md0=1
1247 for nr in `seq 1 $rootdev_nr`; do
1248 eval cr_rootdev="\$rootdev${nr}"
1249 eval cr_dev_list="\$dev_list${nr}"
1250 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
bb529f94 1251
82b2dba2 1252 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
f5db170b 1253
9b557a09 1254 echo "DEVICE $cr_dev_list" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2
ER
1255 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1256 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
1257 if [ -n "$cr_md_conf" ]; then
9b557a09 1258 echo "$cr_md_conf" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2 1259 else
9b557a09 1260 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$DESTDIR/etc/mdadm.conf"
82b2dba2 1261 fi
034fdd5d 1262
82b2dba2
ER
1263 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1264 # mkdir in case of devfs name
1265 inst_d $(dirname $f)
9b557a09 1266 [ -e "$DESTDIR/$f" ] && continue
82b2dba2
ER
1267 # this works fine with and without devfs
1268 inst $f $f
1269 done
1270 done
bb529f94 1271
82b2dba2 1272 echo "mdassemble" | add_linuxrc
bb529f94 1273
82b2dba2
ER
1274 # needed to determine md-version
1275 if [ "$do_md0" -eq 1 ]; then
9b557a09 1276 mknod $DESTDIR/dev/md0 b 9 0
82b2dba2
ER
1277 fi
1278}
ef66f232 1279
82b2dba2
ER
1280initrd_gen_nfs() {
1281 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1282 # have problems like init(XX) being child process of swapper(1).
1283 debug "Adding rootfs on NFS support to initrd (dhcp)"
9b557a09
ER
1284 mknod "$DESTDIR/dev/urandom" c 1 9
1285 mkdir "$DESTDIR/newroot"
1286 mkdir "$DESTDIR/proc"
82b2dba2
ER
1287 echo "ifconfig lo 127.0.0.1 up" | add_linuxrc
1288 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" | add_linuxrc
1289 echo "ifconfig eth0 0.0.0.0 up" | add_linuxrc
1290 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" | add_linuxrc
57227e0a 1291
9b557a09 1292 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
82b2dba2
ER
1293 #!/bin/sh
1294 [ "$1" != "bound" ] && exit
1295 [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1296 [ -n "$subnet" ] && NETMASK="netmask $subnet"
1297 ifconfig $interface $ip $BROADCAST $NETMASK up
1298 if [ -n "$router" ]; then
1299 for r in $router; do
1300 route add default gw $r dev $interface
1301 done
1302 fi
1303 EOF
aeb75537 1304
9b557a09 1305 cat <<-'EOF' > "$DESTDIR/bin/setdhcp"
3a1d3d88 1306 for o in $CMDLINE; do
82b2dba2
ER
1307 case $o in
1308 nfsroot=*)
1309 rootpath=${o#nfsroot=}
1310 ;;
1311 esac
1312 done
e7751933 1313
82b2dba2
ER
1314 if [ -n "$rootpath" ]; then
1315 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
1316 else
1317 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1318 echo "All seen variables are listed below:"
1319 set
e934d044 1320 fi
82b2dba2 1321 EOF
e7751933 1322
9b557a09 1323 chmod 755 "$DESTDIR/bin/setdhcp"
82b2dba2
ER
1324 add_linuxrc <<-'EOF'
1325 cd /newroot
1326 pivot_root . initrd
1327 [ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1328 exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1
1329 EOF
1330}
1331
1332initrd_gen_lvm() {
1333 debug "Adding LVM support to initrd"
1334 inst_d /tmp /newroot
1335 inst /sbin/initrd-lvm /bin/lvm.static
1336
1337 # always make /dev on tmpfs for LVM2
1338 if [ "$LVMTOOLSVERSION" = "2" ]; then
1339 mount_dev
c6c6ce01 1340 fi
e7751933 1341
82b2dba2
ER
1342 if ! is_yes "$dev_mounted"; then
1343 inst_d /dev/mapper
9b557a09 1344 mknod $DESTDIR/dev/mapper/control c 10 63
82b2dba2
ER
1345 for device in $PVDEVICES; do
1346 # if LVM on RAID then device might be copied already in gen_md
9b557a09 1347 [ -e "$DESTDIR/dev/$(basename $device)" ] && continue
82b2dba2
ER
1348 inst $device /dev
1349 done
e7751933 1350 fi
c31050f3 1351
82b2dba2
ER
1352 mount_tmp
1353 if [ "$LVMTOOLSVERSION" = "1" ]; then
1354 add_linuxrc <<-EOF
1355 lvm vgscan -T
1356 lvm vgchange -T -a y $VGVOLUME
1357 EOF
1358 else
1359 echo "cat /etc/lvm.conf > /tmp/lvm.conf" | add_linuxrc
9b557a09
ER
1360 echo "global {" > "$DESTDIR/etc/lvm.conf"
1361 echo " locking_type = 0" >> "$DESTDIR/etc/lvm.conf"
1362 echo " locking_dir = \"/tmp\"" >> "$DESTDIR/etc/lvm.conf"
1363 echo "}" >> "$DESTDIR/etc/lvm.conf"
1364 echo "devices {" >> "$DESTDIR/etc/lvm.conf"
1365 echo " sysfs_scan=0" >> "$DESTDIR/etc/lvm.conf"
82b2dba2 1366 if is_yes "$have_md"; then
9b557a09 1367 echo " md_component_detection = 1" >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1368 fi
1369 if is_yes "$have_dmraid" || is_yes "$have_multipath"; then
9b557a09 1370 echo ' types = [ "device-mapper", 254 ]' >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1371 fi
1372 if [ "$lvm_ignore_devices" ]; then
1373 # TODO: think of merging with lvm dumpconfig output
9b557a09 1374 echo ' filter = [' >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1375 local dev
1376 for dev in $lvm_ignore_devices; do
d8056591 1377 debug "LVM v2: ignore device $dev"
82b2dba2 1378 printf ' "r|^%s.*|",\n' $dev
9b557a09
ER
1379 done >> "$DESTDIR/etc/lvm.conf"
1380 echo ']' >> "$DESTDIR/etc/lvm.conf"
82b2dba2
ER
1381 fi
1382 # XXX filter= must be on one line!
9b557a09
ER
1383 lvm dumpconfig | awk '/filter=/' >> "$DESTDIR/etc/lvm.conf"
1384 echo "}" >> "$DESTDIR/etc/lvm.conf"
fd2dc249 1385
82b2dba2 1386 initrd_gen_devices
bb529f94 1387
82b2dba2 1388 add_linuxrc <<-EOF
6bdc2eeb
ER
1389 export ROOTDEV=$rootdev
1390 export VGVOLUME=$VGVOLUME
82b2dba2
ER
1391 EOF
1392 add_linuxrc <<-'EOF'
6bdc2eeb 1393 # parse rootdev from kernel commandline
fc787d45 1394 if [ "$ROOT" != "$ROOTDEV" ]; then
1395 ROOTDEV=$ROOT
1396 echo "LVM: Using 'root=$ROOTDEV' from kernel commandline"
1397 local tmp=${ROOTDEV#/dev/}
1398 if [ "$tmp" != "$ROOTDEV" ]; then
1399 VGVOLUME=${tmp%/*}
1400 echo "LVM: Using Volume Group '$VGVOLUME'"
6bdc2eeb 1401 fi
fc787d45 1402 fi
6bdc2eeb 1403
3a1d3d88 1404 # disable noise from LVM accessing devices that aren't ready.
f258d870 1405 read printk < /proc/sys/kernel/printk
ef5812f8
AM
1406 if [ ! "$DEBUGINITRD" ]; then
1407 echo 0 > /proc/sys/kernel/printk
1408 fi
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=)
7308edee
ER
1557 LVMTOOLSVERSION=${1#--lvmtoolsversion=}
1558 LVMTOOLSVERSION=${1#--lvmversion=}
82b2dba2
ER
1559 ;;
1560 --lvmtoolsversion|--lvmversion)
1561 LVMTOOLSVERSION=$2
1562 shift
1563 ;;
1564 --without-udev)
1565 USE_UDEV=no
1566 ;;
1567 --with-udev)
1568 USE_UDEV=yes
1569 ;;
1570 --without-dmraid)
1571 USE_DMRAID=no
1572 ;;
1573 --without-multipath)
1574 USE_MULTPATH=no
1575 ;;
af075488 1576 --without-blkid)
1577 USE_BLKID=no
289fbc9b 1578 ;;
82b2dba2
ER
1579 --with=*)
1580 BASICMODULES="$BASICMODULES ${1#--with=}"
1581 ;;
1582 --with)
1583 BASICMODULES="$BASICMODULES $2"
1584 shift
1585 ;;
1586 --version)
1587 echo "$PROGRAM: version $VERSION"
1588 exit 0
1589 ;;
1590 -v)
1591 verbose=-v
1592 ;;
1593 --nocompress)
1594 COMPRESS=no
1595 ;;
1596 --ifneeded)
1597 ifneeded=1
1598 ;;
1599 -f)
1600 force=1
1601 ;;
1602 --preload=*)
1603 PREMODS="$PREMODS ${1#--preload=}"
1604 ;;
1605 --preload)
1606 PREMODS="$PREMODS $2"
1607 shift
1608 ;;
1609 --fs=*)
f4010f7f 1610 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1611 INITRDFS=${1#--fs=}
1612 ;;
1613 --fs)
f4010f7f 1614 warn "Warning: --fs option is obsoleted. Use --initrdfs instead"
82b2dba2
ER
1615 INITRDFS=$2
1616 shift
1617 ;;
1618 --initrdfs=*)
1619 INITRDFS=${1#--initrdfs=}
1620 ;;
1621 --initrdfs)
1622 INITRDFS=$2
1623 shift
1624 ;;
1625 --image-version)
1626 img_vers=yes
1627 ;;
1628 --ide-only-root)
1629 ide_only_root="yes"
1630 ;;
1631 *)
1632 if [ -z "$target" ]; then
1633 target="$1"
1634 elif [ -z "$kernel" ]; then
1635 kernel="$1"
1636 else
1637 usage
1638 fi
1639 ;;
1640 esac
f5db170b 1641
82b2dba2
ER
1642 shift
1643done
1644
1645if [ -z "$target" -o -z "$kernel" ]; then
1646 usage
1647fi
1648
130aadc1 1649if [ ! -f /boot/vmlinuz-"$kernel" ]; then
f4010f7f 1650 warn "/boot/vmlinuz-$kernel doesn't exist, is your /boot mounted?"
130aadc1
ER
1651fi
1652
7308edee
ER
1653pack_version=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d",$1,$2)}')
1654pack_version_long=$(echo "$kernel" | awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}')
82b2dba2
ER
1655
1656if [ -z "$INITRDFS" ]; then
326dd4ad 1657 if [ -z "$FS" ]; then
82b2dba2
ER
1658 # default value
1659 if [ "$pack_version" -ge "002005" ]; then
1660 INITRDFS="initramfs"
f5db170b 1661 else
82b2dba2 1662 INITRDFS="rom"
f5db170b 1663 fi
82b2dba2 1664 else
f4010f7f 1665 warn "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
82b2dba2 1666 INITRDFS="$FS"
f5db170b 1667 fi
82b2dba2 1668fi
f5db170b 1669
82b2dba2
ER
1670if [ "$pack_version" -lt "002006" ]; then
1671 USE_UDEV=no
1672 USE_DMRAID=no
1673fi
f5db170b 1674
82b2dba2
ER
1675if [ "$pack_version" -ge "002005" ]; then
1676 modext=".ko"
1677 insmod="insmod"
1678fi
966c32cc 1679
82b2dba2
ER
1680if is_yes "$USEINSMODSTATIC"; then
1681 insmod="insmod.static"
1682 INSMOD="/sbin/insmod.static"
1683 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
1684 INSMOD="/sbin/insmod.static.modutils"
966c32cc 1685 fi
82b2dba2
ER
1686 if [ ! -f "$INSMOD" ]; then
1687 die "insmod.static requested but /sbin/insmod.static not found!"
966c32cc 1688 fi
82b2dba2 1689fi
966c32cc 1690
82b2dba2
ER
1691case "$INITRDFS" in
1692 ext2)
1693 if [ ! -x /sbin/mke2fs ]; then
1694 die "/sbin/mke2fs is missing"
f5db170b 1695 fi
82b2dba2
ER
1696 ;;
1697 rom|romfs)
1698 if [ ! -x /sbin/genromfs ]; then
1699 die "/sbin/genromfs is missing"
1700 fi
1701 ;;
1702 cram|cramfs)
1703 if [ ! -x /sbin/mkcramfs ]; then
1704 die "/sbin/mkcramfs is missing"
1705 fi
1706 ;;
1707 initramfs)
1708 if [ ! -x /bin/cpio ]; then
1709 die "/bin/cpio is missing"
1710 fi
1711 if [ ! -x /usr/bin/find ]; then
1712 die "/usr/bin/find is missing"
1713 fi
1714 ;;
1715 *)
1716 die "Filesystem $INITRDFS on initrd is not supported"
1717 ;;
1718esac
f5db170b 1719
82b2dba2
ER
1720if [ -n "$img_vers" ]; then
1721 target="$target-$kernel"
1722fi
8bd582f1 1723
82b2dba2
ER
1724if [ -z "$force" -a -f "$target" ]; then
1725 die "$target already exists."
1726fi
c6c6ce01 1727
82b2dba2
ER
1728if [ ! -d "/lib/modules/$kernel" ]; then
1729 die "/lib/modules/$kernel is not a directory."
1730fi
2ffb1734 1731
82b2dba2 1732if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
9f1cb7c2
ER
1733 warn "Tuxonice can't be used in parallel with mainline suspend! Disabling both inclustion to initrd"
1734 USE_SUSPEND=no
1735 USE_TUXONICE=no
82b2dba2 1736fi
ac085800 1737
7992356a 1738if is_yes "$FB_SPLASH" && is_yes "$BOOT_SPLASH"; then
9f1cb7c2
ER
1739 warn "You can't use bootsplash and fbsplash together! Disabling both inclusion to initrd"
1740 FB_SPLASH=no
1741 BOOT_SPLASH=no
82b2dba2 1742fi
994eb509 1743
82b2dba2 1744if [ ! -f /proc/mounts ]; then
f4010f7f 1745 warn "WARNING: /proc filesystem not mounted, may cause wrong results or failure."
82b2dba2 1746fi
6cca3165 1747
82b2dba2
ER
1748if [ -d /usr/lib64 ]; then
1749 _lib=lib64
1750else
1751 _lib=lib
1752fi
d8056591 1753debug "Using libdir: $_lib"
ac085800 1754
82b2dba2
ER
1755cache_modprobe_conf
1756
1757for n in $PREMODS; do
1758 findmodule "$n"
1759done
1760
1761# allow forcing loading SCSI and/or IDE modules
1762if is_yes "$ADDSCSI"; then
1763 find_modules_scsi
1764fi
1765
1766if is_yes "$ADDIDE"; then
1767 find_modules_ide
1768fi
1769
1770find_root "$fstab" || exit
1771debug "Using $rootdev as device for rootfs"
1772
d8056591
ER
1773find_modules_for_devpath "$rootdev"
1774[ -n "$rootdev_add" ] && find_modules_for_devpath "$rootdev_add"
ac085800 1775
82b2dba2 1776findmodule "-$rootFs"
ac085800 1777
82b2dba2
ER
1778for n in $BASICMODULES; do
1779 findmodule "$n"
1780done
4e9eb79c 1781
82b2dba2
ER
1782if is_yes "$USE_TUXONICE"; then
1783 findmodule "-lzf"
1784fi
33d24e12 1785
82b2dba2
ER
1786if is_yes "$FB_SPLASH"; then
1787 findmodule "-evdev"
1788fi
2968c9dd 1789
82b2dba2
ER
1790if [ -n "$ifneeded" -a -z "$MODULES" ]; then
1791 debug "No modules are needed -- not building initrd image."
1792 exit 0
1793fi
c6c6ce01 1794
d8056591 1795DESTDIR=$(mktemp -d -t initrd.XXXXXX) || die "mktemp failed"
9b557a09 1796RCFILE="$DESTDIR/linuxrc"
82b2dba2
ER
1797> "$RCFILE"
1798chmod a+rx "$RCFILE"
9b557a09 1799ln -s linuxrc $DESTDIR/init
e8d178ff 1800
82b2dba2
ER
1801# create dirs that we really need
1802inst_d /{lib,bin,etc,dev{,/pts,/shm},loopfs,var,proc,sys}
e8d178ff 1803
82b2dba2 1804modules_install "$MODULES"
b64f015b 1805
82b2dba2
ER
1806# mknod'ing the devices instead of copying them works both with and
1807# without devfs...
9b557a09
ER
1808mknod "$DESTDIR/dev/console" c 5 1
1809mknod "$DESTDIR/dev/null" c 1 3
1810mknod "$DESTDIR/dev/zero" c 1 5
be2f3ecc 1811
82b2dba2 1812inst /bin/initrd-busybox /bin/initrd-busybox
9b557a09
ER
1813ln -s initrd-busybox $DESTDIR/bin/sh
1814ln -s initrd-busybox $DESTDIR/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
2ffb1734 1815
82b2dba2
ER
1816if is_yes "$USEINSMODSTATIC"; then
1817 inst "$INSMOD" /bin/insmod.static
1818fi
c6c6ce01 1819
82b2dba2
ER
1820add_linuxrc <<EOF
1821#!/bin/sh
1822# initrd generated by:
1823# $RCSID
c6c6ce01 1824
82b2dba2
ER
1825EOF
1826mount_proc
1827add_linuxrc <<-'EOF'
3a1d3d88 1828 read CMDLINE < /proc/cmdline; export CMDLINE
c6c6ce01 1829
82b2dba2
ER
1830 for arg in $CMDLINE; do
1831 if [ "${arg}" = "debuginitrd" ]; then
1832 DEBUGINITRD=yes
1833 fi
1834 if [ "${arg##debuginitrd=}" != "${arg}" ]; then
1835 DEBUGINITRD=${arg##debuginitrd=}
1836 fi
fc787d45 1837 if [ "${arg##root=}" != "${arg}" ]; then
1838 ROOT=${arg##root=}
1839 fi
82b2dba2 1840 done
c6c6ce01 1841
82b2dba2
ER
1842 # make debugshell() invoke subshell if $DEBUGINITRD=sh
1843 if [ "$DEBUGINITRD" = "sh" ]; then
1844 debugshell() {
e2405b29
AM
1845EOF
1846if is_yes "$RUN_SULOGIN_ON_ERR"; then
1847add_linuxrc <<-'EOF'
1848 echo "debug shell disabled by /etc/sysconfig/system:RUN_SULOGIN_ON_ERR setting"
1849EOF
1850else
1851add_linuxrc <<-'EOF'
1852 sh
1853EOF
1854fi
1855add_linuxrc <<-'EOF'
82b2dba2
ER
1856 }
1857 else
1858 debugshell() {
1859 :
1860 }
1861 fi
e934d044 1862
82b2dba2
ER
1863 if [ "$DEBUGINITRD" ]; then
1864 set -x
cff3058d 1865 fi
82b2dba2 1866EOF
2df2e995 1867
fe280785 1868modules_add_linuxrc $MODULES
82b2dba2
ER
1869
1870# TODO: rewrite for busybox
1871#if [ -n "$loopDev" ]; then
1872# if [ ! -d /initrd ]; then
1873# mkdir /initrd
1874# fi
1875#
9b557a09
ER
1876# cp -a "$loopDev" "$DESTDIR/dev"
1877# cp -a "$rootdev" "$DESTDIR/dev"
82b2dba2
ER
1878# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1879# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1880# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1881# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
1882#fi
2b1a3707 1883
1606e343
AM
1884if is_yes "$USE_UDEV"; then
1885 initrd_gen_udev
1886fi
1887
2ce7656a 1888if is_yes "$USE_SUSPEND"; then
22b0c9f4
AM
1889 initrd_gen_suspend
1890fi
1891
1cd2aabd
ER
1892if is_yes "$USE_TUXONICE"; then
1893 initrd_gen_tuxonice
2df2e995
AM
1894fi
1895
c083ae23 1896if is_yes "$have_dmraid" ]; then
882472ae
ER
1897 initrd_gen_dmraid
1898fi
1899
c083ae23 1900if is_yes "$have_multipath"; then
2cc3ae8b
ER
1901 initrd_gen_multipath
1902fi
1903
289fbc9b 1904if is_yes "$USE_BLKID" ]; then
1905 initrd_gen_blkid
1906fi
1907
69b1e935 1908if is_yes "$have_nfs"; then
2df2e995 1909 initrd_gen_nfs
df738638
ER
1910elif is_yes "$USERAIDSTART" && is_yes "$have_md"; then
1911 initrd_gen_md
69b1e935 1912 if is_yes "$have_lvm"; then
2df2e995 1913 initrd_gen_lvm
bfea009a 1914 else
4828c787 1915 initrd_gen_setrootdev
2df2e995 1916 fi
69b1e935 1917elif is_yes "$have_lvm"; then
2df2e995 1918 initrd_gen_lvm
2b1a3707 1919else
4828c787 1920 initrd_gen_setrootdev
7c38b114
AF
1921fi
1922
5101a385 1923# additional devs always needed
9b557a09 1924[ ! -e "$DESTDIR/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1925
f8f9e56d 1926if [ "$INITRDFS" = "initramfs" ]; then
034fdd5d 1927 inst_d /newroot
6d2c63ed
ER
1928 if [ "$rootdev" = "/dev/nfs" ]; then
1929 echo "rootfs on NFS root=/dev/nfs"
1930 else
1931 [ ! -e "$DESTDIR/$rootdev" ] && inst $rootdev /dev
1932 fi
e4b07ddc 1933 # Parsing root parameter
81d53704 1934 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
c6c6ce01 1935 add_linuxrc <<-'EOF'
fc787d45 1936 device=/dev/no_partition_found
1937 eval "$(busybox awk -v c="$ROOT" '
675e6f41 1938 BEGIN {
1939 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1940 num_pattern = "[0-9a-f]" num_pattern_short;
1941 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1942 partition = "no_partition_found";
1943 min = -1; maj = -1;
1944
675e6f41 1945 sub("^0x", "", c);
1946 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1947 if (c ~ "^" num_pattern "$") {
1948 maj = sprintf("%s",substr(c,1,2));
1949 min = sprintf("%s",substr(c,3));
1950 }
1951 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1952 if (c ~ "^" dev_pattern "$") partition = c;
c6c6ce01 1953 }
df391e6f 1954
675e6f41 1955 $4 ~ partition { maj = $1; min = $2; }
1956 $1 ~ maj && $2 ~ min { partition = $4; }
c6c6ce01 1957
675e6f41 1958 END {
1959 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
1960 partition, maj, min);
1961 }
1962 ' /proc/partitions)"
c6c6ce01
ER
1963 if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
1964 mknod $device b $maj $min
1965 fi
1966 EOF
92a4990b 1967
c6c6ce01 1968 add_linuxrc <<-EOF
f5db170b
ER
1969 rootdev=$rootdev
1970 rootfs=$rootFs
1971 EOF
1972
1973 add_linuxrc <<-'EOF'
1974 if [ "$device" = '/dev/no_partition_found' ]; then
1975 device=$rootdev
c6c6ce01 1976 fi
e620b426 1977
f5db170b
ER
1978 mount -t $rootfs -r $device /newroot
1979 init="$(echo "$CMDLINE" | busybox awk '/init=\// { gsub(/.*init=/,NIL,$0); gsub(/ .*/,NIL,$0); print }')"
1980 if [ -z "$init" -o ! -x "/newroot$init" ]; then
c6c6ce01
ER
1981 init=/sbin/init
1982 fi
b64f015b 1983 EOF
f1a5a1b0 1984
f5db170b
ER
1985 umount_all
1986 busybox_applet switch_root
1987 add_linuxrc <<-'EOF'
1988 exec switch_root /newroot $init
1989
1990 echo "Error! initramfs should not reach this place."
c6c6ce01
ER
1991 echo "It probably means you've got old version of busybox, with broken"
1992 echo "initramfs support. Trying to boot anyway, but won't promise anything."
f1a5a1b0 1993
f5db170b 1994 exec chroot /newroot $init
f1a5a1b0 1995
f5db170b 1996 echo "Failed to chroot!"
c6c6ce01 1997 EOF
f5db170b
ER
1998 # we need /init being real file, not symlink, otherwise the initramfs will
1999 # not be ran by pid 1 which is required for switch_root
9b557a09 2000 mv $DESTDIR/linuxrc $DESTDIR/init
d8056591 2001 ln -s init $DESTDIR/linuxrc
b64f015b
ER
2002else
2003 # other than initramfs
2004 umount_all
f8f9e56d
AM
2005fi
2006
b7feffb3
ER
2007if is_yes "$FB_SPLASH"; then
2008 initrd_gen_fbsplash
2009fi
2010
d8056591 2011IMAGE=$(mktemp -t initrd.img-XXXXXX) || die "mktemp failed"
51dc1fe6
AM
2012
2013debug "Creating $INITRDFS image $IMAGE"
2ad94d8a 2014case "$INITRDFS" in
8b1e4ac7 2015 ext2)
d8056591
ER
2016 IMAGESIZE=$(du -ks $DESTDIR | awk '{print int(($1+1023+512)/1024)*1024}')
2017 debug "ext2 image size: $IMAGESIZE ($DESTDIR)"
73edc0c1 2018 if [ "$IMAGESIZE" -gt 4096 ]; then
19afb117 2019 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
73edc0c1
ER
2020 fi
2021
2022 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
2023 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
2024 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
2025
d8056591
ER
2026 local tmpmnt=$(mktemp -d -t initrd.mnt-XXXXXX)
2027 debug "Mounting ext2 image $IMAGE to $tmpmnt"
73edc0c1 2028 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
d8056591
ER
2029 # We don't need this directory, so let's save space
2030 rm -rf "$tmpmnt"/lost+found
73edc0c1 2031
d8056591
ER
2032 debug "Copy recursively $DESTDIR -> $tmpmnt"
2033 cp -a $DESTDIR/* $tmpmnt
35164381 2034 umount "$IMAGE"
d8056591
ER
2035 rmdir "$tmpmnt"
2036
8b1e4ac7 2037 ;;
c1548a54 2038 rom|romfs)
d8056591 2039 genromfs -f "$IMAGE" -d "$DESTDIR" -V "PLD initrd for kernel $kernel"
cdf1e7c9 2040 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
d8056591 2041 debug "Image size for romfs: ${IMAGESIZE}KiB ($IMAGE)"
a8b63949 2042 if [ "$IMAGESIZE" -gt 4096 ]; then
19afb117 2043 warn "Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
a8b63949 2044 fi
8b1e4ac7 2045 ;;
c1548a54 2046 cram|cramfs)
d8056591 2047 mkcramfs "$DESTDIR" "$IMAGE"
8b1e4ac7 2048 ;;
48413b7f 2049 initramfs)
d8056591 2050 (cd $DESTDIR; find . | cpio --quiet -H newc -o > "$IMAGE")
48413b7f 2051 ;;
8b1e4ac7 2052 *)
7758e45c 2053 echo "Filesystem $INITRDFS not supported by $PROGRAM";
c31050f3 2054esac
bb529f94 2055
82474db9 2056if is_yes "$COMPRESS"; then
d8056591
ER
2057 local tmp=$(mktemp "$target".XXXXXX) || die "mktemp failed"
2058 debug "Compressing $target"
2059 gzip -9 < "$IMAGE" > "$tmp"
2060 mv -f "$tmp" "$target"
bb529f94 2061else
7d2fc5eb 2062 cp -a "$IMAGE" "$target"
bb529f94 2063fi
5b71959c 2064
7992356a 2065# XXX. check if bootsplash can output data to tmp dir not directly to initramfs image.
5b71959c 2066if is_yes "$BOOT_SPLASH"; then
f5db170b 2067 initrd_gen_bootsplash "$target"
5b71959c
AM
2068fi
2069
d8056591 2070rm -rf "$DESTDIR" "$IMAGE"
ac085800
ER
2071
2072# vim:ts=4:sw=4:noet:fdm=marker
This page took 0.468436 seconds and 4 git commands to generate.