]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
- write usage message to stdin not stderr
[projects/geninitrd.git] / geninitrd
CommitLineData
bb529f94
JK
1#!/bin/sh
2
3# geninitrd
4#
5# by Jacek Konieczny <jajcus@pld.org.pl>
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"
7c38b114 23uselvm="no"
10c3df06
MM
24# it should be safe to remove scsi_mod from here, but I'm not sure...
25PRESCSIMODS="-scsi_mod unknown -sd_mod"
64497ebb
AM
26PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
27PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
bb529f94
JK
28target=""
29kernel=""
30force=""
31verbose=""
32MODULES=""
33img_vers=""
7c38b114
AF
34modulefile="/etc/modules.conf"
35raidtab="/etc/raidtab"
bb529f94 36fstab="/etc/fstab"
0868f49f
AF
37insmod="insmod"
38modext=".o"
5b71959c
AM
39# default bootsplash is off, if it have to be on, install bootsplash package
40BOOT_SPLASH=no
bb529f94
JK
41
42usage () {
77bcfc68
AF
43 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]"
44 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]"
45 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]"
46 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]"
47 echo " [--without-bootsplash] [--with-lvmversion=1|2]"
48 echo " <initrd-image> <kernel-version>"
49 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)"
7d2fc5eb 50 exit 1
bb529f94
JK
51}
52
aa69da6e 53
10c3df06
MM
54my_dirname() {
55 echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
56}
57
58find_depmod () {
59 typeset mods module f level depfile first
60
61 depfile=/lib/modules/$kernel/modules.dep
f6de9380 62
b2e62ae1 63 if [ -f $depfile ] ; then
f6de9380
MM
64 : ok
65 else
c83257bc
AF
66 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
67 exit 1
f6de9380
MM
68 fi
69
0868f49f 70 # prepend / if no path given, append $modext.gz if not given,
10c3df06 71 # quote /
3b00e899 72 origmodule="$2"
10c3df06
MM
73 module=$(echo "$2" | \
74 awk '/\// {print;next} {print "/" $0}' | \
0868f49f 75 awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
10c3df06
MM
76 awk '{gsub("/","\\/");print}')
77 mods=$(awk '
78BEGIN { here = 0 }
79/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
80/:/ { here = 0 }
81/(.*)/ { gsub(/\\/," "); if (here) print }
4fd11db9
AF
82' $depfile | xargs)
83
0868f49f 84 # fallback to $modext
4fd11db9
AF
85 if [ "$mods" = "" ] ; then
86 module=$(echo "$module" | \
0868f49f 87 awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
4fd11db9
AF
88 fi
89 mods=$(awk '
90BEGIN { here = 0 }
91/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
92/:/ { here = 0 }
93/(.*)/ { gsub(/\\/," "); if (here) print }
10c3df06
MM
94' $depfile | xargs)
95
96 if [ "$mods" = "" ] ; then
97 if [ "$1" != silent ] ; then
3b00e899 98 echo "$origmodule: module not found in $depfile" 1>&2
10c3df06 99 fi
fd2dc249
AF
100 if ! is_no "$EXIT_IF_MISSING" ; then
101 exit 1
102 else
3b00e899 103 echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
fd2dc249 104 fi
10c3df06
MM
105 fi
106
107 level=$3
108 if [ "$level" = "" ] ; then
109 level=0
110 fi
111 level=$(awk "BEGIN{print $level + 1}")
112 if [ $level -gt 20 ] ; then
3b00e899 113 echo "$origmodule: cycle in $depfile" 1>&2
10c3df06
MM
114 exit 1
115 fi
116
117 first=
118 for f in $mods ; do
119 if [ "$first" = "" ] ; then
120 first=$f
413878f8 121 else
10c3df06 122 find_depmod $1 $f $level
9c9f7cdb 123 fi
aa69da6e 124 done
10c3df06
MM
125
126 echo $first
aa69da6e 127}
128
10c3df06
MM
129addmodule() {
130 fmPath=$1
131 skiperrors=$2
132
133 if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
134 if [ -n "$skiperrors" ]; then
135 return
136 fi
137
138 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
139 exit 1
140 fi
141
142 # only need to add each module once
143 # quote /
144 tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
145 if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
146 MODULES="$MODULES $fmPath"
147 fi
81de8443
AF
148}
149
bb529f94 150findmodule() {
413878f8 151 skiperrors=""
152 modName=$1
10c3df06 153
413878f8 154 if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
155 skiperrors=1
156 modName="$(echo $modName | awk '{print(substr($0,2));}')"
157 fi
bb529f94 158
10c3df06 159 # what's that?
413878f8 160 if [ "$modName" = "pluto" ]; then
161 findmodule fc4
162 findmodule soc
163 fi
164 if [ "$modName" = "fcal" ]; then
165 findmodule fc4
166 findmodule socal
167 fi
bb529f94 168
10c3df06
MM
169 if [ -n "$skiperrors" ]; then
170 allModulesToFind=`find_depmod silent $modName`
171 else
172 allModulesToFind=`find_depmod normal $modName`
173 if [ $? != 0 ] ; then
174 exit 1
413878f8 175 fi
413878f8 176 fi
10c3df06
MM
177
178 for mod in $allModulesToFind ; do
179 mod=$(echo $mod | \
180 awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
181 addmodule $mod "$skiperrors"
182 done
bb529f94
JK
183}
184
185inst() {
413878f8 186 if [ "$#" != "2" ];then
187 echo "usage: inst <file> <destination>"
188 return
c31050f3 189 fi
413878f8 190 [ -n "$verbose" ] && echo "$1 -> $2"
191 cp "$1" "$2"
bb529f94
JK
192}
193
a2c2980f
AF
194get_label_ext2 () {
195 /sbin/e2label $1 2> /dev/null
196}
197
198get_uuid_ext2 () {
c31050f3 199 /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
a2c2980f
AF
200}
201
202get_label_xfs () {
3b9c8219 203 /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
c31050f3 204
a2c2980f
AF
205}
206
207get_uuid_xfs () {
3b9c8219 208 /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
a2c2980f
AF
209}
210
c31050f3 211find_root() {
a2c2980f
AF
212 eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
213 case $rootdev in
214 LABEL=*)
4fd11db9
AF
215 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
216 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
217 if [ -n "$rootdev2" ] ; then
218 rootdev=$rootdev2
219 rootdev_found=1
a2c2980f 220 fi
4fd11db9
AF
221 fi
222 if [ "$rootdev_found." != "1." ] ; then
223 case $rootFs in
224 ext2|ext3)
225 if [ ! -x /sbin/e2label ] ; then
226 echo "/sbin/e2label is missing" 1>&2
227 exit 1
228 fi
229 get_label="get_label_ext2"
230 ;;
231 xfs)
232 if [ ! -x /usr/sbin/xfs_db ] ; then
233 echo "/usr/sbin/xfs_db is missing" 1>&2
234 exit 1
235 fi
236 get_label="get_label_xfs"
237 ;;
238 *)
239 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
240 exit 1
241 ;;
242 esac
243 if [ ! -r /proc/partitions ] ; then
244 echo '/proc/partitions is not readable'; 1>&2
3b9c8219
AF
245 exit 1
246 fi
4fd11db9
AF
247 label=${rootdev#"LABEL="}
248 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
249 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
250 if [ -n "$verbose" ] ; then
251 echo "Using $dev as device for rootfs"
252 fi
253 rootdev=$dev
254 rootdev_found=1
255 break
a2c2980f 256 fi
4fd11db9
AF
257 done
258 if [ "$rootdev_found." != "1." ] ; then
259 echo "geninitrd can't find real device for LABEL=$label" 1>&2
260 exit 1
261 fi
a2c2980f
AF
262 fi
263 ;;
264 UUID=*)
4fd11db9
AF
265 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
266 rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
267 if [ -n "$rootdev2" ] ; then
268 rootdev=$rootdev2
269 rootdev_found=1
a2c2980f 270 fi
4fd11db9
AF
271 fi
272 if [ "$rootdev_found." != "1." ] ; then
273 case $rootFs in
274 ext2|ext3)
275 if [ ! -x /sbin/tune2fs ] ; then
276 echo "/sbin/tune2fs is missing" 1>&2
277 exit 1
278 fi
279 get_uuid="get_uuid_ext2"
280 ;;
281 xfs)
282 if [ ! -x /usr/sbin/xfs_db ] ; then
283 echo "/usr/sbin/xfs_db is missing" 1>&2
284 exit 1
285 fi
286 get_label="get_uuid_xfs"
287 ;;
288 *)
289 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
290 exit 1
291 ;;
292 esac
293 if [ ! -r /proc/partitions ] ; then
294 echo '/proc/partitions is not readable'; 1>&2
3b9c8219
AF
295 exit 1
296 fi
4fd11db9
AF
297 uuid=${rootdev#"UUID="}
298 for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
299 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
300 if [ -n "$verbose" ] ; then
301 echo "Using $dev as device for rootfs"
302 fi
303 rootdev=$dev
304 rootdev_found=1
305 break
a2c2980f 306 fi
4fd11db9
AF
307 done
308 if [ "$rootdev_found" != 1 ] ; then
309 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
310 exit 1
311 fi
a2c2980f
AF
312 fi
313 ;;
314 esac
315
316}
bb529f94 317
7c38b114 318find_modules_softraid() {
8c4ce35e 319 if [ -f /etc/mdadm.conf ] ; then
28eec2b1 320 [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
af9328f7 321 eval `/sbin/mdadm --examine --scan --config=/etc/mdadm.conf | \
56946560
MM
322 awk -v rootdev="$1" '
323 BEGIN {
324 found = "no";
325 dev_list = "";
326 raidlevel = ""
327 }
328
329 /^ARRAY/ {
809cc4cc
AM
330 if ($2 == rootdev) {
331 raidlevel=$3;
332 gsub(/level=/,NUL,raidlevel);
333 if (raidlevel ~ /^raid[0-5]/) {
334 gsub(/raid/,NUL,raidlevel);
335 };
336 found="yes";
56946560
MM
337 getline x;
338 if (x ~ /devices=/) {
339 dev_list = x;
340 gsub("devices=", NUL, dev_list);
341 gsub(",", " ", dev_list);
342 }
343 }
344 }
809cc4cc 345
56946560
MM
346 END {
347 print "raidfound=" found;
348 print "raidlevel=" raidlevel;
349 print "dev_list=\"" dev_list "\"";
350 }'`
4c02e358
AM
351 fi
352 if [ "$raidfound" != "yes" ]; then
28eec2b1 353 [ -n "$verbose" ] && echo "Finding RAID details using raidtab for rootdev=$1"
809cc4cc 354 eval `awk -v rootdev="$1" 'BEGIN {
7c38b114
AF
355 found="no";
356 dev_list="";
357}
358
359{
360 gsub("\t"," ");
361 gsub(" +", " ");
362 gsub("^ ","");
363 if (/^[\t ]*#/)
364 next;
365 if (/^raiddev/) {
366 if ($2 == rootdev) {
367 found="yes";
368 } else {
369 if (found == "yes") {
370 exit 0;
371 };
372 };
373 };
374 if (found == "yes") {
375 if ($1 == "device") {
376 dev_list = dev_list " " $2;
377 };
378 if ($1 == "raid-level") {
379 raidlevel=$2;
380 }
381 };
382}
383
384END {
385 print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
386}' $raidtab `
809cc4cc
AM
387 fi
388
7c38b114
AF
389 if is_yes "$raidfound" ; then
390 case "$raidlevel" in
391 [0145])
392 findmodule "raid$raidlevel"
393 ;;
394 linear)
395 findmodule "linear"
396 ;;
397 *)
398 echo "raid level $number (in $raidtab) not recognized" 1>&2
399 ;;
400 esac
401 fi
402 for device in $dev_list; do
403 find_modules_for $device
404 done
405}
406
407find_modules_scsi() {
408 for n in $PRESCSIMODS; do
409 if [ "X$n" = "Xunknown" ] ; then
64497ebb
AM
410 if [ "$pack_version" -ge "002005" ]; then
411 modulefile=/etc/modprobe.conf
412 fi
7c38b114
AF
413 if [ ! -f "$modulefile" ]; then
414 modulefile=/etc/conf.modules
415 fi
416 if [ -f "$modulefile" ]; then
d4a15d5f 417 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
418 for n in $scsimodules; do
419 # for now allow scsi modules to come from anywhere. There are some
420 # RAID controllers with drivers in block
421 findmodule "$n"
422 done
423 fi
424 else
425 findmodule "$n"
426 fi
427 done
428}
429
430find_modules_ide() {
28eec2b1
AM
431 typeset rootdev
432
afa3d7a8 433 rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
64497ebb
AM
434 if [ "$pack_version_long" -lt "002004021" ]; then
435 [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
436 for n in $PREIDEMODSOLD; do
7c38b114 437 findmodule "$n"
64497ebb
AM
438 done
439 else
440 tryauto=1
441 for n in $PREIDEMODS; do
442 if [ "X$n" = "Xunknown" ] ; then
443 if [ "$pack_version" -ge "002005" ]; then
444 modulefile=/etc/modprobe.conf
445 fi
446 if [ ! -f "$modulefile" ]; then
447 modulefile=/etc/conf.modules
448 fi
449 if [ -f "$modulefile" ]; then
450 [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
d4a15d5f 451 idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
9f2442b9 452 for na in $idemodules; do
64497ebb 453 tryauto=0;
9f2442b9 454 findmodule "$na"
64497ebb
AM
455 done
456 fi
457
458 if [ "$tryauto" -eq 1 ]; then
bf5b3bb7 459 if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices ]; then
64497ebb 460 [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
4f4e832d
AM
461 if is_yes "${ide_only_root}"; then
462 if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ] ; then
afa3d7a8
AM
463 vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
464 deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
465 searchpciid="${vendorid}${deviceid}"
4f4e832d 466 elif [ -f /proc/ide/${rootdev}/../config ]; then
26bfa502 467 searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
4f4e832d
AM
468 fi
469 fi
470 if [ -z "${searchpciid}" ]; then
afa3d7a8
AM
471 searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
472 fi
64497ebb 473 idemodules=""
afa3d7a8 474 for nb in $searchpciid; do
9f2442b9 475 eval `awk -v pciid="$nb" 'BEGIN {
64497ebb
AM
476}
477
478{
479 gsub("\t"," ");
480 gsub(" +", " ");
481 gsub("^ ","");
482 if (/^[\t ]*#/)
483 next;
91e589d6
JR
484 compmod = $1 ""; # make sure comparison type will be string
485 # cause pci IDs are hexadecimal numeric
486 if (compmod == pciid) {
64497ebb 487 module=$2;
6fd644af 488# min_kernel=$3; # now in ide.pci $3,$4 = vendor and device name
489# max_kernel=$4; #
64497ebb
AM
490 exit 0;
491 }
492}
493
494END {
495 print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
92b8ae17 496}' /usr/share/pci-database/ide.pci`
64497ebb 497 if [ -n "$module" ]; then
64497ebb
AM
498 gomin=1
499 gomax=1
500 [ -n "$min_kernel" -a "$pack_version_long" -lt "$min_kernel" ] && gomin=0
501 [ -n "$max_kernel" -a "$pack_version_long" -gt "$max_kernel" ] && gomax=0
502 [ "$gomax" -ne 0 -a "$gomin" -ne 0 ] && idemodules="$idemodules $module"
503 fi
504 done
4f4e832d
AM
505 if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
506 new_idemodules=""
507 for nc in idemodules; do
508 new_idemodules="$nc $new_idemodules"
509 done
510 idemodules="${new_idemodules}"
511 fi
9f2442b9
AM
512 for nd in $idemodules; do
513 findmodule "-$nd"
64497ebb 514 done
7add695b 515 else
bf5b3bb7 516 echo -n "WARNING: "
517 [ -r /usr/share/pci-database/ide.pci ] || echo -n "/usr/share/pci-database/ide.pci missing."
518 [ -r /proc/bus/pci/devices ] || echo -n "/proc/bus/pci/devices missing."
519 echo "Automatic IDE modules finding not available."
7add695b 520 fi
64497ebb 521 fi
9f2442b9
AM
522 else
523 findmodule "$n"
64497ebb
AM
524 fi
525 done
526 fi
7c38b114
AF
527}
528
529find_modules_for() {
530 if is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
531 find_modules_softraid "$1"
532 elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
533 find_modules_scsi
5d27006d 534 elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
afa3d7a8 535 find_modules_ide "$1"
7c38b114
AF
536 elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
537 findmodule "DAC960"
538 elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
539 findmodule "cpqarray"
540 elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
541 findmodule "cciss"
542 elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
5d27006d 543 find_modules_ide
7c38b114 544 findmodule "ataraid"
d4a15d5f 545 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
7c38b114
AF
546 if -n "$ataraidmodules" ; then
547 # FIXME: think about modules compiled in kernel
548 echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
549 echo "Please set it and run $0 again."
550 exit 1
551 fi
552 for n in $ataraidmodules; do
553 findmodule "$n"
554 done
555 # check to see if we need to set up a loopback filesystem
556 elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
557 echo "Sorry, root on loop device isn't supported." 1>&2
558 exit 1
559 # TODO: rewrite for bsp and make nfs ready
560 if [ ! -x /sbin/losetup ]; then
561 echo "losetup is missing"
562 exit 1
563 fi
564 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
565 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
566 echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
567 echo "for this device. Consult the geninitrd man page for more information" 1>&2
568 exit 1
569 fi
570
571 line="`awk '/'$key'/ { print $0; }' $fstab`"
572 loopDev="$(echo $line | awk '{print $3}')"
573 loopFs="$(echo $line | awk '{print $4}')"
574 loopFile="$(echo $line | awk '{print $5}')"
575
576 BASICMODULES="$BASICMODULES -loop"
577 findmodule "-$loopFs"
578 BASICMODULES="$BASICMODULES -${loopFs}"
579 # don't have any clue, how is this supposed to work
e59d9e5e 580 elif ls -l "$1" | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' || /sbin/lvdisplay "$1" > /dev/null 2>&1 ; then
decd277c
AM
581 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvm ] ; then
582 echo "ERROR: root on LVM but /sbin/initrd-lvm and /sbin/lvm not found."
583 echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0."
7c38b114
AF
584 exit 1
585 fi
77bcfc68
AF
586 if [ -z "$LVMVERSION" ] ; then
587 LVMVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgdisplay: Logical Volume Manager ",""); gsub("LVM version: ",""); gsub(/\..*/,"");print $1}')
588 if [ -z "$LVMVERSION" ] ; then
589 echo "WARNING: Can't determine LVM tools version. Please set LVMVERSION."
590 fi
591 fi
decd277c
AM
592 if [ -z "$PVDEVICES" ] ; then
593 VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
594 PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
595 fi
7c38b114
AF
596 if [ -n "$PVDEVICES" ] ; then
597 for device in $PVDEVICES; do
598 find_modules_for $device
599 done
600 else
14e7b1aa
AM
601 echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)."
602 echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd."
7c38b114
AF
603 exit 1
604 fi
77bcfc68 605 if [ "$LVMVERSION" = "2" ]; then
93d781d1 606 findmodule "-dm-mod"
77bcfc68 607 elif [ "$LVMVERSION" = "1" ]; then
93d781d1
AM
608 findmodule "-lvm"
609 findmodule "-lvm-mod"
610 else
611 findmodule "-dm-mod"
612 findmodule "-lvm"
613 findmodule "-lvm-mod"
614 fi
7c38b114
AF
615 uselvm="yes"
616 fi
617}
618
5dc785c7 619if [ -r /etc/sysconfig/geninitrd ] ; then
620 . /etc/sysconfig/geninitrd
621fi
622
5b71959c
AM
623if [ -r /etc/sysconfig/bootsplash ] ; then
624 . /etc/sysconfig/bootsplash
625fi
626
2ad94d8a
AF
627if [ "x" = "x$INITRDFS" ] ; then
628 if [ "x" = "x$FS" ] ; then
629 # default value
630 INITRDFS="rom"
631 else
632 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
633 INITRDFS="$FS"
634 fi
635fi
636
2baa76b4
AM
637if [ ! -x /bin/initrd-busybox ] ; then
638 echo "/bin/initrd-busybox is missing !"
fd2dc249 639 exit 1
5dc785c7 640fi
641if [ "`uname -m`" = "ia64" ]; then
642 IMAGESIZE=3000
643else
644 IMAGESIZE=1500
645fi
bb529f94 646while [ $# -gt 0 ]; do
413878f8 647 case $1 in
6bd433bc
AF
648 --fstab=*)
649 fstab="`echo $1 | awk -F= '{print $2;}'`"
650 ;;
651 --fstab)
652 fstab="$2"
653 shift
413878f8 654 ;;
cd670d83
AF
655 --modules-conf=*)
656 modulefile="`echo $1 | awk -F= '{print $2;}'`"
657 ;;
57188d60 658 --modules-conf)
cd670d83
AF
659 modulefile="$2"
660 shift
661 ;;
611e9e47
AF
662 --raidtab=*)
663 raidtab="`echo $1 | awk -F= '{print $2;}'`"
664 ;;
665 --raidtab)
666 raidtab="$2"
667 shift
668 ;;
6bd433bc
AF
669 --use-raidstart|--with-raidstart)
670 USERAIDSTART="yes"
671 ;;
672 --without-raidstart)
673 USERAIDSTART="no"
674 ;;
57227e0a
AF
675 --use-insmod-static|--with-insmod-static)
676 USEINSMODSTATIC="yes"
677 ;;
678 --without-insmod-static)
679 USEINSMODSTATIC="no"
680 ;;
5b71959c
AM
681 --without-bootsplash)
682 BOOT_SPLASH="no"
683 ;;
77bcfc68
AF
684 --lvmversion=)
685 LVMVERSION="`echo $1 | awk -F= '{print $2;}'`"
686 ;;
687 --lvmversion)
688 LVMVERSION="$2"
689 shift
690 ;;
6bd433bc
AF
691 --with=*)
692 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
693 ;;
694 --with)
695 BASICMODULES="$BASICMODULES $2"
696 shift
413878f8 697 ;;
bb529f94 698 --version)
413878f8 699 echo "geninitrd: version $VERSION"
700 exit 0
701 ;;
bb529f94 702 -v)
413878f8 703 verbose=-v
704 ;;
bb529f94 705 --nocompress)
413878f8 706 COMPRESS="no"
707 ;;
bb529f94 708 --ifneeded)
413878f8 709 ifneeded=1
710 ;;
bb529f94 711 -f)
413878f8 712 force=1
713 ;;
6bd433bc
AF
714 --preload=*)
715 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
716 ;;
717 --preload)
72623c13 718 PREMODS="$PREMODS $2"
6bd433bc 719 shift
413878f8 720 ;;
2ad94d8a
AF
721 --fs=*)
722 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
723 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
724 ;;
2ad94d8a
AF
725 --fs)
726 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
727 INITRDFS="$2"
728 shift
cd670d83 729 ;;
6bd433bc
AF
730 --initrdfs=*)
731 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
732 ;;
fd2dc249 733 --initrdfs)
2ad94d8a 734 INITRDFS="$2"
413878f8 735 shift
736 ;;
bb529f94 737 --image-version)
413878f8 738 img_vers=yes
739 ;;
4f4e832d
AM
740 --ide-only-root)
741 ide_only_root="yes"
742 ;;
bb529f94 743 *)
413878f8 744 if [ -z "$target" ]; then
745 target="$1"
746 elif [ -z "$kernel" ]; then
747 kernel="$1"
748 else
749 usage
750 fi
751 ;;
752 esac
753
754 shift
bb529f94
JK
755done
756
06ac05d6 757if [ -z "$target" -o -z "$kernel" ]; then
413878f8 758 usage
06ac05d6
AF
759fi
760
0868f49f 761pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
64497ebb 762pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
0868f49f
AF
763
764if [ "$pack_version" -ge "002005" ] ; then
765 modext=".ko"
0b6536f5 766 insmod="insmod"
0868f49f
AF
767fi
768
57227e0a
AF
769if is_yes "$USEINSMODSTATIC" ; then
770 insmod="insmod.static"
b2e62ae1 771 INSMOD="/sbin/insmod.static"
f7c18703
AM
772 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
773 INSMOD="/sbin/insmod.static.modutils"
b2e62ae1
AF
774 fi
775 if [ ! -f "$INSMOD" ] ; then
776 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
777 exit 1
778 fi
57227e0a
AF
779fi
780
2ad94d8a 781case "$INITRDFS" in
8b1e4ac7 782 ext2)
f5d71bb2 783 if [ ! -x /sbin/mke2fs ]; then
a2c2980f 784 echo "/sbin/mke2fs is missing" 1>&2
8b1e4ac7
AF
785 exit 1
786 fi
787 ;;
788 rom)
789 if [ ! -x /sbin/genromfs ]; then
a2c2980f 790 echo "/sbin/genromfs is missing" 1>&2
8b1e4ac7
AF
791 exit 1
792 fi
793 ;;
794 cram)
795 if [ ! -x /sbin/mkcramfs ]; then
a2c2980f 796 echo "/sbin/mkcramfs is missing" 1>&2
8b1e4ac7
AF
797 exit 1
798 fi
c31050f3 799 ;;
8b1e4ac7 800 *)
2ad94d8a 801 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
8b1e4ac7
AF
802 exit 1
803 ;;
804esac
bb529f94 805
bb529f94 806if [ -n "$img_vers" ]; then
413878f8 807 target="$target-$kernel"
bb529f94
JK
808fi
809
35164381 810if [ -z "$force" -a -f "$target" ]; then
a2c2980f 811 echo "$target already exists." 1>&2
413878f8 812 exit 1
bb529f94
JK
813fi
814
35164381 815if [ ! -d "/lib/modules/$kernel" ]; then
a2c2980f 816 echo "/lib/modules/$kernel is not a directory." 1>&2
413878f8 817 exit 1
bb529f94
JK
818fi
819
820for n in $PREMODS; do
35164381 821 findmodule "$n"
bb529f94
JK
822done
823
7c38b114
AF
824# allow forcing loading SCSI and/or IDE modules
825if is_yes "$ADDSCSI" ; then
826 find_modules_scsi
bb529f94
JK
827fi
828
7c38b114
AF
829if is_yes "$ADDIDE" ; then
830 find_modules_ide
cd670d83
AF
831fi
832
7c38b114 833find_root
cd670d83 834
7c38b114 835find_modules_for "$rootdev"
cd670d83 836
7c38b114 837findmodule "-$rootFs"
bb529f94 838
c31050f3 839for n in $BASICMODULES; do
7d2fc5eb 840 findmodule "$n"
bb529f94
JK
841done
842
7c38b114 843
bb529f94 844if [ -n "$ifneeded" -a -z "$MODULES" ]; then
7d2fc5eb 845 if [ -n "$verbose" ]; then
846 echo "No modules are needed -- not building initrd image."
847 fi
848 exit 0
bb529f94
JK
849fi
850
851if [ -n "$verbose" ]; then
7d2fc5eb 852 echo "Using modules: $MODULES"
bb529f94
JK
853fi
854
35164381
SZ
855MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
856IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
857MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
858RCFILE="$MNTIMAGE/linuxrc"
bb529f94 859
35164381 860if [ -f "$MNTIMAGE" ]; then
c31050f3 861 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 862 exit 1
bb529f94
JK
863fi
864
35164381 865if [ -f "$IMAGE" ]; then
a2c2980f 866 echo "$IMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 867 exit 1
bb529f94
JK
868fi
869
2ad94d8a 870if [ "$INITRDFS" = "ext2" ] ; then
35164381 871 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
bb529f94 872
bb529f94
JK
873 # We have to "echo y |" so that it doesn't complain about $IMAGE not
874 # being a block device
35164381 875 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
bb529f94 876
35164381
SZ
877 mkdir -p "$MNTPOINT"
878 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
bb529f94 879else
35164381 880 mkdir -p "$MNTPOINT"
bb529f94
JK
881fi
882
8b1e4ac7 883
35164381 884mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs}
8b1e4ac7 885
bb529f94
JK
886
887# We don't need this directory, so let's save space
35164381 888rm -rf "$MNTPOINT"/lost+found
bb529f94 889
bb529f94 890for MODULE in $MODULES; do
81de8443
AF
891 MODULEDIR="`my_dirname "$MODULE"`"
892 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
893 cp $verbose -a "/lib/modules/$kernel/$MODULE" "$MNTIMAGE/lib/modules/$kernel/$MODULE"
4fd11db9 894 gunzip "$MNTIMAGE/lib/modules/$kernel/$MODULE" 2> /dev/null
bb529f94
JK
895done
896
897# mknod'ing the devices instead of copying them works both with and
898# without devfs...
35164381 899mknod "$MNTIMAGE/dev/console" c 5 1
eb6e37ff
MM
900mknod "$MNTIMAGE/dev/null" c 1 3
901mknod "$MNTIMAGE/dev/zero" c 1 5
bb529f94 902
84670990 903s="$RCFILE"
ef66f232 904
7543158a 905inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
ee3a3416 906ln -s sh "$MNTIMAGE/bin/busybox"
ef66f232 907
b2e62ae1
AF
908if is_yes "$USEINSMODSTATIC" ; then
909 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
57227e0a
AF
910fi
911
84670990
MM
912cat > "$s" <<EOF
913#! /bin/sh
914
d70364fa 915set -x
84670990
MM
916EOF
917chmod 755 "$s"
c31050f3 918
fd2dc249 919for MODULE in $MODULES; do
4fd11db9
AF
920 MODULE2="`my_dirname "$MODULE"`"
921 NAME2=`basename "$MODULE" .gz`
922 MODULE2=$MODULE2/$NAME2
0868f49f 923 module="`echo $MODULE | awk -F/ '{ $0=$NF } /'$modext'$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
fd2dc249 924 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
c31050f3 925
fd2dc249
AF
926 if [ -n "$verbose" ]; then
927 /bin/echo -n "Loading module $module "
928 if [ -n "$options" ] ; then
929 echo "with options $options."
ea10b6a5 930 else
fd2dc249 931 echo "without options."
7d2fc5eb 932 fi
7d2fc5eb 933 fi
0868f49f 934 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$s"
fd2dc249
AF
935done
936
937# TODO: rewrite for bsp
938#if [ -n "$loopDev" ]; then
939# if [ ! -d /initrd ]; then
940# mkdir /initrd
941# fi
942#
943# cp -a "$loopDev" "$MNTIMAGE/dev"
944# cp -a "$rootdev" "$MNTIMAGE/dev"
945# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
946# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
947# echo "echo Setting up loopback device $rootdev" >> $RCFILE
948# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
949#fi
bb529f94 950
7c38b114 951if is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
8c4ce35e
AM
952 [ -n "$verbose" ] && echo "Setting up mdadm ($rootdev $dev_list)"
953
994eb509 954 if [ ! -x /sbin/initrd-mdadm -a ! -x /sbin/initrd-mdassemble ] ; then
6d208806 955 echo "/sbin/initrd-mdadm and /sbin/initrd-mdassemble are missing !"
8c4ce35e 956 exit 1
d3fa6ec7 957 fi
994eb509
AM
958
959 if [ -x /sbin/initrd-mdassemble ] ; then
960 inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
961 echo "DEVICE $dev_list" > "$MNTIMAGE/etc/mdadm.conf"
962 echo "ARRAY $rootdev" >> "$MNTIMAGE/etc/mdadm.conf"
963 echo "mdassemble" >> "$s"
964 else
965 inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
966 echo "mdadm --assemble $rootdev $dev_list" >> "$s"
967 fi
fef73933 968
ef66f232
MM
969 # needed to determine md-version
970 if [ "$rootdev" != /dev/md0 ] ; then
971 mknod $MNTIMAGE/dev/md0 b 9 0
972 fi
973
974 for f in $dev_list $rootdev ; do
975 # mkdir in case of devfs name
976 mkdir -p `my_dirname $f`
977 [ -n "$verbose" ] && echo "copying $f"
978 # this works fine with and without devfs
979 cp -HR $f $MNTIMAGE/$f
980 done
2968c9dd
AF
981fi
982
7c38b114
AF
983if is_yes "$uselvm" ; then
984 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
985 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
986 mkdir $MNTIMAGE/tmp
987 mkdir $MNTIMAGE/proc
84670990
MM
988 echo "mount -t proc none /proc" >> "$s"
989 echo "mount -t tmpfs none /tmp" >> "$s"
990 echo "mount -t devfs none /dev" >> "$s"
7c38b114 991 echo "lvm vgscan -T" >> "$s"
78ba9381 992 echo "lvm vgchange -T -a y" >> "$s"
7c38b114
AF
993 echo "umount /tmp" >> "$s"
994 echo "umount /proc" >> "$s"
0868f49f 995 # fail to umount
14e7b1aa 996 echo "umount /devfs" >> "$s"
7c38b114
AF
997fi
998
35164381 999chmod +x "$RCFILE"
bb529f94 1000
35164381 1001(cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
bb529f94 1002
2ad94d8a 1003case "$INITRDFS" in
8b1e4ac7 1004 ext2)
35164381 1005 umount "$IMAGE"
8b1e4ac7
AF
1006 ;;
1007 rom)
1008 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1009 ;;
1010 cram)
1011 mkcramfs "$MNTPOINT" "$IMAGE"
8b1e4ac7
AF
1012 ;;
1013 *)
2ad94d8a 1014 echo "Filesystem $INITRDFS not supported by $0";
c31050f3 1015esac
bb529f94
JK
1016
1017if is_yes "$COMPRESS" ; then
7d2fc5eb 1018 gzip -9 < "$IMAGE" > "$target"
bb529f94 1019else
7d2fc5eb 1020 cp -a "$IMAGE" "$target"
bb529f94 1021fi
5b71959c
AM
1022
1023if is_yes "$BOOT_SPLASH"; then
1024 if [ ! -x /bin/splash.bin ]; then
1025 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1026 elif [ -z "$THEME" ]; then
1027 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1028 echo "Generating bootsplashes skipped." 1>&2
1029 else
350cd2f9 1030 if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
5b71959c
AM
1031 for res in $BOOT_SPLASH_RESOLUTIONS; do
1032 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1033 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1034 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1035 else
1036 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1037 fi
1038 done
350cd2f9
AM
1039 else
1040 echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1041 echo "Not adding bootsplash to initrd." 1>&2
1042 fi
5b71959c
AM
1043 fi
1044fi
1045
35164381 1046rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
This page took 0.185483 seconds and 4 git commands to generate.