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