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