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