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