]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
Umount /proc in initrd_gen_procdata().
[projects/geninitrd.git] / geninitrd
CommitLineData
bb529f94
JK
1#!/bin/sh
2
3# geninitrd
4#
4e9eb79c 5# by Jacek Konieczny <jajcus@pld-linux.org>
bb529f94 6#
413878f8 7# based on mkinitrd from RedHat
c31050f3 8
28eec2b1 9RCSID='$Id$'
bb529f94
JK
10PATH=/sbin:$PATH
11export PATH
12
2b649ae0 13VERSION="`echo "$RCSID"|awk '{print $3}'`"
bb529f94
JK
14
15. /etc/rc.d/init.d/functions
16
17COMPRESS="yes"
2ad94d8a
AF
18# INITRDFS is set later (catch obsoleted FS option)
19#INITRDFS="rom"
6bd433bc 20USERAIDSTART="yes"
d3fa6ec7 21USEMDADMSTATIC="no"
b2e62ae1 22USEINSMODSTATIC="no"
2a5bcca9 23USESUSPEND="yes"
7c38b114 24uselvm="no"
6fe19d5b 25usenfs="no"
10c3df06
MM
26# it should be safe to remove scsi_mod from here, but I'm not sure...
27PRESCSIMODS="-scsi_mod unknown -sd_mod"
64497ebb
AM
28PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
29PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
a62e2bd8 30SUSPENDMODS="-suspend2_core -suspend2_lzf -suspend2_block_io -suspend2_swap -suspend_core -suspend_text -suspend_lzf -suspend_block_io -suspend_swap"
bb529f94
JK
31target=""
32kernel=""
33force=""
34verbose=""
35MODULES=""
36img_vers=""
f121024f 37modulefile=""
7c38b114 38raidtab="/etc/raidtab"
bb529f94 39fstab="/etc/fstab"
0868f49f
AF
40insmod="insmod"
41modext=".o"
4e9eb79c 42rootdev_nr=0
5b71959c
AM
43# default bootsplash is off, if it have to be on, install bootsplash package
44BOOT_SPLASH=no
bb529f94
JK
45
46usage () {
77bcfc68
AF
47 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
48 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
49 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
50 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
e0c502bb 51 echo " [--without-bootsplash] [--lvmtoolsversion=1|2]"
77bcfc68
AF
52 echo " <initrd-image> <kernel-version>"
53 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
7d2fc5eb 54 exit 1
bb529f94
JK
55}
56
aa69da6e 57
10c3df06
MM
58my_dirname() {
59 echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
60}
61
62find_depmod () {
63 typeset mods module f level depfile first
64
65 depfile=/lib/modules/$kernel/modules.dep
f6de9380 66
b2e62ae1 67 if [ -f $depfile ] ; then
f6de9380
MM
68 : ok
69 else
c83257bc
AF
70 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
71 exit 1
f6de9380
MM
72 fi
73
0868f49f 74 # prepend / if no path given, append $modext.gz if not given,
10c3df06 75 # quote /
3b00e899 76 origmodule="$2"
10c3df06
MM
77 module=$(echo "$2" | \
78 awk '/\// {print;next} {print "/" $0}' | \
0868f49f 79 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
10c3df06
MM
80 awk '{gsub("/","\\/");print}')
81 mods=$(awk '
82BEGIN { here = 0 }
83/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
84/:/ { here = 0 }
85/(.*)/ { gsub(/\\/," "); if (here) print }
4fd11db9
AF
86' $depfile | xargs)
87
0868f49f 88 # fallback to $modext
4fd11db9
AF
89 if [ "$mods" = "" ] ; then
90 module=$(echo "$module" | \
0868f49f 91 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
4fd11db9
AF
92 fi
93 mods=$(awk '
94BEGIN { here = 0 }
95/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
96/:/ { here = 0 }
97/(.*)/ { gsub(/\\/," "); if (here) print }
10c3df06
MM
98' $depfile | xargs)
99
100 if [ "$mods" = "" ] ; then
101 if [ "$1" != silent ] ; then
3b00e899 102 echo "$origmodule: module not found in $depfile" 1>&2
10c3df06 103 fi
fd2dc249
AF
104 if ! is_no "$EXIT_IF_MISSING" ; then
105 exit 1
106 else
3b00e899 107 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
fd2dc249 108 fi
10c3df06
MM
109 fi
110
111 level=$3
112 if [ "$level" = "" ] ; then
113 level=0
114 fi
115 level=$(awk "BEGIN{print $level + 1}")
116 if [ $level -gt 20 ] ; then
3b00e899 117 echo "$origmodule: cycle in $depfile" 1>&2
10c3df06
MM
118 exit 1
119 fi
120
121 first=
122 for f in $mods ; do
123 if [ "$first" = "" ] ; then
124 first=$f
413878f8 125 else
10c3df06 126 find_depmod $1 $f $level
9c9f7cdb 127 fi
aa69da6e 128 done
10c3df06
MM
129
130 echo $first
aa69da6e 131}
132
10c3df06
MM
133addmodule() {
134 fmPath=$1
135 skiperrors=$2
136
137 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
138 if [ -n "$skiperrors" ]; then
139 return
140 fi
141
142 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
143 exit 1
144 fi
145
146 # only need to add each module once
147 # quote /
148 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
149 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
150 MODULES="$MODULES $fmPath"
151 fi
81de8443
AF
152}
153
bb529f94 154findmodule() {
413878f8 155 skiperrors=""
156 modName=$1
10c3df06 157
413878f8 158 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
159 skiperrors=1
160 modName="$(echo $modName | awk '{print(substr($0,2));}')"
161 fi
bb529f94 162
10c3df06 163 # what's that?
413878f8 164 if [ "$modName" = "pluto" ]; then
165 findmodule fc4
166 findmodule soc
167 fi
168 if [ "$modName" = "fcal" ]; then
169 findmodule fc4
170 findmodule socal
171 fi
bb529f94 172
10c3df06
MM
173 if [ -n "$skiperrors" ]; then
174 allModulesToFind=`find_depmod silent $modName`
175 else
176 allModulesToFind=`find_depmod normal $modName`
177 if [ $? != 0 ] ; then
178 exit 1
413878f8 179 fi
413878f8 180 fi
10c3df06
MM
181
182 for mod in $allModulesToFind ; do
183 mod=$(echo $mod | \
184 awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
185 addmodule $mod "$skiperrors"
186 done
bb529f94
JK
187}
188
189inst() {
413878f8 190 if [ "$#" != "2" ];then
191 echo "usage: inst <file> <destination>"
192 return
c31050f3 193 fi
413878f8 194 [ -n "$verbose" ] && echo "$1 -> $2"
195 cp "$1" "$2"
bb529f94
JK
196}
197
a2c2980f
AF
198get_label_ext2 () {
199 /sbin/e2label $1 2> /dev/null
200}
201
202get_uuid_ext2 () {
c31050f3 203 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
a2c2980f
AF
204}
205
206get_label_xfs () {
3b9c8219 207 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
c31050f3 208
a2c2980f
AF
209}
210
211get_uuid_xfs () {
3b9c8219 212 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
a2c2980f
AF
213}
214
c31050f3 215find_root() {
a2c2980f
AF
216 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
217 case $rootdev in
218 LABEL=*)
4fd11db9
AF
219 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
220 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
221 if [ -n "$rootdev2" ] ; then
222 rootdev=$rootdev2
223 rootdev_found=1
a2c2980f 224 fi
4fd11db9
AF
225 fi
226 if [ "$rootdev_found." != "1." ] ; then
227 case $rootFs in
228 ext2|ext3)
229 if [ ! -x /sbin/e2label ] ; then
230 echo "/sbin/e2label is missing" 1>&2
231 exit 1
232 fi
233 get_label="get_label_ext2"
234 ;;
235 xfs)
236 if [ ! -x /usr/sbin/xfs_db ] ; then
237 echo "/usr/sbin/xfs_db is missing" 1>&2
238 exit 1
239 fi
240 get_label="get_label_xfs"
241 ;;
242 *)
243 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
244 exit 1
245 ;;
246 esac
247 if [ ! -r /proc/partitions ] ; then
248 echo '/proc/partitions is not readable'; 1>&2
3b9c8219
AF
249 exit 1
250 fi
4fd11db9
AF
251 label=${rootdev#"LABEL="}
252 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
253 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
254 if [ -n "$verbose" ] ; then
255 echo "Using $dev as device for rootfs"
256 fi
257 rootdev=$dev
258 rootdev_found=1
259 break
a2c2980f 260 fi
4fd11db9
AF
261 done
262 if [ "$rootdev_found." != "1." ] ; then
263 echo "geninitrd can't find real device for LABEL=$label" 1>&2
264 exit 1
265 fi
a2c2980f
AF
266 fi
267 ;;
268 UUID=*)
4fd11db9
AF
269 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
270 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
271 if [ -n "$rootdev2" ] ; then
272 rootdev=$rootdev2
273 rootdev_found=1
a2c2980f 274 fi
4fd11db9
AF
275 fi
276 if [ "$rootdev_found." != "1." ] ; then
277 case $rootFs in
278 ext2|ext3)
279 if [ ! -x /sbin/tune2fs ] ; then
280 echo "/sbin/tune2fs is missing" 1>&2
281 exit 1
282 fi
283 get_uuid="get_uuid_ext2"
284 ;;
285 xfs)
286 if [ ! -x /usr/sbin/xfs_db ] ; then
287 echo "/usr/sbin/xfs_db is missing" 1>&2
288 exit 1
289 fi
290 get_label="get_uuid_xfs"
291 ;;
292 *)
293 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
294 exit 1
295 ;;
296 esac
297 if [ ! -r /proc/partitions ] ; then
298 echo '/proc/partitions is not readable'; 1>&2
3b9c8219
AF
299 exit 1
300 fi
4fd11db9
AF
301 uuid=${rootdev#"UUID="}
302 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
303 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
304 if [ -n "$verbose" ] ; then
305 echo "Using $dev as device for rootfs"
306 fi
307 rootdev=$dev
308 rootdev_found=1
309 break
a2c2980f 310 fi
4fd11db9
AF
311 done
312 if [ "$rootdev_found" != 1 ] ; then
313 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
314 exit 1
315 fi
a2c2980f
AF
316 fi
317 ;;
318 esac
4e9eb79c 319 rootdev1=${rootdev}
a2c2980f 320}
bb529f94 321
7c38b114 322find_modules_softraid() {
8c4ce35e 323 if [ -f /etc/mdadm.conf ] ; then
28eec2b1 324 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
af9328f7 325 eval `/sbin/mdadm --examine --scan --config=/etc/mdadm.conf | \
56946560
MM
326 awk -v rootdev="$1" '
327 BEGIN {
328 found = "no";
329 dev_list = "";
330 raidlevel = ""
514a668a
AM
331 rootdev_devfs = rootdev;
332 if (rootdev ~ /\/dev\/md\/[0-9]/) {
333 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
334 }
56946560
MM
335 }
336
337 /^ARRAY/ {
514a668a 338 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
809cc4cc
AM
339 raidlevel=$3;
340 gsub(/level=/,NUL,raidlevel);
341 if (raidlevel ~ /^raid[0-5]/) {
342 gsub(/raid/,NUL,raidlevel);
343 };
344 found="yes";
56946560
MM
345 getline x;
346 if (x ~ /devices=/) {
347 dev_list = x;
348 gsub("devices=", NUL, dev_list);
349 gsub(",", " ", dev_list);
350 }
351 }
352 }
809cc4cc 353
56946560
MM
354 END {
355 print "raidfound=" found;
356 print "raidlevel=" raidlevel;
357 print "dev_list=\"" dev_list "\"";
358 }'`
4c02e358
AM
359 fi
360 if [ "$raidfound" != "yes" ]; then
28eec2b1 361 [ -n "$verbose" ] && echo "Finding RAID details using raidtab for rootdev=$1"
809cc4cc 362 eval `awk -v rootdev="$1" 'BEGIN {
7c38b114
AF
363 found="no";
364 dev_list="";
514a668a
AM
365 rootdev_devfs = rootdev;
366 if (rootdev ~ /\/dev\/md\/[0-9]/) {
367 gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
368 }
7c38b114
AF
369}
370
371{
372 gsub("\t"," ");
373 gsub(" +", " ");
374 gsub("^ ","");
375 if (/^[\t ]*#/)
376 next;
377 if (/^raiddev/) {
514a668a 378 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
7c38b114
AF
379 found="yes";
380 } else {
381 if (found == "yes") {
382 exit 0;
383 };
384 };
385 };
386 if (found == "yes") {
387 if ($1 == "device") {
388 dev_list = dev_list " " $2;
389 };
390 if ($1 == "raid-level") {
391 raidlevel=$2;
392 }
393 };
394}
395
396END {
397 print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
398}' $raidtab `
809cc4cc
AM
399 fi
400
7c38b114
AF
401 if is_yes "$raidfound" ; then
402 case "$raidlevel" in
403 [0145])
404 findmodule "raid$raidlevel"
405 ;;
406 linear)
407 findmodule "linear"
408 ;;
409 *)
410 echo "raid level $number (in $raidtab) not recognized" 1>&2
411 ;;
412 esac
88614cd1
AM
413 else
414 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
415 exit 1
7c38b114 416 fi
4e9eb79c
AM
417
418 rootdev_nr=$(( $rootdev_nr + 1 ))
419 eval "rootdev${rootdev_nr}=\"$1\""
420 eval "dev_list${rootdev_nr}=\"${dev_list}\""
421
7c38b114
AF
422 for device in $dev_list; do
423 find_modules_for $device
424 done
425}
426
427find_modules_scsi() {
428 for n in $PRESCSIMODS; do
429 if [ "X$n" = "Xunknown" ] ; then
7c38b114 430 if [ -f "$modulefile" ]; then
d4a15d5f 431 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
432 for n in $scsimodules; do
433 # for now allow scsi modules to come from anywhere. There are some
434 # RAID controllers with drivers in block
435 findmodule "$n"
436 done
437 fi
438 else
439 findmodule "$n"
440 fi
441 done
442}
443
444find_modules_ide() {
28eec2b1
AM
445 typeset rootdev
446
afa3d7a8 447 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
64497ebb
AM
448 if [ "$pack_version_long" -lt "002004021" ]; then
449 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
450 for n in $PREIDEMODSOLD; do
7c38b114 451 findmodule "$n"
64497ebb
AM
452 done
453 else
454 tryauto=1
455 for n in $PREIDEMODS; do
456 if [ "X$n" = "Xunknown" ] ; then
64497ebb
AM
457 if [ -f "$modulefile" ]; then
458 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
d4a15d5f 459 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
9f2442b9 460 for na in $idemodules; do
64497ebb 461 tryauto=0;
9f2442b9 462 findmodule "$na"
64497ebb
AM
463 done
464 fi
465
466 if [ "$tryauto" -eq 1 ]; then
bf5b3bb7 467 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
64497ebb 468 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
4f4e832d
AM
469 if is_yes "${ide_only_root}"; then
470 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ] ; then
afa3d7a8
AM
471 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
472 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
473 searchpciid="${vendorid}${deviceid}"
4f4e832d 474 elif [ -f /proc/ide/${rootdev}/../config ]; then
26bfa502 475 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
4f4e832d
AM
476 fi
477 fi
478 if [ -z "${searchpciid}" ]; then
afa3d7a8
AM
479 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
480 fi
64497ebb 481 idemodules=""
afa3d7a8 482 for nb in $searchpciid; do
9f2442b9 483 eval `awk -v pciid="$nb" 'BEGIN {
64497ebb
AM
484}
485
486{
487 gsub("\t"," ");
488 gsub(" +", " ");
489 gsub("^ ","");
490 if (/^[\t ]*#/)
491 next;
91e589d6
JR
492 compmod = $1 ""; # make sure comparison type will be string
493 # cause pci IDs are hexadecimal numeric
494 if (compmod == pciid) {
64497ebb 495 module=$2;
6fd644af 496# min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
497# max_kernel=$4; #
64497ebb
AM
498 exit 0;
499 }
500}
501
502END {
503 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
92b8ae17 504}' /usr/share/pci-database/ide.pci`
d09abbd7 505 [ -n "$module" ] && idemodules="$idemodules $module"
64497ebb 506 done
4f4e832d
AM
507 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
508 new_idemodules=""
509 for nc in idemodules; do
510 new_idemodules="$nc $new_idemodules"
511 done
512 idemodules="${new_idemodules}"
513 fi
5de40f1f
AM
514 if [ -z "$idemodules" ]; then
515 echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
516 idemodules="ide-generic"
517 fi
9f2442b9
AM
518 for nd in $idemodules; do
519 findmodule "-$nd"
64497ebb 520 done
7add695b 521 else
bf5b3bb7 522 echo -n "WARNING: "
523 [ -r /usr/share/pci-database/ide.pci ] || echo -n "/usr/share/pci-database/ide.pci missing."
524 [ -r /proc/bus/pci/devices ] || echo -n "/proc/bus/pci/devices missing."
525 echo "Automatic IDE modules finding not available."
7add695b 526 fi
64497ebb 527 fi
9f2442b9
AM
528 else
529 findmodule "$n"
64497ebb
AM
530 fi
531 done
532 fi
7c38b114
AF
533}
534
535find_modules_for() {
4e9eb79c 536 if [ -z "$1" ]; then
0f8c08be 537 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
4e9eb79c 538 exit
5c4cec75
AM
539 elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
540 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
6fe19d5b
AM
541 echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
542 echo "Please install correct pci-database package and rerun $0." >&2
543 exit 1
544 fi
5c4cec75
AM
545 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
546 for m in $NFS_ETH_MODULES; do
6fe19d5b
AM
547 findmodule "$m"
548 done
549 findmodule "-ipv4"
550 findmodule "nfs"
551 usenfs="yes"
d024196b
AM
552 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
553 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
4e9eb79c 554 elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
7c38b114
AF
555 find_modules_softraid "$1"
556 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
557 find_modules_scsi
5d27006d 558 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
afa3d7a8 559 find_modules_ide "$1"
7c38b114
AF
560 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
561 findmodule "DAC960"
562 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
563 findmodule "cpqarray"
564 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
565 findmodule "cciss"
566 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
5d27006d 567 find_modules_ide
7c38b114 568 findmodule "ataraid"
d4a15d5f 569 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
570 if -n "$ataraidmodules" ; then
571 # FIXME: think about modules compiled in kernel
572 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
573 echo "Please set it and run $0 again."
574 exit 1
575 fi
576 for n in $ataraidmodules; do
577 findmodule "$n"
578 done
579 # check to see if we need to set up a loopback filesystem
38228bb7 580 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
7c38b114
AF
581 echo "Sorry, root on loop device isn't supported." 1>&2
582 exit 1
583 # TODO: rewrite for bsp and make nfs ready
584 if [ ! -x /sbin/losetup ]; then
585 echo "losetup is missing"
586 exit 1
587 fi
588 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
589 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
590 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
591 echo "for this device. Consult the geninitrd man page for more information" 1>&2
592 exit 1
593 fi
594
595 line="`awk '/'$key'/ { print $0; }' $fstab`"
596 loopDev="$(echo $line | awk '{print $3}')"
597 loopFs="$(echo $line | awk '{print $4}')"
598 loopFile="$(echo $line | awk '{print $5}')"
599
600 BASICMODULES="$BASICMODULES -loop"
601 findmodule "-$loopFs"
602 BASICMODULES="$BASICMODULES -${loopFs}"
603 # don't have any clue, how is this supposed to work
71888053 604 elif [ -e "$1" ] && ls -l "$1" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' || /sbin/lvm lvdisplay "$1" > /dev/null 2>&1 ; then
9f2d32ed
AM
605 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
606 echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
cff3058d 607 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
7c38b114
AF
608 exit 1
609 fi
e0c502bb
AM
610 if [ -z "$LVMTOOLSVERSION" ] ; then
611 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}')
612 if [ -z "$LVMTOOLSVERSION" ] ; then
613 echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
b78e6497 614 echo "and rerun $0." >&2
cff3058d 615 exit 1
77bcfc68
AF
616 fi
617 fi
decd277c
AM
618 if [ -z "$PVDEVICES" ] ; then
619 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
620 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
621 fi
7c38b114
AF
622 if [ -n "$PVDEVICES" ] ; then
623 for device in $PVDEVICES; do
624 find_modules_for $device
625 done
626 else
b78e6497
AF
627 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2
628 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
7c38b114
AF
629 exit 1
630 fi
e0c502bb 631 if [ "$LVMTOOLSVERSION" = "2" ]; then
93d781d1 632 findmodule "-dm-mod"
e0c502bb 633 elif [ "$LVMTOOLSVERSION" = "1" ]; then
93d781d1
AM
634 findmodule "-lvm"
635 findmodule "-lvm-mod"
636 else
e0c502bb 637 echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
cff3058d 638 exit 1
93d781d1 639 fi
7c38b114
AF
640 uselvm="yes"
641 fi
642}
643
2a5bcca9
AM
644modules_install() {
645 modules="$1"
646
647 for mod in $modules; do
648 MODULEDIR="`my_dirname "$mod"`"
649 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
650 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
651 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
652 done
653}
654
655modules_add_linuxrc() {
656 modules="$1"
657 linuxrc="$2"
658
659 for mod in $modules; do
660 MODULE2="`my_dirname "$mod"`"
661 NAME2=`basename "$mod" .gz`
662 MODULE2=$MODULE2/$NAME2
663 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
664 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
665
666 if [ -n "$verbose" ]; then
667 /bin/echo -n "Loading module [$module] "
668 if [ -n "$options" ] ; then
669 echo "with options [$options]."
670 else
671 echo "without options."
672 fi
673 fi
674 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
675 done
676}
677
5dc785c7 678if [ -r /etc/sysconfig/geninitrd ] ; then
679 . /etc/sysconfig/geninitrd
680fi
681
5b71959c
AM
682if [ -r /etc/sysconfig/bootsplash ] ; then
683 . /etc/sysconfig/bootsplash
684fi
685
2baa76b4
AM
686if [ ! -x /bin/initrd-busybox ] ; then
687 echo "/bin/initrd-busybox is missing !"
fd2dc249 688 exit 1
5dc785c7 689fi
690if [ "`uname -m`" = "ia64" ]; then
691 IMAGESIZE=3000
692else
693 IMAGESIZE=1500
694fi
bb529f94 695while [ $# -gt 0 ]; do
413878f8 696 case $1 in
6bd433bc
AF
697 --fstab=*)
698 fstab="`echo $1 | awk -F= '{print $2;}'`"
699 ;;
700 --fstab)
701 fstab="$2"
702 shift
413878f8 703 ;;
cd670d83
AF
704 --modules-conf=*)
705 modulefile="`echo $1 | awk -F= '{print $2;}'`"
706 ;;
57188d60 707 --modules-conf)
cd670d83
AF
708 modulefile="$2"
709 shift
710 ;;
611e9e47
AF
711 --raidtab=*)
712 raidtab="`echo $1 | awk -F= '{print $2;}'`"
713 ;;
714 --raidtab)
715 raidtab="$2"
716 shift
717 ;;
6bd433bc
AF
718 --use-raidstart|--with-raidstart)
719 USERAIDSTART="yes"
720 ;;
721 --without-raidstart)
722 USERAIDSTART="no"
723 ;;
57227e0a
AF
724 --use-insmod-static|--with-insmod-static)
725 USEINSMODSTATIC="yes"
726 ;;
727 --without-insmod-static)
728 USEINSMODSTATIC="no"
729 ;;
5b71959c
AM
730 --without-bootsplash)
731 BOOT_SPLASH="no"
732 ;;
2c52f208
AM
733 --without-suspend)
734 USESUSPEND="no";
735 ;;
e0c502bb
AM
736 --lvmtoolsversion=|--lvmversion=)
737 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
77bcfc68 738 ;;
e0c502bb
AM
739 --lvmtoolsversion|--lvmversion)
740 LVMTOOLSVERSION="$2"
77bcfc68
AF
741 shift
742 ;;
6bd433bc
AF
743 --with=*)
744 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
745 ;;
746 --with)
747 BASICMODULES="$BASICMODULES $2"
748 shift
413878f8 749 ;;
bb529f94 750 --version)
413878f8 751 echo "geninitrd: version $VERSION"
752 exit 0
753 ;;
bb529f94 754 -v)
413878f8 755 verbose=-v
756 ;;
bb529f94 757 --nocompress)
413878f8 758 COMPRESS="no"
759 ;;
bb529f94 760 --ifneeded)
413878f8 761 ifneeded=1
762 ;;
bb529f94 763 -f)
413878f8 764 force=1
765 ;;
6bd433bc
AF
766 --preload=*)
767 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
768 ;;
769 --preload)
72623c13 770 PREMODS="$PREMODS $2"
6bd433bc 771 shift
413878f8 772 ;;
2ad94d8a
AF
773 --fs=*)
774 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
775 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
776 ;;
2ad94d8a
AF
777 --fs)
778 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
779 INITRDFS="$2"
780 shift
cd670d83 781 ;;
6bd433bc
AF
782 --initrdfs=*)
783 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
784 ;;
fd2dc249 785 --initrdfs)
2ad94d8a 786 INITRDFS="$2"
413878f8 787 shift
788 ;;
bb529f94 789 --image-version)
413878f8 790 img_vers=yes
791 ;;
4f4e832d
AM
792 --ide-only-root)
793 ide_only_root="yes"
794 ;;
bb529f94 795 *)
413878f8 796 if [ -z "$target" ]; then
797 target="$1"
798 elif [ -z "$kernel" ]; then
799 kernel="$1"
800 else
801 usage
802 fi
803 ;;
804 esac
805
806 shift
bb529f94
JK
807done
808
06ac05d6 809if [ -z "$target" -o -z "$kernel" ]; then
413878f8 810 usage
06ac05d6
AF
811fi
812
0868f49f 813pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
64497ebb 814pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
0868f49f 815
48413b7f
AM
816if [ "x" = "x$INITRDFS" ] ; then
817 if [ "x" = "x$FS" ] ; then
818 # default value
566ad08b
AM
819# if [ "$pack_version" -ge "002005" ] ; then
820# INITRDFS="initramfs"
821# else
48413b7f 822 INITRDFS="rom"
566ad08b 823# fi
48413b7f
AM
824 else
825 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
826 INITRDFS="$FS"
827 fi
828fi
829
0868f49f
AF
830if [ "$pack_version" -ge "002005" ] ; then
831 modext=".ko"
0b6536f5 832 insmod="insmod"
0868f49f
AF
833fi
834
57227e0a
AF
835if is_yes "$USEINSMODSTATIC" ; then
836 insmod="insmod.static"
b2e62ae1 837 INSMOD="/sbin/insmod.static"
f7c18703
AM
838 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
839 INSMOD="/sbin/insmod.static.modutils"
b2e62ae1
AF
840 fi
841 if [ ! -f "$INSMOD" ] ; then
842 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
843 exit 1
844 fi
57227e0a
AF
845fi
846
2ad94d8a 847case "$INITRDFS" in
8b1e4ac7 848 ext2)
f5d71bb2 849 if [ ! -x /sbin/mke2fs ]; then
a2c2980f 850 echo "/sbin/mke2fs is missing" 1>&2
8b1e4ac7
AF
851 exit 1
852 fi
853 ;;
854 rom)
855 if [ ! -x /sbin/genromfs ]; then
a2c2980f 856 echo "/sbin/genromfs is missing" 1>&2
8b1e4ac7
AF
857 exit 1
858 fi
859 ;;
860 cram)
861 if [ ! -x /sbin/mkcramfs ]; then
a2c2980f 862 echo "/sbin/mkcramfs is missing" 1>&2
8b1e4ac7
AF
863 exit 1
864 fi
c31050f3 865 ;;
48413b7f
AM
866 initramfs)
867 if [ ! -x /bin/cpio ]; then
868 echo "/bin/cpio is missing" 1>&2
869 exit 1
870 fi
871 if [ ! -x /usr/bin/find ]; then
872 echo "/usr/bin/find is missing" 1>&2
873 exit 1
874 fi
875 ;;
8b1e4ac7 876 *)
2ad94d8a 877 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
8b1e4ac7
AF
878 exit 1
879 ;;
880esac
bb529f94 881
bb529f94 882if [ -n "$img_vers" ]; then
413878f8 883 target="$target-$kernel"
bb529f94
JK
884fi
885
35164381 886if [ -z "$force" -a -f "$target" ]; then
a2c2980f 887 echo "$target already exists." 1>&2
413878f8 888 exit 1
bb529f94
JK
889fi
890
35164381 891if [ ! -d "/lib/modules/$kernel" ]; then
a2c2980f 892 echo "/lib/modules/$kernel is not a directory." 1>&2
413878f8 893 exit 1
bb529f94
JK
894fi
895
48762878
AM
896if [ ! -f /proc/mounts ]; then
897 echo "/proc filesystem not mounted, may cause wrong results or failure." 1>&2
898fi
f121024f
AM
899
900if [ "$pack_version" -lt "002005" ]; then
901 modulefile=/etc/modules.conf
902 if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
903 modulefile=/etc/conf.modules
904 fi
905else
906 modulefile=/etc/modprobe.conf
907fi
908
bb529f94 909for n in $PREMODS; do
35164381 910 findmodule "$n"
bb529f94
JK
911done
912
7c38b114
AF
913# allow forcing loading SCSI and/or IDE modules
914if is_yes "$ADDSCSI" ; then
915 find_modules_scsi
bb529f94
JK
916fi
917
7c38b114
AF
918if is_yes "$ADDIDE" ; then
919 find_modules_ide
cd670d83
AF
920fi
921
7c38b114 922find_root
cd670d83 923
4e1e40bd
AM
924org_rootdev="$rootdev1"
925
4e9eb79c 926find_modules_for "$rootdev1"
cd670d83 927
7c38b114 928findmodule "-$rootFs"
bb529f94 929
c31050f3 930for n in $BASICMODULES; do
7d2fc5eb 931 findmodule "$n"
bb529f94
JK
932done
933
934if [ -n "$ifneeded" -a -z "$MODULES" ]; then
7d2fc5eb 935 if [ -n "$verbose" ]; then
936 echo "No modules are needed -- not building initrd image."
937 fi
938 exit 0
bb529f94
JK
939fi
940
941if [ -n "$verbose" ]; then
7d2fc5eb 942 echo "Using modules: $MODULES"
bb529f94
JK
943fi
944
35164381
SZ
945MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
946IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
947MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
948RCFILE="$MNTIMAGE/linuxrc"
bb529f94 949
35164381 950if [ -f "$MNTIMAGE" ]; then
c31050f3 951 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 952 exit 1
bb529f94
JK
953fi
954
35164381 955if [ -f "$IMAGE" ]; then
a2c2980f 956 echo "$IMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 957 exit 1
bb529f94
JK
958fi
959
2ad94d8a 960if [ "$INITRDFS" = "ext2" ] ; then
35164381 961 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
bb529f94 962
bb529f94
JK
963 # We have to "echo y |" so that it doesn't complain about $IMAGE not
964 # being a block device
35164381 965 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
bb529f94 966
35164381
SZ
967 mkdir -p "$MNTPOINT"
968 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
bb529f94 969else
35164381 970 mkdir -p "$MNTPOINT"
bb529f94
JK
971fi
972
8b1e4ac7 973
cff3058d 974mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
8b1e4ac7 975
bb529f94
JK
976
977# We don't need this directory, so let's save space
35164381 978rm -rf "$MNTPOINT"/lost+found
bb529f94 979
2a5bcca9 980modules_install "$MODULES"
bb529f94
JK
981
982# mknod'ing the devices instead of copying them works both with and
983# without devfs...
35164381 984mknod "$MNTIMAGE/dev/console" c 5 1
eb6e37ff
MM
985mknod "$MNTIMAGE/dev/null" c 1 3
986mknod "$MNTIMAGE/dev/zero" c 1 5
bb529f94 987
84670990 988s="$RCFILE"
566ad08b 989ln -s /linuxrc $MNTIMAGE/init
ef66f232 990
7543158a 991inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
ee3a3416 992ln -s sh "$MNTIMAGE/bin/busybox"
ef66f232 993
b2e62ae1
AF
994if is_yes "$USEINSMODSTATIC" ; then
995 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
57227e0a
AF
996fi
997
84670990
MM
998cat > "$s" <<EOF
999#! /bin/sh
1000
d70364fa 1001set -x
84670990
MM
1002EOF
1003chmod 755 "$s"
c31050f3 1004
2a5bcca9 1005modules_add_linuxrc "$MODULES" "$s"
fd2dc249 1006
4e9eb79c 1007# TODO: rewrite for busybox
fd2dc249
AF
1008#if [ -n "$loopDev" ]; then
1009# if [ ! -d /initrd ]; then
1010# mkdir /initrd
1011# fi
1012#
1013# cp -a "$loopDev" "$MNTIMAGE/dev"
4e9eb79c 1014# cp -a "$rootdev1" "$MNTIMAGE/dev"
fd2dc249
AF
1015# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1016# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
4e9eb79c
AM
1017# echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1018# echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
fd2dc249 1019#fi
bb529f94 1020
2df2e995 1021initrd_gen_suspend() {
2a5bcca9
AM
1022 MODULES=""
1023 for mod in $SUSPENDMODS; do
f2479fd9 1024 is_yes "$BOOT_SPLASH" && [ "$mod" = "-suspend-text" ] && mod="-suspend_bootsplash"
2a5bcca9
AM
1025 findmodule "$mod"
1026 done
1027 modules_install "$MODULES"
2c52f208
AM
1028 mkdir -p $MNTIMAGE/sys
1029 mkdir -p $MNTIMAGE/proc
2b1a3707
AM
1030cat << EOF >> "$s"
1031mount -t proc none /proc
1032if [ "\$(awk ' /resume2=/ { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1033EOF
2a5bcca9 1034 modules_add_linuxrc "$MODULES" "$s"
2b1a3707
AM
1035cat << EOF >> "$s"
1036 echo > /proc/software_suspend/activate
1037fi
1038umount /proc
1039EOF
2df2e995 1040}
2c52f208 1041
2df2e995 1042initrd_gen_softraid() {
4e9eb79c 1043 [ -n "$verbose" ] && echo "Setting up mdadm..."
8c4ce35e 1044
994eb509 1045 if [ ! -x /sbin/initrd-mdadm -a ! -x /sbin/initrd-mdassemble ] ; then
6d208806 1046 echo "/sbin/initrd-mdadm and /sbin/initrd-mdassemble are missing !"
8c4ce35e 1047 exit 1
d3fa6ec7 1048 fi
994eb509
AM
1049
1050 if [ -x /sbin/initrd-mdassemble ] ; then
867ab390 1051 do_mdassemble=1
994eb509 1052 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
994eb509 1053 else
4e9eb79c
AM
1054 do_mdassemble=0
1055 inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
ef66f232 1056 fi
4e9eb79c
AM
1057
1058 # LVM on RAID case
1059 do_md0=1
1060 for nr in `seq 1 $rootdev_nr`; do
1061 eval cr_rootdev="\$rootdev${nr}"
1062 eval cr_dev_list="\$dev_list${nr}"
1063 [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1064
1065 [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1066
1067 if [ "$do_mdassemble" -eq 1 ] ; then
1068 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
570d0b18 1069 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
33d24e12 1070 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
4e9eb79c
AM
1071 else
1072 echo "mdadm --assemble $cr_rootdev $cr_dev_list" >> "$s"
1073 fi
1074
1075 for f in $cr_dev_list $cr_rootdev ; do
ef66f232 1076 # mkdir in case of devfs name
02266c5e 1077 mkdir -p $MNTIMAGE/`my_dirname $f`
ef66f232
MM
1078 [ -n "$verbose" ] && echo "copying $f"
1079 # this works fine with and without devfs
1080 cp -HR $f $MNTIMAGE/$f
4e9eb79c 1081 done
ef66f232 1082 done
4e9eb79c 1083
33d24e12
AM
1084 if [ "$do_mdassemble" -eq 1 ] ; then
1085 echo "mdassemble" >> "$s"
1086 fi
1087
4e9eb79c
AM
1088 # needed to determine md-version
1089 if [ "$do_md0" -eq 1 ] ; then
1090 mknod $MNTIMAGE/dev/md0 b 9 0
1091 fi
2df2e995 1092}
2968c9dd 1093
2df2e995 1094initrd_gen_nfs() {
51447ab3
AM
1095 # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1096 # have problems like init(XX) being child process of swapper(1).
6fe19d5b 1097 [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
53623c90 1098 mknod "$MNTIMAGE/dev/urandom" c 1 8
5c4cec75 1099 mkdir "$MNTIMAGE/newroot"
5c4cec75
AM
1100 echo "ifconfig lo 127.0.0.1 up" >> "$s"
1101 echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1102 echo "ifconfig eth0 0.0.0.0 up" >> "$s"
c52ba2fe 1103 echo "udhcpc -i eth0 -f -q -s /bin/setdhcp" >> "$s"
5c4cec75
AM
1104 cat << EOF > "$MNTIMAGE/bin/setdhcp"
1105#!/bin/sh
1106[ "\$1" != "bound" ] && exit
1107[ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
1108[ -n "\$subnet" ] && NETMASK="netmask \$subnet"
1109set -x
1110ifconfig \$interface \$ip \$BROADCAST \$NETMASK up
1111set +x
1112if [ -n "\$router" ]; then
1113 for r in \$router; do
1114 set -x
1115 route add default gw \$r dev \$interface
1116 set +x
1117 done
1118fi
1119if [ -n "\$rootpath" ]; then
1120 set -x
cc64642a 1121 mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 \$rootpath /newroot
5c4cec75
AM
1122 set +x
1123else
1124 set +x
1125 echo "Missing rootpath in what DHCP server sent to us. Failing..."
1126 echo "All seen variables are listed below:"
1127 set
1128 set -x
1129fi
1130EOF
1131 chmod 755 "$MNTIMAGE/bin/setdhcp"
1132 echo "cd /newroot" >> "$s"
c52ba2fe 1133 echo "pivot_root . initrd" >> "$s"
d4a8e40e 1134 echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
c52ba2fe 1135 echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
2df2e995 1136}
6fe19d5b 1137
2df2e995 1138initrd_gen_lvm() {
7c38b114
AF
1139 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1140 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
f34c76a3
AM
1141 mkdir -p $MNTIMAGE/etc
1142 mkdir -p $MNTIMAGE/tmp
1143 mkdir -p $MNTIMAGE/proc
4e1e40bd 1144 mkdir -p $MNTIMAGE/newroot
84670990 1145 echo "mount -t proc none /proc" >> "$s"
84670990 1146 echo "mount -t devfs none /dev" >> "$s"
b78e6497 1147 echo "mount -t tmpfs none /tmp" >> "$s"
e0c502bb 1148 if [ "$LVMTOOLSVERSION" = "1" ] ; then
cff3058d 1149 echo "lvm vgscan -T" >> "$s"
90b5b05a 1150 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
4e1e40bd
AM
1151 echo "umount /tmp" >> "$s"
1152 # fail to umount
1153 echo "umount /dev" >> "$s"
1154 echo "umount /proc" >> "$s"
cff3058d 1155 else
f34c76a3
AM
1156 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1157 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1158 echo " locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1159 echo " locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1160 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1161 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
8fb0a4d2 1162 echo " sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
f34c76a3
AM
1163 if is_yes "$raidfound"; then
1164 echo " md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1165 fi
1166 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1167 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
4e1e40bd 1168 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure" >> "$s"
90b5b05a 1169 echo "LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME" >> "$s"
91ed0242
AM
1170 # Find out major/minor
1171 echo "majmin=\"\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`\"" >> "$s"
1172 echo "majmin=\"\${majmin#*/}\"" >> "$s"
1173 echo "majmin=\"\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}\"" >> "$s"
1174 echo "major=\"\${majmin%:*}\"" >> "$s"
1175 echo "minor=\"\${majmin#*:}\"" >> "$s"
1176 # Pass it to kernel
1177 echo "val=\$((256 * \$major + \$minor))" >> "$s"
1178 echo "echo \$val > /proc/sys/kernel/real-root-dev" >> "$s"
4e1e40bd 1179 echo "umount /tmp" >> "$s"
4e1e40bd
AM
1180 echo "umount /dev" >> "$s"
1181 echo "umount /proc" >> "$s"
91ed0242
AM
1182# echo "mount -n -o ro $org_rootdev /newroot" >> "$s"
1183# echo "cd /newroot" >> "$s"
1184# echo "pivot_root . initrd" >> "$s"
1185# echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1186# echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
cff3058d 1187 fi
2df2e995
AM
1188}
1189
2b1a3707
AM
1190initrd_gen_procdata() {
1191 [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1192 mkdir -p $MNTIMAGE/proc
1193cat << EOF >> "$s"
1194set +x
1195mount -t proc none /proc
1196root="\$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline)"
1197if [ -n "\$root" ]; then
1198 rootnr="\$(busybox awk -v root="\$root" ' { if (\$4 == root) { print 256*\$1+\$2; } } ' /proc/partitions)"
1199 if [ -n "\$rootnr" ]; then
1200 echo "\$rootnr" > /proc/sys/kernel/real-root-dev
1201 fi
1202fi
9d949203 1203umount /proc
2b1a3707
AM
1204set -x
1205EOF
1206}
1207
2df2e995
AM
1208# main generation
1209if is_yes "$USESUSPEND"; then
1210 initrd_gen_suspend
1211fi
1212
1213if is_yes "$usenfs" ; then
1214 initrd_gen_nfs
1215elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1216 initrd_gen_softraid
1217 if is_yes "$uselvm" ; then
1218 initrd_gen_lvm
1219 fi
1220elif is_yes "$uselvm" ; then
1221 initrd_gen_lvm
2b1a3707
AM
1222else
1223 initrd_gen_procdata
7c38b114
AF
1224fi
1225
35164381 1226chmod +x "$RCFILE"
bb529f94 1227
35164381 1228(cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
bb529f94 1229
2ad94d8a 1230case "$INITRDFS" in
8b1e4ac7 1231 ext2)
35164381 1232 umount "$IMAGE"
8b1e4ac7
AF
1233 ;;
1234 rom)
1235 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1236 ;;
1237 cram)
1238 mkcramfs "$MNTPOINT" "$IMAGE"
8b1e4ac7 1239 ;;
48413b7f 1240 initramfs)
566ad08b 1241 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
48413b7f 1242 ;;
8b1e4ac7 1243 *)
2ad94d8a 1244 echo "Filesystem $INITRDFS not supported by $0";
c31050f3 1245esac
bb529f94
JK
1246
1247if is_yes "$COMPRESS" ; then
7d2fc5eb 1248 gzip -9 < "$IMAGE" > "$target"
bb529f94 1249else
7d2fc5eb 1250 cp -a "$IMAGE" "$target"
bb529f94 1251fi
5b71959c
AM
1252
1253if is_yes "$BOOT_SPLASH"; then
1254 if [ ! -x /bin/splash.bin ]; then
1255 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1256 elif [ -z "$THEME" ]; then
1257 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1258 echo "Generating bootsplashes skipped." 1>&2
1259 else
350cd2f9 1260 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
5b71959c
AM
1261 for res in $BOOT_SPLASH_RESOLUTIONS; do
1262 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1263 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1264 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1265 else
1266 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1267 fi
1268 done
350cd2f9
AM
1269 else
1270 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1271 echo "Not adding bootsplash to initrd." 1>&2
1272 fi
5b71959c
AM
1273 fi
1274fi
1275
35164381 1276rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
This page took 0.272932 seconds and 4 git commands to generate.