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