]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- detect physical devices for dm-multipath
[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:
10# - make udev start before insomds
11# - make proper use of USE_UDEV - don't copy fules if USE_UDEV is off no!
12# - sanitize - one mounting of /proc and /sys at the begining and one umount at the end!
aebe301c 13#
c31050f3 14
28eec2b1 15RCSID='$Id$'
ca2c2012
ER
16R=${RCSID#* * }; VERSION=${R%% *}
17PROGRAM=${0##*/}
bb529f94
JK
18
19. /etc/rc.d/init.d/functions
1cea325b 20. /etc/geninitrd/functions
bb529f94
JK
21
22COMPRESS="yes"
2ad94d8a
AF
23# INITRDFS is set later (catch obsoleted FS option)
24#INITRDFS="rom"
6bd433bc 25USERAIDSTART="yes"
d3fa6ec7 26USEMDADMSTATIC="no"
b2e62ae1 27USEINSMODSTATIC="no"
4ef98747 28USE_SUSPEND="yes"
1cd2aabd 29USE_TUXONICE="yes"
7c38b114 30uselvm="no"
6fe19d5b 31usenfs="no"
10c3df06
MM
32# it should be safe to remove scsi_mod from here, but I'm not sure...
33PRESCSIMODS="-scsi_mod unknown -sd_mod"
64497ebb
AM
34PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
35PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
bb529f94
JK
36target=""
37kernel=""
38force=""
39verbose=""
40MODULES=""
41img_vers=""
f121024f 42modulefile=""
bb529f94 43fstab="/etc/fstab"
0868f49f
AF
44insmod="insmod"
45modext=".o"
4e9eb79c 46rootdev_nr=0
738c05d8
ER
47# device node for rootfs from fstab
48rootdev=""
5b71959c
AM
49# default bootsplash is off, if it have to be on, install bootsplash package
50BOOT_SPLASH=no
e4b07ddc 51# default same as bootsplash, if on install splashutils and some splashutils theme
52FB_SPLASH=no
53# defualt we don't use udev to make nodes for static modules, as per default
54# PLD loads the modules needed to mount and boot
55PROBESTATICMODULES=no
bb529f94 56
8bd582f1
ER
57# internal variables
58# is /dev on tmpfs
59tmpfs_dev=no
60# is /proc/devices entries already created
61proc_partitions=no
f155a80b
ER
62# dmraid component devices of rootfs is on dmraid
63dmraid_devices=''
9baf4f3f
ER
64# if we should init dm-multipath at boot
65use_multipath=no
b4d9d384 66
447ff04b 67if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
1606e343 68 USE_UDEV="yes"
1606e343
AM
69 . /etc/udev/udev.conf
70fi
882472ae
ER
71
72if [ -x /sbin/dmraid-initrd ]; then
73 USE_DMRAID="yes"
74fi
ac085800 75
2cc3ae8b
ER
76if [ -x /sbin/multipath ]; then
77 USE_MULTIPATH="yes"
78fi
79
bb529f94 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]"
ac085800 92 echo " <initrd-image> <kernel-version>"
553786c4
ER
93 echo ""
94 echo "example:"
00eaa938 95 echo " $PROGRAM -f --initrdfs=rom /boot/initrd-$uname_r.gz $uname_r"
7d2fc5eb 96 exit 1
bb529f94
JK
97}
98
94769f11 99debug() {
f155a80b 100 [ -n "$verbose" ] && echo >&2 "$*"
94769f11 101}
aa69da6e 102
bf6c3fcb
ER
103# aborts program abnormally
104die() {
b5f5c089 105 local rc=${2:-1}
bf6c3fcb
ER
106 echo >&2 "$PROGRAM: ERROR: $1"
107 exit $rc
108}
109
9299682f
ER
110# Checks if busybox has support for APPLET(s)
111# Exits from geninitrd if the support is not present.
112#
113# NB! XXX do not output to STDOUT, it will appear in initrd images in some cases!
114busybox_applet() {
115 local err=0
116
117 if [ -z "$busybox_functions" ]; then
9b1373fb
ER
118 local tmp=$(/bin/initrd-busybox 2>&1)
119
120 # BusyBox v1.1.3 says applet not found if it's not called 'busybox'.
121 if [[ "$tmp" = *applet\ not\ found* ]]; then
122 local t=$(mktemp -d)
123 ln -s /bin/initrd-busybox $t/busybox
124 local tmp=$($t/busybox 2>&1)
125 rm -rf $t
126 fi
127
128 busybox_functions=$(echo "$tmp" | \
9299682f
ER
129 sed -ne '/Currently defined functions:/,$p' | \
130 xargs | sed -e 's,.*Currently defined functions: ,,'
131 )
132 fi
133 for applet in $*; do
134 local have
135 # try cache
136 eval have='$'busybox_have_$applet
137 if [ -z "$have" ]; then
138 have=$(echo "$busybox_functions" | egrep -c "( |^)$applet(,|$)")
139 if [ "$have" = 0 ]; then
140 echo >&2 "This setup requires busybox-initrd compiled with applet '$applet' support"
141 err=1
142 fi
143 eval busybox_have_$applet=$have
144 fi
145 done
146 if [ $err = 1 ]; then
00eaa938 147 die "Aborted"
9299682f
ER
148 fi
149}
150
10c3df06
MM
151find_depmod () {
152 typeset mods module f level depfile first
153
154 depfile=/lib/modules/$kernel/modules.dep
ac085800 155
00eaa938 156 if [ ! -f $depfile ]; then
9e1ceabe 157 die "No $depfile! Run depmod and rerun $PROGRAM."
f6de9380 158 fi
ac085800 159
0868f49f 160 # prepend / if no path given, append $modext.gz if not given,
10c3df06 161 # quote /
3b00e899 162 origmodule="$2"
10c3df06 163 module=$(echo "$2" | \
ac085800
ER
164 awk '/\// {print;next} {print "/" $0}' | \
165 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
166 awk '{gsub("/","\\/");print}')
10c3df06
MM
167 mods=$(awk '
168BEGIN { here = 0 }
169/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
170/:/ { here = 0 }
171/(.*)/ { gsub(/\\/," "); if (here) print }
4fd11db9
AF
172' $depfile | xargs)
173
0868f49f 174 # fallback to $modext
4fd11db9 175 if [ "$mods" = "" ] ; then
00eaa938 176 module=$(echo "$module" | awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
740d6215 177 # ") - vim
ac085800 178 fi
00eaa938 179
4fd11db9
AF
180 mods=$(awk '
181BEGIN { here = 0 }
182/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
183/:/ { here = 0 }
184/(.*)/ { gsub(/\\/," "); if (here) print }
10c3df06
MM
185' $depfile | xargs)
186
187 if [ "$mods" = "" ] ; then
188 if [ "$1" != silent ] ; then
94769f11 189 echo >&2 "$origmodule: module not found in $depfile"
10c3df06 190 fi
00eaa938 191 if ! is_no "$EXIT_IF_MISSING"; then
fd2dc249
AF
192 exit 1
193 else
94769f11 194 echo >&2 "If $origmodule isn't compiled in kernel then this initrd may not start your system."
fd2dc249 195 fi
10c3df06 196 fi
ac085800 197
10c3df06
MM
198 level=$3
199 if [ "$level" = "" ] ; then
200 level=0
201 fi
94769f11 202 level=$((level + 1))
10c3df06 203 if [ $level -gt 20 ] ; then
00eaa938 204 die "$origmodule: cycle in $depfile"
10c3df06 205 fi
ac085800 206
10c3df06
MM
207 first=
208 for f in $mods ; do
209 if [ "$first" = "" ] ; then
210 first=$f
413878f8 211 else
10c3df06 212 find_depmod $1 $f $level
9c9f7cdb 213 fi
aa69da6e 214 done
ac085800 215
10c3df06 216 echo $first
aa69da6e 217}
218
10c3df06
MM
219addmodule() {
220 fmPath=$1
221 skiperrors=$2
222
223 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
224 if [ -n "$skiperrors" ]; then
225 return
226 fi
227
00eaa938 228 die "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)"
10c3df06
MM
229 fi
230
231 # only need to add each module once
232 # quote /
233 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
234 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
235 MODULES="$MODULES $fmPath"
236 fi
81de8443
AF
237}
238
bb529f94 239findmodule() {
413878f8 240 skiperrors=""
241 modName=$1
10c3df06 242
94769f11 243 if [ ${modName#-} != ${modName} ]; then
413878f8 244 skiperrors=1
94769f11 245 modName=${modName#-}
413878f8 246 fi
bb529f94 247
10c3df06 248 # what's that?
413878f8 249 if [ "$modName" = "pluto" ]; then
250 findmodule fc4
251 findmodule soc
252 fi
253 if [ "$modName" = "fcal" ]; then
254 findmodule fc4
255 findmodule socal
256 fi
bb529f94 257
10c3df06 258 if [ -n "$skiperrors" ]; then
94769f11 259 allModulesToFind=$(find_depmod silent $modName)
10c3df06 260 else
94769f11
ER
261 allModulesToFind=$(find_depmod normal $modName)
262 if [ $? != 0 ]; then
10c3df06 263 exit 1
413878f8 264 fi
413878f8 265 fi
ac085800 266
94769f11
ER
267 for mod in $allModulesToFind; do
268 mod=$(echo $mod | awk '{sub(/^\/lib\/modules\/[^\/]*\//, ""); print}')
10c3df06
MM
269 addmodule $mod "$skiperrors"
270 done
bb529f94
JK
271}
272
034fdd5d
ER
273# install a file to temporary mount image.
274# it will operate recursively (copying directories)
275# and will symlink destinations if source is symlink.
bb529f94 276inst() {
dab92b1d 277 if [ "$#" -lt "2" ];then
1775ba37 278 die 'Usage: inst <file> $MNTIMAGE<destination>'
c31050f3 279 fi
1775ba37 280 cp -HR "$1" "$MNTIMAGE$2"
bb529f94
JK
281}
282
dab92b1d 283inst_d() {
034fdd5d 284 if [ "$#" = "0" ];then
dab92b1d 285 die 'Usage: inst_d $MNTIMAGE<destination> $MNTIMAGE<destination>'
034fdd5d
ER
286 fi
287 for dir in "$@"; do
034fdd5d
ER
288 install -d "$MNTIMAGE$dir"
289 done
290}
291
7c38b114 292find_modules_softraid() {
ac085800 293 if [ -f /etc/mdadm.conf ]; then
94769f11 294 debug "Finding RAID details using mdadm for rootdev=$1"
ac085800
ER
295 eval `/sbin/mdadm -v --examine --scan --config=/etc/mdadm.conf | awk -v rootdev="$1" '
296 BEGIN {
297 found = "no";
298 dev_list = "";
299 raidlevel = ""
300 rootdev_devfs = rootdev;
301 if (rootdev ~ /\/dev\/md\/[0-9]/) {
302 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
303 }
514a668a 304 }
ac085800
ER
305
306 /^ARRAY/ {
307 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
308 raidlevel=$3;
309 gsub(/level=/,NUL,raidlevel);
310 if (raidlevel ~ /^raid([0-6]|10)/) {
311 gsub(/raid/,NUL,raidlevel);
312 };
313 found="yes";
314 getline x;
315 if (x ~ /devices=/) {
316 dev_list = x;
317 gsub(".*devices=", NUL, dev_list);
318 gsub(",", " ", dev_list);
319 }
320 }
56946560 321 }
ac085800
ER
322
323 END {
324 print "raidfound=" found;
325 print "raidlevel=" raidlevel;
326 print "dev_list=\"" dev_list "\"";
327 }'`
328 fi
7c38b114 329
59846acb 330 if [ "$raidfound" != "yes" -a -f /etc/raidtab ]; then
00eaa938 331 die "raidtools are not longer supported. Please migrate to mdadm setup!"
809cc4cc 332 fi
ac085800 333
7c38b114
AF
334 if is_yes "$raidfound" ; then
335 case "$raidlevel" in
bf17c86c 336 [01]|10)
7c38b114
AF
337 findmodule "raid$raidlevel"
338 ;;
bf17c86c
AM
339 [456])
340 findmodule "-raid$raidlevel"
341 findmodule "-raid456"
342 ;;
7c38b114
AF
343 linear)
344 findmodule "linear"
345 ;;
346 *)
94769f11 347 echo >&2 "raid level $number (in mdadm config) not recognized"
7c38b114
AF
348 ;;
349 esac
88614cd1 350 else
00eaa938 351 die "RAID devices not found for \"$1\", check your configuration!"
7c38b114 352 fi
4e9eb79c
AM
353
354 rootdev_nr=$(( $rootdev_nr + 1 ))
355 eval "rootdev${rootdev_nr}=\"$1\""
356 eval "dev_list${rootdev_nr}=\"${dev_list}\""
ac085800 357
7c38b114 358 for device in $dev_list; do
a8007847 359 find_modules_for_device $device
7c38b114
AF
360 done
361}
362
363find_modules_scsi() {
364 for n in $PRESCSIMODS; do
365 if [ "X$n" = "Xunknown" ] ; then
7c38b114 366 if [ -f "$modulefile" ]; then
d4a15d5f 367 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
368 for n in $scsimodules; do
369 # for now allow scsi modules to come from anywhere. There are some
370 # RAID controllers with drivers in block
371 findmodule "$n"
372 done
373 fi
374 else
375 findmodule "$n"
376 fi
377 done
84df18b8 378 findmodule "-scsi_wait_scan"
7c38b114
AF
379}
380
381find_modules_ide() {
f0615744
ER
382 local rootblkdev
383
384 # set blockdev for rootfs (hda, sdc, ...)
385 rootblkdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
ac085800 386
ac085800 387 if [ "$pack_version_long" -lt "002004021" ]; then
94769f11 388 debug "Finding IDE modules for kernels <= 2.4.20"
ac085800
ER
389 for n in $PREIDEMODSOLD; do
390 findmodule "$n"
391 done
64497ebb 392 else
ac085800
ER
393 tryauto=1
394 for n in $PREIDEMODS; do
395 if [ "X$n" = "Xunknown" ] ; then
396 if [ -f "$modulefile" ]; then
94769f11 397 debug "Finding IDE modules using ide_hostadapter"
ac085800
ER
398 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
399 for na in $idemodules; do
400 tryauto=0;
401 findmodule "$na"
402 done
403 fi
64497ebb 404
ac085800
ER
405 if [ "$tryauto" -eq 1 ]; then
406 # If tryauto {{{
407 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
94769f11 408 debug "Finding IDE modules using PCI ID database"
ac085800
ER
409 # Finding IDE modules using PCI ID database {{{
410 if is_yes "${ide_only_root}"; then
f0615744
ER
411 if [ -f /sys/block/${rootblkdev}/device/../../vendor -a -f /sys/block/${rootblkdev}/device/../../device ]; then
412 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../vendor)"
413 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootblkdev}/device/../../device)"
ac085800 414 searchpciid="${vendorid}${deviceid}"
f0615744
ER
415 elif [ -f /proc/ide/${rootblkdev}/../config ]; then
416 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootblkdev}/../config)"
ac085800
ER
417 fi
418 fi
419
420 if [ -z "${searchpciid}" ]; then
421 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
422 fi
423
424 idemodules=""
425
426 for nb in $searchpciid; do
427 eval `awk -v pciid="$nb" '{
428 gsub("\t"," ");
429 gsub(" +", " ");
430 gsub("^ ","");
431 if (/^[\t ]*#/)
432 next;
433 compmod = $1 ""; # make sure comparison type will be string
434 # cause pci IDs are hexadecimal numeric
435 if (compmod == pciid) {
436 module=$2;
437 # min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
438 # max_kernel=$4; #
439 exit 0;
440 }
441 }
442
443 END {
444 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
445 }' /usr/share/pci-database/ide.pci`
446 [ -n "$module" ] && idemodules="$idemodules $module"
447 done
448 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
449 new_idemodules=""
450 for nc in idemodules; do
451 new_idemodules="$nc $new_idemodules"
452 done
453 idemodules="${new_idemodules}"
454 fi
455
456 if [ -z "$idemodules" ]; then
457 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
458 idemodules="ide-generic"
459 fi
460
461 # }}}
462 for nd in $idemodules; do
463 findmodule "-$nd"
464 done
465 # }}}
466 # else tryauto {{{
467 else
468 [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
469 [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
470 echo "Automatic IDE modules finding not available."
471 fi
472 # }}}
473 fi
474 else
475 findmodule "$n"
5de40f1f 476 fi
ac085800 477 done
64497ebb 478 fi
7c38b114
AF
479}
480
a7fce633
ER
481# return true if node is lvm node
482_check_lvm() {
483 local node="$1"
484 if [ ! -e "$node" ]; then
94769f11 485 echo >&2 "WARNING: check_lvm(): node $node doesn't exist!"
a7fce633
ER
486 return 1
487 fi
488
489 # block-major-58 is lvm1
490 ls -lL "$node" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'
491 rc=$?
492
493 if [ $rc = 0 ]; then
94769f11 494 debug "$node is LVM1 node"
a7fce633
ER
495 # is lvm1
496 return 0
497 fi
498
499 /sbin/lvm lvdisplay "$node" > /dev/null 2>&1
500 rc=$?
501 if [ $rc -gt 127 ]; then
502 # lvdisplay terminated by signal! most likely it segfaulted.
00eaa938 503 die "Unexpected exit from 'lvdisplay $node': $rc - are your lvm tools broken?"
a7fce633
ER
504 fi
505
506 if [ $rc = 0 ]; then
94769f11 507 debug "$node is lvm2 node"
a7fce633 508 else
94769f11 509 debug "$node is not any lvm node"
a7fce633
ER
510 fi
511 return $rc
512}
513
bc0d6f2d 514# find modules for $devpath
a8007847 515find_modules_for_device() {
bc0d6f2d
ER
516 local devpath="$1"
517 if [ -z "$devpath" ]; then
a8007847 518 die "No argument passed to find_modules_for_device() - is your /etc/fstab correct?"
f6536797 519 fi
ac085800 520
bc0d6f2d
ER
521 # /dev/dm-3 -> /dev/mapper/sil_ahbgadcbchfc3
522 case "$devpath" in
523 /dev/dm-*)
524 devpath=$(dm_longname "$devpath")
525 ;;
526 esac
9baf4f3f 527 debug "find_modules_for_device($devpath)"
bc0d6f2d 528
bc0d6f2d 529 if is_yes "`echo "$devpath" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
5c4cec75 530 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
00eaa938 531 die "root on NFS but /usr/bin/pcidev not found. Please install correct pci-database package and rerun $PROGRAM."
6fe19d5b 532 fi
5c4cec75
AM
533 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
534 for m in $NFS_ETH_MODULES; do
ac085800 535 findmodule "$m"
6fe19d5b
AM
536 done
537 findmodule "-ipv4"
ac085800 538 findmodule "nfs"
6fe19d5b 539 usenfs="yes"
9baf4f3f
ER
540 echo >&2 "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel"
541 echo >&2 "or you will have problems like init(xx) being child process of swapper(1)."
d9179777
ER
542 return
543 fi
544
9baf4f3f 545 if [[ "$devpath" == /dev/md/* ]]; then
bc0d6f2d 546 find_modules_softraid "$devpath"
d9179777
ER
547 return
548 fi
549
9baf4f3f 550 if [[ "$devpath" == /dev/mapper/* ]] && is_yes "$USE_MULTIPATH"; then
aabf157c 551 # remove partition
9baf4f3f 552 local disk=${devpath%p[0-9]*}
aabf157c 553 local id=${disk#/dev/mapper/}
9baf4f3f 554
aabf157c
ER
555 local info=$(multipath -l $id)
556 if [ "$info" ]; then
557 debug "have multipath"
9baf4f3f 558 use_multipath=yes
aabf157c
ER
559 local dev phydevs=$(echo "$info" | awk '$2 ~ /^[0-9]+:[0-9]+:[0-9]+:[0-9]+$/{printf("/dev/%s\n", $3)}')
560 for dev in $phydevs; do
561 find_modules_for_device $dev
562 done
563
564 local hw hwhandlers=$(echo "$info" | awk '/hwhandler=1/{sub(/.*hwhandler=1 /, ""); sub(/\]$/, ""); print}')
565 for hw in $hwhandlers; do
566 findmodule "dm-$hw"
567 done
9baf4f3f 568
aabf157c
ER
569 local target targets=$(echo "$info" | awk '/prio=/{print $2}' | sort -u)
570 for target in $targets; do
571 findmodule "dm-$target"
572 done
573
574 findmodule "dm-mod"
9baf4f3f 575 return
9baf4f3f
ER
576 fi
577
578 # fallback
579 fi
580
d9179777 581 if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
7c38b114 582 find_modules_scsi
d9179777
ER
583 return
584 fi
585
586 if is_yes "`echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
bc0d6f2d 587 find_modules_ide "$devpath"
d9179777
ER
588 return
589 fi
590
d9179777 591 if is_yes "$(echo "$devpath" | awk '/^\/dev\/mapper\/(sil|hpt37x|hpt45x|isw|lsi|nvidia|pdc|sil|via|dos)_/ { print "yes"; }')"; then
bc0d6f2d
ER
592 # dmraid nodes taken from: `dmraid -l` output
593 if [ ! -x /usr/sbin/dmraid ]; then
594 die "root on dmraid but /usr/sbin/dmraid not found."
595 fi
596
597 # XXX dmraid could say to us that /dev/dm-3 consists from /dev/sda, /dev/sdb
598
599 # get blockdev itself (without partition)
600 local node blockdev
601 blockdev=${devpath%%[0-9]*}
602 blockdev=${blockdev#/dev/mapper/}
603 for node in $(dmraid -r -cdevpath,raidname |awk -F, -vv="$blockdev" '{if ($2 == v) print $1}'); do
a8007847 604 find_modules_for_device $node
f155a80b 605 dmraid_devices="$dmraid_devices $node"
bc0d6f2d
ER
606 done
607
608 # XXX probably should detect
609 findmodule "dm-mirror"
d9179777
ER
610 return
611 fi
bc0d6f2d 612
d9179777 613 if is_yes "`echo "$devpath" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
7c38b114 614 findmodule "DAC960"
d9179777
ER
615 return
616 fi
617
618 if is_yes "`echo "$devpath" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
7c38b114 619 findmodule "cpqarray"
d9179777
ER
620 return
621 fi
622
623 if is_yes "`echo "$devpath" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
7c38b114 624 findmodule "cciss"
d9179777
ER
625 return
626 fi
627
628 if is_yes "`echo "$devpath" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
ac085800 629 find_modules_ide
7c38b114 630 findmodule "ataraid"
d4a15d5f 631 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
632 if -n "$ataraidmodules" ; then
633 # FIXME: think about modules compiled in kernel
00eaa938 634 die "ataraid_hostadapter alias not defined in $modulefile! Please set it and run $PROGRAM again."
7c38b114
AF
635 fi
636 for n in $ataraidmodules; do
637 findmodule "$n"
638 done
d9179777
ER
639 return
640 fi
641
7c38b114 642 # check to see if we need to set up a loopback filesystem
d9179777 643 if is_yes "`echo "$devpath" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
00eaa938 644 die "Sorry, root on loop device isn't supported."
7c38b114
AF
645 # TODO: rewrite for bsp and make nfs ready
646 if [ ! -x /sbin/losetup ]; then
00eaa938 647 die "losetup is missing"
7c38b114 648 fi
bc0d6f2d 649 key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
7c38b114 650 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
bc0d6f2d 651 die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the geninitrd man page for more information"
7c38b114
AF
652 fi
653
654 line="`awk '/'$key'/ { print $0; }' $fstab`"
655 loopDev="$(echo $line | awk '{print $3}')"
656 loopFs="$(echo $line | awk '{print $4}')"
657 loopFile="$(echo $line | awk '{print $5}')"
658
659 BASICMODULES="$BASICMODULES -loop"
660 findmodule "-$loopFs"
661 BASICMODULES="$BASICMODULES -${loopFs}"
d9179777
ER
662 return
663 fi
664
665 if _check_lvm "$devpath"; then
bc0d6f2d 666 node="$devpath"
f6536797 667
9f2d32ed 668 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
00eaa938 669 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 670 fi
ac085800
ER
671 if [ -z "$LVMTOOLSVERSION" ] ; then
672 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}')
673 if [ -z "$LVMTOOLSVERSION" ] ; then
00eaa938 674 die "Can't determine LVM tools version. Please set LVMTOOLSVERSION and rerun $PROGRAM."
ac085800 675 fi
77bcfc68 676 fi
decd277c 677 if [ -z "$PVDEVICES" ] ; then
f6536797 678 VGVOLUME=$(/sbin/lvdisplay -c "$node" 2> /dev/null | awk -F":" ' { print $2 } ')
d2dc16e9 679 PVDEVICES=$(/sbin/pvdisplay -c 2>/dev/null | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
decd277c 680 fi
7c38b114
AF
681 if [ -n "$PVDEVICES" ] ; then
682 for device in $PVDEVICES; do
a8007847 683 find_modules_for_device $device
7c38b114
AF
684 done
685 else
00eaa938 686 die "I wasn't able to find PV (via lvdisplay and pvdisplay). You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
7c38b114 687 fi
e0c502bb 688 if [ "$LVMTOOLSVERSION" = "2" ]; then
ac085800 689 findmodule "-dm-mod"
e0c502bb 690 elif [ "$LVMTOOLSVERSION" = "1" ]; then
ac085800
ER
691 findmodule "-lvm"
692 findmodule "-lvm-mod"
93d781d1 693 else
00eaa938 694 die "LVM version $LVMTOOLSVERSION is not supported yet."
93d781d1 695 fi
94769f11 696 debug "LVM $LVMTOOLSVERSION enabled"
7c38b114 697 uselvm="yes"
d9179777 698 return
7c38b114
AF
699 fi
700}
701
9ed6e1db
AM
702firmware_install_module_pre() {
703 module="$1"
704 linuxrc="$2"
705 firmware_files="$3"
706
94769f11 707 debug "Adding Firmwares ($firmware_files) to initrd for module $module"
034fdd5d
ER
708 inst_d /proc
709 inst_d /sys
9ed6e1db
AM
710 # firmware not yet installed
711 if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then
034fdd5d 712 inst_d /lib/firmware
9ed6e1db
AM
713cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh"
714#!/bin/sh -e
8639f99a
AM
715echo 1 > /sys$DEVPATH/loading
716cat "/lib/firmware/$FIRMWARE" > /sys$DEVPATH/data
717echo 0 > /sys$DEVPATH/loading
718exit 0
9ed6e1db 719EOF
94769f11 720 chmod 755 "$MNTIMAGE/lib/firmware/firmware.sh"
9ed6e1db
AM
721 fi
722
723 for firmware in $firmware_files; do
dcc1b914 724 inst /lib/firmware/$firmware /lib/firmware/$firmware
9ed6e1db
AM
725 done
726
727 echo "mount -t proc none /proc" >> "$linuxrc"
728 echo "mount -t sysfs none /sys" >> "$linuxrc"
0867ab75 729 echo "echo -n "/lib/firmware/firmware.sh" > /proc/sys/kernel/hotplug" >> "$linuxrc"
9ed6e1db
AM
730}
731
732firmware_install_module_post() {
733 module="$1"
734 linuxrc="$2"
735 firmware_files="$3"
736 echo "umount /sys" >> "$linuxrc"
737 echo "umount /proc" >> "$linuxrc"
738}
739
2a5bcca9
AM
740modules_install() {
741 modules="$1"
742
743 for mod in $modules; do
034fdd5d
ER
744 MODULEDIR=$(dirname "$mod")
745 inst_d "/lib/modules/$kernel/$MODULEDIR"
dd87738f 746 cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
ac085800 747 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
2a5bcca9
AM
748 done
749}
750
751modules_add_linuxrc() {
752 modules="$1"
753 linuxrc="$2"
ac085800 754
2a5bcca9 755 for mod in $modules; do
87d21026 756 MODULE2="`dirname "$mod"`"
ac085800
ER
757 NAME2=`basename "$mod" .gz`
758 MODULE2=$MODULE2/$NAME2
759 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
760 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
ffa1b198 761
9ed6e1db
AM
762 generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
763 sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
94769f11 764 firmware_var="$(eval echo \$MODULE_${generic_module}_FIRMWARE)"
2a5bcca9 765
ac085800
ER
766 if [ -n "$verbose" ]; then
767 echo -n "Loading module [$module] "
768 if [ -n "$options" ] ; then
769 echo -n "with options [$options]"
770 else
771 echo -n "without options"
772 fi
8e598759 773 if [ -n "$sleep_var" ]; then
ba0552ce 774 echo " and $sleep_var usleep."
8e598759
AM
775 else
776 echo "."
777 fi
ac085800
ER
778 fi
779
9ed6e1db
AM
780 if [ -n "$firmware_var" ]; then
781 firmware_install_module_pre "$module" "$linuxrc" "$firmware_var"
782 fi
ac085800 783 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
8e598759
AM
784 if [ -n "${sleep_var}" ]; then
785 echo "usleep $sleep_var" >> "$linuxrc"
786 fi
9ed6e1db
AM
787 if [ -n "$firmware_var" ]; then
788 firmware_install_module_post "$module" "$linuxrc" "$firmware_var"
789 fi
2a5bcca9
AM
790 done
791}
792
5dc785c7 793if [ -r /etc/sysconfig/geninitrd ] ; then
794 . /etc/sysconfig/geninitrd
795fi
796
5b71959c
AM
797if [ -r /etc/sysconfig/bootsplash ] ; then
798 . /etc/sysconfig/bootsplash
799fi
800
e4b07ddc 801if [ -r /etc/sysconfig/fbsplash ] ; then
802 . /etc/sysconfig/fbsplash
803fi
804
ac085800 805if [ ! -x /bin/initrd-busybox ] ; then
00eaa938 806 die "/bin/initrd-busybox is missing!"
5dc785c7 807fi
901afd79 808
7591cd37
ER
809# backwards compatible
810if [ "$USE_SUSPEND2" ] ; then
811 USE_TUXONICE=$USE_SUSPEND2
812 echo >&2 "USE_SUSPEND2 is deprecated, use USE_TUXONICE now instead."
813fi
814
bb529f94 815while [ $# -gt 0 ]; do
413878f8 816 case $1 in
6bd433bc
AF
817 --fstab=*)
818 fstab="`echo $1 | awk -F= '{print $2;}'`"
819 ;;
820 --fstab)
821 fstab="$2"
822 shift
413878f8 823 ;;
cd670d83
AF
824 --modules-conf=*)
825 modulefile="`echo $1 | awk -F= '{print $2;}'`"
826 ;;
57188d60 827 --modules-conf)
cd670d83
AF
828 modulefile="$2"
829 shift
830 ;;
6bd433bc
AF
831 --use-raidstart|--with-raidstart)
832 USERAIDSTART="yes"
833 ;;
834 --without-raidstart)
835 USERAIDSTART="no"
836 ;;
57227e0a
AF
837 --use-insmod-static|--with-insmod-static)
838 USEINSMODSTATIC="yes"
839 ;;
840 --without-insmod-static)
841 USEINSMODSTATIC="no"
842 ;;
ba5d09f0 843 --with-bootsplash)
844 BOOT_SPLASH="yes"
845 ;;
5b71959c
AM
846 --without-bootsplash)
847 BOOT_SPLASH="no"
848 ;;
ba5d09f0 849 --with-fbsplash)
850 FB_SPLASH="yes"
851 ;;
e4b07ddc 852 --without-fbsplash)
853 FB_SPLASH="no"
854 ;;
ba5d09f0 855 --with-suspend)
856 USE_SUSPEND="yes"
857 ;;
4ef98747 858 --without-suspend)
ba5d09f0 859 USE_SUSPEND="no"
860 ;;
1cd2aabd
ER
861 --with-suspend2 | --with-tuxonice)
862 USE_TUXONICE="yes"
22b0c9f4 863 ;;
1cd2aabd
ER
864 --without-suspend2 | --without-tuxonice)
865 USE_TUXONICE="no"
2c52f208 866 ;;
e0c502bb
AM
867 --lvmtoolsversion=|--lvmversion=)
868 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
77bcfc68 869 ;;
e0c502bb
AM
870 --lvmtoolsversion|--lvmversion)
871 LVMTOOLSVERSION="$2"
77bcfc68
AF
872 shift
873 ;;
1606e343
AM
874 --without-udev)
875 USE_UDEV=
876 ;;
d7d5530e
ER
877 --with-udev)
878 USE_UDEV="yes"
879 ;;
882472ae
ER
880 --without-dmraid)
881 USE_DMRAID=
882 ;;
2cc3ae8b
ER
883 --without-multipath)
884 USE_MULTPATH=
885 ;;
6bd433bc
AF
886 --with=*)
887 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
888 ;;
889 --with)
890 BASICMODULES="$BASICMODULES $2"
891 shift
413878f8 892 ;;
bb529f94 893 --version)
9e1ceabe 894 echo "$PROGRAM: version $VERSION"
413878f8 895 exit 0
896 ;;
bb529f94 897 -v)
413878f8 898 verbose=-v
899 ;;
bb529f94 900 --nocompress)
413878f8 901 COMPRESS="no"
902 ;;
bb529f94 903 --ifneeded)
413878f8 904 ifneeded=1
905 ;;
bb529f94 906 -f)
413878f8 907 force=1
908 ;;
6bd433bc
AF
909 --preload=*)
910 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
911 ;;
912 --preload)
72623c13 913 PREMODS="$PREMODS $2"
6bd433bc 914 shift
413878f8 915 ;;
2ad94d8a 916 --fs=*)
94769f11 917 echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead"
2ad94d8a
AF
918 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
919 ;;
2ad94d8a 920 --fs)
94769f11 921 echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead"
2ad94d8a
AF
922 INITRDFS="$2"
923 shift
cd670d83 924 ;;
6bd433bc
AF
925 --initrdfs=*)
926 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
927 ;;
fd2dc249 928 --initrdfs)
2ad94d8a 929 INITRDFS="$2"
413878f8 930 shift
931 ;;
bb529f94 932 --image-version)
413878f8 933 img_vers=yes
934 ;;
4f4e832d
AM
935 --ide-only-root)
936 ide_only_root="yes"
937 ;;
bb529f94 938 *)
413878f8 939 if [ -z "$target" ]; then
940 target="$1"
941 elif [ -z "$kernel" ]; then
942 kernel="$1"
943 else
944 usage
945 fi
946 ;;
947 esac
948
949 shift
bb529f94
JK
950done
951
06ac05d6 952if [ -z "$target" -o -z "$kernel" ]; then
413878f8 953 usage
06ac05d6
AF
954fi
955
0868f49f 956pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
64497ebb 957pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
0868f49f 958
48413b7f
AM
959if [ "x" = "x$INITRDFS" ] ; then
960 if [ "x" = "x$FS" ] ; then
961 # default value
8d6cdf87 962 if [ "$pack_version" -ge "002005" ] ; then
963 INITRDFS="initramfs"
964 else
ac085800 965 INITRDFS="rom"
8d6cdf87 966 fi
48413b7f 967 else
94769f11 968 echo >&2 "Warning: FS configuration options is obsoleted. Use INITRDFS instead"
48413b7f
AM
969 INITRDFS="$FS"
970 fi
971fi
972
1606e343 973if [ "$pack_version" -lt "002006" ] ; then
882472ae
ER
974 USE_UDEV=
975 USE_DMRAID=
1606e343 976fi
ac085800 977
0868f49f
AF
978if [ "$pack_version" -ge "002005" ] ; then
979 modext=".ko"
0b6536f5 980 insmod="insmod"
0868f49f
AF
981fi
982
57227e0a
AF
983if is_yes "$USEINSMODSTATIC" ; then
984 insmod="insmod.static"
b2e62ae1 985 INSMOD="/sbin/insmod.static"
f7c18703
AM
986 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
987 INSMOD="/sbin/insmod.static.modutils"
b2e62ae1
AF
988 fi
989 if [ ! -f "$INSMOD" ] ; then
00eaa938 990 die "insmod.static requested but /sbin/insmod.static not found!"
b2e62ae1 991 fi
57227e0a
AF
992fi
993
2ad94d8a 994case "$INITRDFS" in
8b1e4ac7 995 ext2)
f5d71bb2 996 if [ ! -x /sbin/mke2fs ]; then
00eaa938 997 die "/sbin/mke2fs is missing"
8b1e4ac7
AF
998 fi
999 ;;
1000 rom)
1001 if [ ! -x /sbin/genromfs ]; then
00eaa938 1002 die "/sbin/genromfs is missing"
8b1e4ac7
AF
1003 fi
1004 ;;
1005 cram)
1006 if [ ! -x /sbin/mkcramfs ]; then
00eaa938 1007 die "/sbin/mkcramfs is missing"
8b1e4ac7 1008 fi
c31050f3 1009 ;;
48413b7f
AM
1010 initramfs)
1011 if [ ! -x /bin/cpio ]; then
00eaa938 1012 die "/bin/cpio is missing"
48413b7f
AM
1013 fi
1014 if [ ! -x /usr/bin/find ]; then
00eaa938 1015 die "/usr/bin/find is missing"
48413b7f
AM
1016 fi
1017 ;;
8b1e4ac7 1018 *)
00eaa938 1019 die "Filesystem $INITRDFS on initrd is not supported"
8b1e4ac7
AF
1020 ;;
1021esac
bb529f94 1022
bb529f94 1023if [ -n "$img_vers" ]; then
413878f8 1024 target="$target-$kernel"
bb529f94
JK
1025fi
1026
35164381 1027if [ -z "$force" -a -f "$target" ]; then
00eaa938 1028 die "$target already exists."
bb529f94
JK
1029fi
1030
35164381 1031if [ ! -d "/lib/modules/$kernel" ]; then
00eaa938 1032 die "/lib/modules/$kernel is not a directory."
bb529f94
JK
1033fi
1034
1cd2aabd
ER
1035if is_yes "$USE_SUSPEND" && is_yes "$USE_TUXONICE"; then
1036 die "Tuxonice shouldn't be used in parallel with mainline suspend!."
22b0c9f4
AM
1037fi
1038
e4b07ddc 1039if is_yes "$FB_SPLASH"; then
1040 if is_yes "$BOOT_SPLASH"; then
00eaa938 1041 die "You can't use both bootsplash and fbsplash! Please choose one."
e4b07ddc 1042 elif [ "$INITRDFS" != "initramfs" ]; then
00eaa938 1043 die "FB_SPLASH works only if INITRDFS is initramfs!."
e4b07ddc 1044 fi
1045fi
1046
48762878 1047if [ ! -f /proc/mounts ]; then
94769f11 1048 echo >&2 "WARNING: /proc filesystem not mounted, may cause wrong results or failure."
48762878 1049fi
f121024f
AM
1050
1051if [ "$pack_version" -lt "002005" ]; then
1052 modulefile=/etc/modules.conf
1053 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
1054 modulefile=/etc/conf.modules
1055 fi
1056else
1057 modulefile=/etc/modprobe.conf
1058fi
ac085800 1059
bb529f94 1060for n in $PREMODS; do
35164381 1061 findmodule "$n"
bb529f94
JK
1062done
1063
7c38b114
AF
1064# allow forcing loading SCSI and/or IDE modules
1065if is_yes "$ADDSCSI" ; then
1066 find_modules_scsi
bb529f94
JK
1067fi
1068
7c38b114
AF
1069if is_yes "$ADDIDE" ; then
1070 find_modules_ide
cd670d83
AF
1071fi
1072
1cea325b
ER
1073find_root "$fstab" || exit
1074debug "Using $rootdev as device for rootfs"
1075
a8007847
ER
1076find_modules_for_device "$rootdev"
1077[ -n "$rootdev_add" ] && find_modules_for_device "$rootdev_add"
cd670d83 1078
7c38b114 1079findmodule "-$rootFs"
bb529f94 1080
c31050f3 1081for n in $BASICMODULES; do
7d2fc5eb 1082 findmodule "$n"
bb529f94
JK
1083done
1084
1cd2aabd 1085if is_yes "$USE_TUXONICE"; then
335cd101
JR
1086 findmodule "-lzf"
1087fi
1088
e4b07ddc 1089if is_yes "$FB_SPLASH"; then
1090 findmodule "-evdev"
1091fi
2cc3ae8b 1092
bb529f94 1093if [ -n "$ifneeded" -a -z "$MODULES" ]; then
94769f11 1094 debug "No modules are needed -- not building initrd image."
7d2fc5eb 1095 exit 0
bb529f94 1096fi
94769f11 1097debug "Using modules: $MODULES"
bb529f94 1098
35164381
SZ
1099MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
1100IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
1101MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
1102RCFILE="$MNTIMAGE/linuxrc"
bb529f94 1103
35164381 1104if [ -f "$MNTIMAGE" ]; then
00eaa938 1105 die "$MNTIMAGE already exists. Remove it and try again"
bb529f94
JK
1106fi
1107
35164381 1108if [ -f "$IMAGE" ]; then
00eaa938 1109 die "$IMAGE already exists. Remove it and try again"
bb529f94
JK
1110fi
1111
73edc0c1 1112mkdir -p "$MNTPOINT"
bb529f94 1113# We don't need this directory, so let's save space
35164381 1114rm -rf "$MNTPOINT"/lost+found
bb529f94 1115
034fdd5d
ER
1116inst_d /{lib,bin,etc,dev,loopfs,var}
1117
2a5bcca9 1118modules_install "$MODULES"
bb529f94
JK
1119
1120# mknod'ing the devices instead of copying them works both with and
1121# without devfs...
35164381 1122mknod "$MNTIMAGE/dev/console" c 5 1
eb6e37ff
MM
1123mknod "$MNTIMAGE/dev/null" c 1 3
1124mknod "$MNTIMAGE/dev/zero" c 1 5
034fdd5d 1125inst_d /dev/pts /dev/shm
bb529f94 1126
84670990 1127s="$RCFILE"
566ad08b 1128ln -s /linuxrc $MNTIMAGE/init
ef66f232 1129
dcc1b914 1130inst /bin/initrd-busybox /bin/initrd-busybox
dab92b1d
ER
1131ln -s initrd-busybox $MNTIMAGE/bin/sh
1132ln -s initrd-busybox $MNTIMAGE/bin/busybox # for older busyboxes who had /bin/busybox as EXEPATH
ef66f232 1133
1775ba37
ER
1134if is_yes "$USEINSMODSTATIC"; then
1135 inst "$INSMOD" /bin/insmod.static
57227e0a
AF
1136fi
1137
f116bd42 1138cat > "$s" <<'EOF'
84670990 1139#! /bin/sh
f116bd42 1140mount -t proc none /proc
c3e2550c
AM
1141if [ "$(awk ' /debuginitrd/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1142 export DEBUG=yes
1143 set -x
1144fi
1145umount /proc
84670990
MM
1146EOF
1147chmod 755 "$s"
c31050f3 1148
2a5bcca9 1149modules_add_linuxrc "$MODULES" "$s"
fd2dc249 1150
4e9eb79c 1151# TODO: rewrite for busybox
fd2dc249
AF
1152#if [ -n "$loopDev" ]; then
1153# if [ ! -d /initrd ]; then
1154# mkdir /initrd
1155# fi
1156#
1157# cp -a "$loopDev" "$MNTIMAGE/dev"
738c05d8 1158# cp -a "$rootdev" "$MNTIMAGE/dev"
fd2dc249
AF
1159# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1160# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
738c05d8
ER
1161# echo "echo Setting up loopback device $rootdev" >> $RCFILE
1162# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
fd2dc249 1163#fi
bb529f94 1164
22b0c9f4
AM
1165initrd_gen_suspend() {
1166 if [ ! -x /usr/sbin/resume ]; then
00eaa938 1167 die "/usr/sbin/resume is missing!"
22b0c9f4 1168 fi
034fdd5d 1169 inst_d /etc /dev
22b0c9f4 1170 resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
1775ba37
ER
1171 inst /dev/snapshot /dev
1172 inst $resume_dev /dev
1173 inst /etc/suspend.conf /etc/suspend.conf
dcc1b914 1174 inst /usr/sbin/resume /bin/resume
22b0c9f4
AM
1175 echo "resume" >> "$s"
1176}
1177
1cd2aabd 1178initrd_gen_tuxonice() {
034fdd5d 1179 inst_d /sys /proc
5a61a17c 1180cat << 'EOF' >> "$s"
2b1a3707 1181mount -t proc none /proc
050198fa 1182mount -t sysfs none /sys
5a61a17c 1183if [ "$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
2b1a3707 1184EOF
2b1a3707 1185cat << EOF >> "$s"
050198fa 1186 [ -e /proc/suspend2/do_resume ] && echo > /proc/suspend2/do_resume
1187 [ -e /sys/power/suspend2/do_resume ] && echo > /sys/power/suspend2/do_resume
5b26c57b 1188 [ -e /sys/power/tuxonice/do_resume ] && echo > /sys/power/tuxonice/do_resume
2b1a3707 1189fi
050198fa 1190umount /sys
2b1a3707
AM
1191umount /proc
1192EOF
2df2e995 1193}
2c52f208 1194
7915c8b1 1195# generate code to mount /dev on tmpfs and create initial nodes
4ca8a6c5
ER
1196# can be called multiple times. /dev is cleaned up (umounted) automatically at
1197# the end of script.
b4d9d384 1198initrd_gen_tmpfs_dev() {
dd856379
AG
1199 if [ "$INITRDFS" = "initramfs" ]; then
1200 # initramfs is read-write filesystem, no need for tmpfs
1201 return
1202 fi
7915c8b1
ER
1203
1204 # we already generated tmpfs code; return
1205 if is_yes "$tmpfs_dev"; then
1206 return
1207 fi
1208
b4d9d384 1209 tmpfs_dev=yes
9299682f
ER
1210
1211 busybox_applet mount mknod mkdir
d07b92a4 1212 cat >> "$s" <<-EOF
b4d9d384
ER
1213: 'Creating /dev'
1214mount -o mode=0755 -t tmpfs none /dev
1215mknod /dev/console c 5 1
1216mknod /dev/null c 1 3
1217mknod /dev/zero c 1 5
1218mkdir /dev/pts
1219mkdir /dev/shm
1220EOF
1221}
1222
1606e343 1223initrd_gen_udev() {
94769f11 1224 debug "Setting up udev..."
034fdd5d 1225 inst_d /sbin /proc /etc/udev /sys
ac085800 1226
9299682f 1227 if [ ! -x /sbin/initrd-udevd ]; then
00eaa938 1228 die "/sbin/initrd-udevd not present"
9299682f
ER
1229 fi
1230
1775ba37
ER
1231 inst /sbin/initrd-udevd /sbin/udevd
1232 inst /etc/udev/udev.conf /etc/udev/udev.conf
1606e343 1233
1606e343 1234 if is_yes "$USE_UDEV"; then
d07b92a4 1235 initrd_gen_tmpfs_dev
e4b07ddc 1236 cat >> "$s" <<- 'EOF'
1237 mount -t proc none /proc
1238 mount -t sysfs none /sys
1239 : 'Starting udev'
fdc8f895 1240 /sbin/udevd --daemon
7915c8b1 1241 EOF
e4b07ddc 1242 if is_yes "$PROBESTATICMODS"; then
1775ba37
ER
1243 inst /sbin/initrd-udevtrigger /sbin/udevtrigger
1244 inst /sbin/initrd-udevsettle /sbin/udevsettle
7915c8b1 1245 cat >> "$s" <<-'EOF'
e4b07ddc 1246 /sbin/udevtrigger
1247 /sbin/udevsettle
7915c8b1 1248 EOF
e4b07ddc 1249 fi
9299682f
ER
1250
1251 busybox_applet killall
1252 cat >> "$s" <<-'EOF'
93f2f7c3 1253 killall udevd
e4b07ddc 1254 umount /proc
1255 umount /sys
7915c8b1 1256 EOF
1606e343
AM
1257 fi
1258}
1259
2cc3ae8b 1260initrd_gen_multipath() {
2cc3ae8b
ER
1261 inst_d /proc /sys /sbin /lib/udev
1262# inst /sbin/multipathd /sbin
1263 inst /sbin/kpartx /sbin
1264# inst /bin/mountpoint /bin
1265# inst /sbin/devmap_name /sbin
1266 inst /sbin/multipath /sbin
1267 # for udev callouts
1268 inst /sbin/scsi_id /lib/udev
1269 for a in /sbin/mpath*; do
1270 inst $a /sbin
1271 done
1272
1273 if [ -d /lib64 ]; then
1274 lib=/lib64
1275 else
1276 lib=/lib
1277 fi
1278 inst_d $lib
1279 inst /lib64/ld-linux-x86-64.so.2 $lib
aabf157c 1280 for a in $(ldd /sbin/kpartx /sbin/multipath | grep -v linux-gate.so | sort -u | awk '{print $3}'); do
2cc3ae8b
ER
1281 inst $a $lib
1282 done
aabf157c 1283 for a in $(ldd $MNTIMAGE$lib/lib* | grep -v linux-gate.so | sort -u | awk '{print $3}'); do
2cc3ae8b
ER
1284 inst $a $lib
1285 done
1286
1287 cat <<-'EOF' >> "$s"
1288 mount -t proc none /proc
1289 mount -t sysfs none /sys
1290EOF
1291
1292 initrd_gen_tmpfs_dev
1293 initrd_gen_devices
1294
1295 cat <<-'EOF' >> "$s"
1296 /sbin/multipath -v 0
1297
1298 for a in /dev/mapper/*; do
1299 [ $a = /dev/mapper/control ] && continue
1300 kpartx -a $a
1301 done
1302 rm -f /dev/sd?* # XXX adjust lvm.conf instead. however at initrd creation time
1303 sh
1304
1305 umount /sys
1306 umount /proc
1307EOF
1308}
1309
882472ae 1310initrd_gen_dmraid() {
ac085800 1311 if [ ! -x /sbin/dmraid-initrd ] ; then
00eaa938 1312 die "/sbin/dmraid-initrd is missing missing!"
ac085800
ER
1313 fi
1314
661cd523 1315 # always make /dev on tmpfs
7915c8b1 1316 initrd_gen_tmpfs_dev
ac085800 1317
034fdd5d 1318 inst_d /sbin /sys
1775ba37 1319 inst /sbin/dmraid-initrd /sbin/dmraid
9bb6d02a 1320 cat <<-EOF >> "$s"
882472ae
ER
1321 mount -t proc none /proc
1322 mount -t sysfs none /sys
2ffb1734
ER
1323EOF
1324
1325 initrd_gen_devices
1326
1327 cat <<-EOF >> "$s"
882472ae
ER
1328 # 2 secs was enough for my system to initialize. but really this is udev issue?
1329 usleep 2000000
e5d02b56 1330 : 'Activating Device-Mapper RAID(s)'
882472ae
ER
1331 /sbin/dmraid -ay -i
1332 umount /sys
1333 umount /proc
1334EOF
1335}
1336
8bd582f1
ER
1337# Generates /dev nodes based on /proc/partitions information.
1338# Needs /proc mounted.
1339# Can be called multiple times.
2ffb1734 1340initrd_gen_devices() {
8bd582f1
ER
1341 if is_yes "$proc_partitions"; then
1342 return
1343 fi
1344 proc_partitions=yes
1345
06ae4e5a 1346 cat <<-'EOF' >> "$s"
2ffb1734
ER
1347 : 'Making device nodes'
1348 # ignore first two lines, header, empty line and process rest
1349 cat /proc/partitions | (read b; read b; while read major minor blocks dev rest; do
06ae4e5a
ER
1350 node=/dev/$dev
1351 mkdir -p ${node%/*}
1352 mknod $node b $major $minor
2ffb1734
ER
1353 done
1354 )
1355EOF
1356}
1357
2df2e995 1358initrd_gen_softraid() {
94769f11 1359 debug "Setting up mdadm..."
ac085800 1360
00eaa938
ER
1361 if [ ! -x /sbin/mdadm -o ! -x /sbin/initrd-mdassemble ]; then
1362 die "/sbin/mdadm or /sbin/initrd-mdassemble is missing!"
d3fa6ec7 1363 fi
994eb509 1364
dcc1b914 1365 inst /sbin/initrd-mdassemble /bin/mdassemble
6cca3165 1366
4e9eb79c 1367 # LVM on RAID case
6cca3165
AM
1368 dev_list_extra=$(awk '/^DEVICE / { for (i=2; i<=NF; i++) { printf "%s ", $i; }; } ' /etc/mdadm.conf)
1369 for ex_dev in $dev_list_extra; do
1370 echo "DEVICE $ex_dev" >> "$MNTIMAGE/etc/mdadm.conf"
1371 done
ac085800 1372 do_md0=1
4e9eb79c 1373 for nr in `seq 1 $rootdev_nr`; do
ac085800
ER
1374 eval cr_rootdev="\$rootdev${nr}"
1375 eval cr_dev_list="\$dev_list${nr}"
94769f11 1376 debug echo "Setting up array ($cr_rootdev = $cr_dev_list)"
ac085800
ER
1377
1378 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1379
1380 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1381 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
a46f8bda 1382 cr_md_conf=$(/sbin/mdadm --detail --brief --config=/etc/mdadm.conf $cr_rootdev | awk ' { gsub(/spares=[0-9]+/, "", $0); print $0; }')
ac085800
ER
1383 if [ -n "$cr_md_conf" ]; then
1384 echo "$cr_md_conf" >> "$MNTIMAGE/etc/mdadm.conf"
1385 else
1386 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1387 fi
1388
1389 for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
1390 # mkdir in case of devfs name
034fdd5d 1391 inst_d $(dirname $f)
ac085800 1392 [ -e "$MNTIMAGE/$f" ] && continue
ac085800 1393 # this works fine with and without devfs
1775ba37 1394 inst $f $f
ac085800 1395 done
ef66f232 1396 done
4e9eb79c 1397
6cca3165 1398 echo "mdassemble" >> "$s"
33d24e12 1399
4e9eb79c
AM
1400 # needed to determine md-version
1401 if [ "$do_md0" -eq 1 ] ; then
1402 mknod $MNTIMAGE/dev/md0 b 9 0
1403 fi
2df2e995 1404}
2968c9dd 1405
2df2e995 1406initrd_gen_nfs() {
5a61a17c 1407 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
51447ab3 1408 # have problems like init(XX) being child process of swapper(1).
94769f11 1409 debug "Adding rootfs on NFS support to initrd (dhcp)"
7fc1e5bd 1410 mknod "$MNTIMAGE/dev/urandom" c 1 9
5c4cec75 1411 mkdir "$MNTIMAGE/newroot"
7d400dbe 1412 mkdir "$MNTIMAGE/proc"
5c4cec75
AM
1413 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1414 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1415 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
ac085800 1416 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
5a61a17c 1417 cat << 'EOF' > "$MNTIMAGE/bin/setdhcp"
5c4cec75 1418#!/bin/sh
5a61a17c
ER
1419[ "$1" != "bound" ] && exit
1420[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
1421[ -n "$subnet" ] && NETMASK="netmask $subnet"
5a61a17c 1422ifconfig $interface $ip $BROADCAST $NETMASK up
5a61a17c 1423if [ -n "$router" ]; then
ac085800 1424 for r in $router; do
ac085800 1425 route add default gw $r dev $interface
ac085800 1426 done
5c4cec75 1427fi
7d400dbe
ER
1428
1429mount -t proc none /proc
5a61a17c
ER
1430for o in $(cat /proc/cmdline); do
1431 case $o in
7d400dbe 1432 nfsroot=*)
5a61a17c 1433 rootpath=${o#nfsroot=}
7d400dbe
ER
1434 ;;
1435 esac
1436done
1437umount /proc
1438
5a61a17c 1439if [ -n "$rootpath" ]; then
ac085800 1440 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 $rootpath /newroot
5c4cec75 1441else
ac085800
ER
1442 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1443 echo "All seen variables are listed below:"
1444 set
5c4cec75
AM
1445fi
1446EOF
1447 chmod 755 "$MNTIMAGE/bin/setdhcp"
1448 echo "cd /newroot" >> "$s"
c52ba2fe 1449 echo "pivot_root . initrd" >> "$s"
d4a8e40e 1450 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
c52ba2fe 1451 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
2df2e995 1452}
6fe19d5b 1453
2df2e995 1454initrd_gen_lvm() {
94769f11 1455 debug "Adding LVM support to initrd"
1775ba37 1456 inst /sbin/initrd-lvm /bin/lvm
034fdd5d 1457 inst_d /etc /tmp /proc /newroot
e8d178ff
ER
1458
1459 # always make /dev on tmpfs for LVM2
7915c8b1 1460 if [ "$LVMTOOLSVERSION" = "2" ]; then
d07b92a4 1461 initrd_gen_tmpfs_dev
e8d178ff
ER
1462 fi
1463
b4d9d384 1464 if ! is_yes "$tmpfs_dev"; then
034fdd5d 1465 inst_d /dev/mapper
afaefcb5 1466 mknod $MNTIMAGE/dev/mapper/control c 10 63
b007399c 1467 for device in $PVDEVICES; do
13b29c8f
ER
1468 # if LVM on RAID then device might be copied already in gen_softraid
1469 [ -e "$MNTIMAGE/dev/$(basename $device)" ] && continue
1775ba37 1470 inst $device /dev
b007399c 1471 done
afaefcb5 1472 fi
84670990 1473 echo "mount -t proc none /proc" >> "$s"
b78e6497 1474 echo "mount -t tmpfs none /tmp" >> "$s"
e0c502bb 1475 if [ "$LVMTOOLSVERSION" = "1" ] ; then
cff3058d 1476 echo "lvm vgscan -T" >> "$s"
90b5b05a 1477 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
4e1e40bd 1478 echo "umount /tmp" >> "$s"
ac085800 1479 # fail to umount
ac085800 1480 echo "umount /proc" >> "$s"
cff3058d 1481 else
ac085800
ER
1482 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1483 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
f34c76a3
AM
1484 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1485 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1486 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
ac085800 1487 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
8fb0a4d2 1488 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
f34c76a3 1489 if is_yes "$raidfound"; then
ac085800 1490 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
f34c76a3 1491 fi
9baf4f3f 1492 if [ "$dmraid_devices" ] || is_yes "$use_multipath"; then
3938fd10 1493 echo ' types = [ "device-mapper", 254 ]' >> "$MNTIMAGE/etc/lvm.conf"
2cc3ae8b
ER
1494 fi
1495 if [ "$dmraid_devices" ]; then
bc0d6f2d 1496 # ignore /dev/sd* devices that dmraid consists
2cc3ae8b
ER
1497 echo ' filter = [' >> "$MNTIMAGE/etc/lvm.conf"
1498 for dev in $dmraid_devices; do
1499 debug "dmraid: ignoring $dev from LVM"
1500 printf ' "r|^%s.*|",\n' $dev
1501 done >> "$MNTIMAGE/etc/lvm.conf"
1502 echo ']' >> "$MNTIMAGE/etc/lvm.conf"
3938fd10 1503 fi
f34c76a3
AM
1504 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1505 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
be2f3ecc 1506
2ffb1734
ER
1507 initrd_gen_devices
1508
c79b26a6 1509 cat <<-EOF >> "$s"
e8d178ff 1510
dd87738f
ER
1511 # disable noise from lvm accessing devices that aren't ready.
1512 printk=\$(cat /proc/sys/kernel/printk)
e8d178ff 1513 echo 0 > /proc/sys/kernel/printk
dd87738f 1514
2cc3ae8b 1515 export LVM_SYSTEM_DIR=/tmp
dd87738f 1516 : 'Scanning for Volume Groups'
2cc3ae8b 1517 lvm vgscan --mknodes --ignorelockingfailure 2>/dev/null
e8d178ff 1518
c79b26a6 1519 : 'Activating Volume Groups'
2cc3ae8b 1520 lvm vgchange --ignorelockingfailure -a y $VGVOLUME 2>/dev/null
be2f3ecc 1521
dd87738f
ER
1522 echo "\$printk" > /proc/sys/kernel/printk
1523
91ed0242 1524 # Find out major/minor
2cc3ae8b 1525 majmin="\$(lvm lvdisplay --ignorelockingfailure -c $rootdev 2>/dev/null)"
c79b26a6
ER
1526 majmin="\${majmin#*/}"
1527 majmin="\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}"
1528 major="\${majmin%:*}"
1529 minor="\${majmin#*:}"
91ed0242 1530 # Pass it to kernel
c79b26a6
ER
1531 val=\$((256 * \$major + \$minor))
1532 echo \$val > /proc/sys/kernel/real-root-dev
1533 umount /tmp
1534 umount /proc
1535EOF
cff3058d 1536 fi
2df2e995
AM
1537}
1538
2b1a3707 1539initrd_gen_procdata() {
94769f11 1540 debug "Adding rootfs finding based on root= option support."
034fdd5d 1541 inst_d /proc
5a61a17c 1542cat << 'EOF' >> "$s"
2b1a3707 1543mount -t proc none /proc
5a61a17c
ER
1544root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
1545if [ -n "$root" ]; then
ac085800
ER
1546 rootnr="$(busybox awk -v root="$root" ' { if ($4 == root) { print 256*$1+$2; } } ' /proc/partitions)"
1547 if [ -n "$rootnr" ]; then
1548 echo "$rootnr" > /proc/sys/kernel/real-root-dev
1549 fi
2b1a3707 1550fi
9d949203 1551umount /proc
2b1a3707
AM
1552EOF
1553}
1554
2df2e995 1555# main generation
1606e343
AM
1556
1557if is_yes "$USE_UDEV"; then
1558 initrd_gen_udev
1559fi
1560
2ce7656a 1561if is_yes "$USE_SUSPEND"; then
22b0c9f4
AM
1562 initrd_gen_suspend
1563fi
1564
1cd2aabd
ER
1565if is_yes "$USE_TUXONICE"; then
1566 initrd_gen_tuxonice
2df2e995
AM
1567fi
1568
f155a80b 1569if [ "$dmraid_devices" ]; then
882472ae
ER
1570 initrd_gen_dmraid
1571fi
1572
9baf4f3f 1573if [ "$use_multipath" ]; then
2cc3ae8b
ER
1574 initrd_gen_multipath
1575fi
1576
2df2e995
AM
1577if is_yes "$usenfs" ; then
1578 initrd_gen_nfs
1775ba37 1579elif is_yes "$USERAIDSTART" && is_yes "$raidfound"; then
2df2e995 1580 initrd_gen_softraid
1775ba37 1581 if is_yes "$uselvm"; then
2df2e995 1582 initrd_gen_lvm
bfea009a
AM
1583 else
1584 initrd_gen_procdata
2df2e995 1585 fi
1775ba37 1586elif is_yes "$uselvm"; then
2df2e995 1587 initrd_gen_lvm
2b1a3707
AM
1588else
1589 initrd_gen_procdata
7c38b114
AF
1590fi
1591
737d5a0e 1592# finally umount /dev if it was on tmpfs
661cd523
ER
1593if is_yes "$tmpfs_dev"; then
1594 cat <<-EOF >> "$s"
1595 umount /dev
1596EOF
1597 tmpfs_dev=no
1598fi
1599
5101a385 1600# additional devs always needed
1775ba37 1601[ ! -e "$MNTIMAGE/$rootdev_add" ] && inst $rootdev_add /dev
5101a385 1602
f8f9e56d 1603if [ "$INITRDFS" = "initramfs" ]; then
034fdd5d 1604 inst_d /newroot
1775ba37 1605 [ ! -e "$MNTIMAGE/$rootdev" ] && inst $rootdev /dev
e4b07ddc 1606 # Parsing root parameter
81d53704 1607 # We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
e4b07ddc 1608 cat << 'EOF' >> "$s"
e4b07ddc 1609mount -t proc none /proc
df391e6f 1610
1611CMDLINE="$(busybox cat /proc/cmdline)"
1612eval "$(busybox awk -v c="$CMDLINE" '
1613BEGIN {
92ed99b6 1614 num_pattern_short = "[0-9a-f][0-9a-f][0-9a-f]";
1615 num_pattern = "[0-9a-f]" num_pattern_short;
df391e6f 1616 dev_pattern = "[hms][a-z][a-z]([0-9])+";
1617 partition = "no_partition_found";
1618 min = -1; maj = -1;
1619
1620 gsub(/.*root=/,NIL,c);
1621 gsub(/ .*/,NIL,c);
1622
1623 sub("^0x", "", c);
1624 if (c ~ "^" num_pattern_short "$") sub("^", "0", c);
1625 if (c ~ "^" num_pattern "$") {
92ed99b6 1626 maj = sprintf("%s",substr(c,1,2));
1627 min = sprintf("%s",substr(c,3));
df391e6f 1628 }
1629 if (c ~ "^\/dev\/" dev_pattern "$") sub("^/dev/","", c);
1630 if (c ~ "^" dev_pattern "$") partition = c;
1631}
1632
1633$4 ~ partition { maj = $1; min = $2; }
1634$1 ~ maj && $2 ~ min { partition = $4; }
1635
1636END {
92ed99b6 1637 print sprintf("device=/dev/%s\nmaj=%s\nmin=%s",
df391e6f 1638 partition, maj, min);
1639}
1640' /proc/partitions)"
e620b426 1641if [ "$device" != '/dev/no_partition_found' -a ! -b $device ]; then
e4b07ddc 1642 mknod $device b $maj $min
1643fi
1644EOF
92a4990b
ER
1645
1646 busybox_applet switch_root
e4b07ddc 1647 cat << EOF >> "$s"
e620b426
AG
1648if [ "\$device" = '/dev/no_partition_found' ] ; then
1649 device="$rootdev"
1650fi
1651
51dc11ca 1652mount -t $rootFs -r \$device /newroot
a020063b 1653init="\$(busybox awk ' /init=\// { gsub(/.*init=/,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline )"
1654if [ -z "\$init" -o ! -x "/newroot\$init" ]; then
1655 init=/sbin/init
1656fi
e4b07ddc 1657umount /proc
a020063b 1658exec switch_root /newroot \$init
f1a5a1b0 1659
1660echo "Error ! initramfs should not reach this place."
1661echo "It probably means you've got old version of busybox, with broken"
1662echo "initramfs support. Trying to boot anyway, but won't promise anything."
1663
1664exec chroot /newroot \$init
1665
1666echo "Failed to chroot !"
e4b07ddc 1667EOF
f8f9e56d
AM
1668 # we need real file, not symlink
1669 rm -f $MNTIMAGE/init
1670 cp -a $MNTIMAGE/linuxrc $MNTIMAGE/init
1671fi
1672
35164381 1673chmod +x "$RCFILE"
bb529f94 1674
35164381 1675(cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
bb529f94 1676
2ad94d8a 1677case "$INITRDFS" in
8b1e4ac7 1678 ext2)
94d430a8 1679 IMAGESIZE=$(du -ks $MNTPOINT | awk '{print int(($1+1023+512)/1024)*1024}')
94769f11 1680 debug "ext2 image size: $IMAGESIZE ($MNTPOINT)"
73edc0c1 1681 if [ "$IMAGESIZE" -gt 4096 ]; then
7758e45c 1682 echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
73edc0c1
ER
1683 fi
1684
1685 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
1686 mke2fs -q -F -b 1024 -m 0 "$IMAGE" 2>/dev/null 1>&2
1687 tune2fs -i 0 "$IMAGE" >/dev/null 2>&1
1688
1689 tmpmnt="`mktemp -d /tmp/initrd.mnte2-XXXXXX`"
1690 mount -o loop -t ext2 "$IMAGE" "$tmpmnt"
1691
1692 (cd "$MNTPOINT"; tar cf - .) | (cd "$tmpmnt"; tar xf -)
1693
35164381 1694 umount "$IMAGE"
8b1e4ac7
AF
1695 ;;
1696 rom)
1697 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
cdf1e7c9 1698 IMAGESIZE=$(stat -c %s $IMAGE | awk '{print int((($1/1024)+1023)/1024)*1024}')
a8b63949
ER
1699 debug "romfs image size: $IMAGESIZE ($IMAGE)"
1700 if [ "$IMAGESIZE" -gt 4096 ]; then
7758e45c 1701 echo >&2 "$PROGRAM: Your image size is larger than 4096, Be sure to boot kernel with ramdisk_size=$IMAGESIZE!"
a8b63949 1702 fi
8b1e4ac7
AF
1703 ;;
1704 cram)
1705 mkcramfs "$MNTPOINT" "$IMAGE"
8b1e4ac7 1706 ;;
48413b7f 1707 initramfs)
26939e7a 1708 (cd $MNTPOINT ; find . | cpio --quiet -H newc -o > "$IMAGE")
48413b7f 1709 ;;
8b1e4ac7 1710 *)
7758e45c 1711 echo "Filesystem $INITRDFS not supported by $PROGRAM";
c31050f3 1712esac
bb529f94
JK
1713
1714if is_yes "$COMPRESS" ; then
7d2fc5eb 1715 gzip -9 < "$IMAGE" > "$target"
bb529f94 1716else
7d2fc5eb 1717 cp -a "$IMAGE" "$target"
bb529f94 1718fi
5b71959c
AM
1719
1720if is_yes "$BOOT_SPLASH"; then
1721 if [ ! -x /bin/splash.bin ]; then
94769f11 1722 echo >&2 "Failed to execute /bin/splash.bin. Is bootsplash package installed?"
5b71959c 1723 elif [ -z "$THEME" ]; then
94769f11
ER
1724 echo >&2 "Please configure your /etc/sysconfig/bootsplash first."
1725 echo >&2 "Generating bootsplashes skipped."
5b71959c 1726 else
ac085800
ER
1727 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1728 for res in $BOOT_SPLASH_RESOLUTIONS; do
1729 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1730 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
94769f11 1731 debug "Added $res $THEME theme to initrd."
ac085800 1732 else
94769f11 1733 echo >&2 "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped"
ac085800
ER
1734 fi
1735 done
1736 else
94769f11
ER
1737 echo >&2 "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash."
1738 echo >&2 "Not adding bootsplash to initrd."
ac085800 1739 fi
5b71959c
AM
1740 fi
1741fi
1742
e4b07ddc 1743if is_yes "$FB_SPLASH"; then
1744 if [ ! -x /usr/bin/splash_geninitramfs ]; then
1745 echo >&2 "Failed to execute /usr/bin/splash_geninitramfs. Is splashutils package installed?"
1746 elif [ -z "$SPLASH_THEME" ]; then
1747 echo >&2 "Please configure your /etc/sysconfig/fbsplash first."
1748 echo >&2 "Generating fbsplashes skipped."
1749 else
1750 if [ -n "$FB_SPLASH_RESOLUTIONS" ]; then
1751 for res in $FB_SPLASH_RESOLUTIONS; do
1752 if [ -f "/etc/splash/$SPLASH_THEME/$res.cfg" ]; then
1753 /usr/bin/splash_geninitramfs -a $target -r $res $SPLASH_THEME && \
1754 debug "Added $res $SPLASH_THEME theme to initramfs."
1755 else
1756 echo >&2 "/etc/splash/$SPLASH_THEME/$res.cfg doesn't exist, skipped"
1757 fi
1758 done
1759 else
1760 echo >&2 "No FB_SPLASH_RESOLUTIONS specified in /etc/sysconfig/fbsplash."
1761 echo >&2 "Not adding fbsplash to initramfs."
1762 fi
1763 fi
1764fi
1765
35164381 1766rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
ac085800
ER
1767
1768# vim:ts=4:sw=4:noet:fdm=marker
This page took 0.519129 seconds and 4 git commands to generate.