]> git.pld-linux.org Git - projects/geninitrd.git/blame - geninitrd
Merged bootsplash branch.
[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 () {
a2c2980f 43 echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]" 1>&2
c31050f3 44 echo " [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" 1>&2
fd2dc249 45 echo " [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]" 1>&2
57227e0a 46 echo " [--with-raidstart] [--without-raidstart] [--with-insmod-static]" 1>&2
5b71959c 47 echo " [--with-mdadm-static] [--without-bootsplash]" 1>&2
a2c2980f
AF
48 echo " <initrd-image> <kernel-version>" 1>&2
49 echo " (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" 1>&2
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() {
4fbd2e61 319 if is_yes "$USEMDADMSTATIC" || [ -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
580 elif ls -l "$1"|awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'; then
581 if [ ! -f /sbin/initrd-lvm ] ; then
582 echo "ERROR: root on LVM but /sbin/initrd-lvm not found."
583 echo "Please install lvm-initrd package and rerun $0."
584 exit 1
585 fi
586 if [ -n "$PVDEVICES" ] ; then
587 for device in $PVDEVICES; do
588 find_modules_for $device
589 done
590 else
591 echo "ERROR: Sorry, but searching for PV isn't implemented yet."
592 echo "Use PVDEVICES in /etc/sysconfig/geninitrd to set it."
593 exit 1
594 fi
595 findmodule "-lvm"
596 findmodule "-lvm-mod"
597 uselvm="yes"
598 fi
599}
600
5dc785c7 601if [ -r /etc/sysconfig/geninitrd ] ; then
602 . /etc/sysconfig/geninitrd
603fi
604
5b71959c
AM
605if [ -r /etc/sysconfig/bootsplash ] ; then
606 . /etc/sysconfig/bootsplash
607fi
608
2ad94d8a
AF
609if [ "x" = "x$INITRDFS" ] ; then
610 if [ "x" = "x$FS" ] ; then
611 # default value
612 INITRDFS="rom"
613 else
614 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
615 INITRDFS="$FS"
616 fi
617fi
618
2baa76b4
AM
619if [ ! -x /bin/initrd-busybox ] ; then
620 echo "/bin/initrd-busybox is missing !"
fd2dc249 621 exit 1
5dc785c7 622fi
623if [ "`uname -m`" = "ia64" ]; then
624 IMAGESIZE=3000
625else
626 IMAGESIZE=1500
627fi
bb529f94 628while [ $# -gt 0 ]; do
413878f8 629 case $1 in
6bd433bc
AF
630 --fstab=*)
631 fstab="`echo $1 | awk -F= '{print $2;}'`"
632 ;;
633 --fstab)
634 fstab="$2"
635 shift
413878f8 636 ;;
cd670d83
AF
637 --modules-conf=*)
638 modulefile="`echo $1 | awk -F= '{print $2;}'`"
639 ;;
57188d60 640 --modules-conf)
cd670d83
AF
641 modulefile="$2"
642 shift
643 ;;
611e9e47
AF
644 --raidtab=*)
645 raidtab="`echo $1 | awk -F= '{print $2;}'`"
646 ;;
647 --raidtab)
648 raidtab="$2"
649 shift
650 ;;
6bd433bc
AF
651 --use-raidstart|--with-raidstart)
652 USERAIDSTART="yes"
653 ;;
654 --without-raidstart)
655 USERAIDSTART="no"
656 ;;
d3fa6ec7
AM
657 --use-mdadm-static|--with-mdadm-static)
658 USEMDADMSTATIC="yes"
659 ;;
57227e0a
AF
660 --use-insmod-static|--with-insmod-static)
661 USEINSMODSTATIC="yes"
662 ;;
663 --without-insmod-static)
664 USEINSMODSTATIC="no"
665 ;;
5b71959c
AM
666 --without-bootsplash)
667 BOOT_SPLASH="no"
668 ;;
6bd433bc
AF
669 --with=*)
670 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
671 ;;
672 --with)
673 BASICMODULES="$BASICMODULES $2"
674 shift
413878f8 675 ;;
bb529f94 676 --version)
413878f8 677 echo "geninitrd: version $VERSION"
678 exit 0
679 ;;
bb529f94 680 -v)
413878f8 681 verbose=-v
682 ;;
bb529f94 683 --nocompress)
413878f8 684 COMPRESS="no"
685 ;;
bb529f94 686 --ifneeded)
413878f8 687 ifneeded=1
688 ;;
bb529f94 689 -f)
413878f8 690 force=1
691 ;;
6bd433bc
AF
692 --preload=*)
693 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
694 ;;
695 --preload)
72623c13 696 PREMODS="$PREMODS $2"
6bd433bc 697 shift
413878f8 698 ;;
2ad94d8a
AF
699 --fs=*)
700 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
701 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
702 ;;
2ad94d8a
AF
703 --fs)
704 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
705 INITRDFS="$2"
706 shift
cd670d83 707 ;;
6bd433bc
AF
708 --initrdfs=*)
709 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
710 ;;
fd2dc249 711 --initrdfs)
2ad94d8a 712 INITRDFS="$2"
413878f8 713 shift
714 ;;
bb529f94 715 --image-version)
413878f8 716 img_vers=yes
717 ;;
4f4e832d
AM
718 --ide-only-root)
719 ide_only_root="yes"
720 ;;
bb529f94 721 *)
413878f8 722 if [ -z "$target" ]; then
723 target="$1"
724 elif [ -z "$kernel" ]; then
725 kernel="$1"
726 else
727 usage
728 fi
729 ;;
730 esac
731
732 shift
bb529f94
JK
733done
734
06ac05d6 735if [ -z "$target" -o -z "$kernel" ]; then
413878f8 736 usage
06ac05d6
AF
737fi
738
0868f49f 739pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
64497ebb 740pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
0868f49f
AF
741
742if [ "$pack_version" -ge "002005" ] ; then
743 modext=".ko"
0b6536f5 744 insmod="insmod"
0868f49f
AF
745fi
746
57227e0a
AF
747if is_yes "$USEINSMODSTATIC" ; then
748 insmod="insmod.static"
b2e62ae1 749 INSMOD="/sbin/insmod.static"
f7c18703
AM
750 if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
751 INSMOD="/sbin/insmod.static.modutils"
b2e62ae1
AF
752 fi
753 if [ ! -f "$INSMOD" ] ; then
754 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
755 exit 1
756 fi
57227e0a
AF
757fi
758
2ad94d8a 759case "$INITRDFS" in
8b1e4ac7 760 ext2)
f5d71bb2 761 if [ ! -x /sbin/mke2fs ]; then
a2c2980f 762 echo "/sbin/mke2fs is missing" 1>&2
8b1e4ac7
AF
763 exit 1
764 fi
765 ;;
766 rom)
767 if [ ! -x /sbin/genromfs ]; then
a2c2980f 768 echo "/sbin/genromfs is missing" 1>&2
8b1e4ac7
AF
769 exit 1
770 fi
771 ;;
772 cram)
773 if [ ! -x /sbin/mkcramfs ]; then
a2c2980f 774 echo "/sbin/mkcramfs is missing" 1>&2
8b1e4ac7
AF
775 exit 1
776 fi
c31050f3 777 ;;
8b1e4ac7 778 *)
2ad94d8a 779 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
8b1e4ac7
AF
780 exit 1
781 ;;
782esac
bb529f94 783
bb529f94 784if [ -n "$img_vers" ]; then
413878f8 785 target="$target-$kernel"
bb529f94
JK
786fi
787
35164381 788if [ -z "$force" -a -f "$target" ]; then
a2c2980f 789 echo "$target already exists." 1>&2
413878f8 790 exit 1
bb529f94
JK
791fi
792
35164381 793if [ ! -d "/lib/modules/$kernel" ]; then
a2c2980f 794 echo "/lib/modules/$kernel is not a directory." 1>&2
413878f8 795 exit 1
bb529f94
JK
796fi
797
798for n in $PREMODS; do
35164381 799 findmodule "$n"
bb529f94
JK
800done
801
7c38b114
AF
802# allow forcing loading SCSI and/or IDE modules
803if is_yes "$ADDSCSI" ; then
804 find_modules_scsi
bb529f94
JK
805fi
806
7c38b114
AF
807if is_yes "$ADDIDE" ; then
808 find_modules_ide
cd670d83
AF
809fi
810
7c38b114 811find_root
cd670d83 812
7c38b114 813find_modules_for "$rootdev"
cd670d83 814
7c38b114 815findmodule "-$rootFs"
bb529f94 816
c31050f3 817for n in $BASICMODULES; do
7d2fc5eb 818 findmodule "$n"
bb529f94
JK
819done
820
7c38b114 821
bb529f94 822if [ -n "$ifneeded" -a -z "$MODULES" ]; then
7d2fc5eb 823 if [ -n "$verbose" ]; then
824 echo "No modules are needed -- not building initrd image."
825 fi
826 exit 0
bb529f94
JK
827fi
828
829if [ -n "$verbose" ]; then
7d2fc5eb 830 echo "Using modules: $MODULES"
bb529f94
JK
831fi
832
35164381
SZ
833MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
834IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
835MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
836RCFILE="$MNTIMAGE/linuxrc"
bb529f94 837
35164381 838if [ -f "$MNTIMAGE" ]; then
c31050f3 839 echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 840 exit 1
bb529f94
JK
841fi
842
35164381 843if [ -f "$IMAGE" ]; then
a2c2980f 844 echo "$IMAGE already exists. Remove it and try again" 1>&2
7d2fc5eb 845 exit 1
bb529f94
JK
846fi
847
2ad94d8a 848if [ "$INITRDFS" = "ext2" ] ; then
35164381 849 dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
bb529f94 850
bb529f94
JK
851 # We have to "echo y |" so that it doesn't complain about $IMAGE not
852 # being a block device
35164381 853 echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
bb529f94 854
35164381
SZ
855 mkdir -p "$MNTPOINT"
856 mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
bb529f94 857else
35164381 858 mkdir -p "$MNTPOINT"
bb529f94
JK
859fi
860
8b1e4ac7 861
35164381 862mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs}
8b1e4ac7 863
bb529f94
JK
864
865# We don't need this directory, so let's save space
35164381 866rm -rf "$MNTPOINT"/lost+found
bb529f94 867
bb529f94 868for MODULE in $MODULES; do
81de8443
AF
869 MODULEDIR="`my_dirname "$MODULE"`"
870 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
871 cp $verbose -a "/lib/modules/$kernel/$MODULE" "$MNTIMAGE/lib/modules/$kernel/$MODULE"
4fd11db9 872 gunzip "$MNTIMAGE/lib/modules/$kernel/$MODULE" 2> /dev/null
bb529f94
JK
873done
874
875# mknod'ing the devices instead of copying them works both with and
876# without devfs...
35164381 877mknod "$MNTIMAGE/dev/console" c 5 1
eb6e37ff
MM
878mknod "$MNTIMAGE/dev/null" c 1 3
879mknod "$MNTIMAGE/dev/zero" c 1 5
bb529f94 880
84670990 881s="$RCFILE"
ef66f232 882
7543158a 883inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
ee3a3416 884ln -s sh "$MNTIMAGE/bin/busybox"
ef66f232 885
b2e62ae1
AF
886if is_yes "$USEINSMODSTATIC" ; then
887 inst "$INSMOD" $MNTIMAGE/bin/insmod.static
57227e0a
AF
888fi
889
84670990
MM
890cat > "$s" <<EOF
891#! /bin/sh
892
d70364fa 893set -x
84670990
MM
894EOF
895chmod 755 "$s"
c31050f3 896
fd2dc249 897for MODULE in $MODULES; do
4fd11db9
AF
898 MODULE2="`my_dirname "$MODULE"`"
899 NAME2=`basename "$MODULE" .gz`
900 MODULE2=$MODULE2/$NAME2
0868f49f 901 module="`echo $MODULE | awk -F/ '{ $0=$NF } /'$modext'$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
fd2dc249 902 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
c31050f3 903
fd2dc249
AF
904 if [ -n "$verbose" ]; then
905 /bin/echo -n "Loading module $module "
906 if [ -n "$options" ] ; then
907 echo "with options $options."
ea10b6a5 908 else
fd2dc249 909 echo "without options."
7d2fc5eb 910 fi
7d2fc5eb 911 fi
0868f49f 912 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$s"
fd2dc249
AF
913done
914
915# TODO: rewrite for bsp
916#if [ -n "$loopDev" ]; then
917# if [ ! -d /initrd ]; then
918# mkdir /initrd
919# fi
920#
921# cp -a "$loopDev" "$MNTIMAGE/dev"
922# cp -a "$rootdev" "$MNTIMAGE/dev"
923# echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
924# echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
925# echo "echo Setting up loopback device $rootdev" >> $RCFILE
926# echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
927#fi
bb529f94 928
7c38b114 929if is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
d3fa6ec7
AM
930 if is_yes "$USEMDADMSTATIC" ; then
931 [ -n "$verbose" ] && echo "Setting up mdadm"
932 inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
933 echo "mdadm --assemble $rootdev $dev_list" >> "$s"
934 else
d70364fa
AM
935 [ -n "$verbose" ] && echo "Enabling raid ($rootdev $dev_list)"
936 echo "raid_start $rootdev $dev_list" >> "$s"
d3fa6ec7 937 fi
fef73933 938
ef66f232
MM
939 # needed to determine md-version
940 if [ "$rootdev" != /dev/md0 ] ; then
941 mknod $MNTIMAGE/dev/md0 b 9 0
942 fi
943
944 for f in $dev_list $rootdev ; do
945 # mkdir in case of devfs name
946 mkdir -p `my_dirname $f`
947 [ -n "$verbose" ] && echo "copying $f"
948 # this works fine with and without devfs
949 cp -HR $f $MNTIMAGE/$f
950 done
2968c9dd
AF
951fi
952
7c38b114
AF
953if is_yes "$uselvm" ; then
954 [ -n "$verbose" ] && echo "Adding LVM support to initrd"
955 inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
956 mkdir $MNTIMAGE/tmp
957 mkdir $MNTIMAGE/proc
84670990
MM
958 echo "mount -t proc none /proc" >> "$s"
959 echo "mount -t tmpfs none /tmp" >> "$s"
960 echo "mount -t devfs none /dev" >> "$s"
7c38b114 961 echo "lvm vgscan -T" >> "$s"
78ba9381 962 echo "lvm vgchange -T -a y" >> "$s"
7c38b114
AF
963 echo "umount /tmp" >> "$s"
964 echo "umount /proc" >> "$s"
0868f49f
AF
965 # fail to umount
966 #echo "umount /devfs" >> "$s"
7c38b114
AF
967fi
968
35164381 969chmod +x "$RCFILE"
bb529f94 970
35164381 971(cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
bb529f94 972
2ad94d8a 973case "$INITRDFS" in
8b1e4ac7 974 ext2)
35164381 975 umount "$IMAGE"
8b1e4ac7
AF
976 ;;
977 rom)
978 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
979 ;;
980 cram)
981 mkcramfs "$MNTPOINT" "$IMAGE"
8b1e4ac7
AF
982 ;;
983 *)
2ad94d8a 984 echo "Filesystem $INITRDFS not supported by $0";
c31050f3 985esac
bb529f94
JK
986
987if is_yes "$COMPRESS" ; then
7d2fc5eb 988 gzip -9 < "$IMAGE" > "$target"
bb529f94 989else
7d2fc5eb 990 cp -a "$IMAGE" "$target"
bb529f94 991fi
5b71959c
AM
992
993if is_yes "$BOOT_SPLASH"; then
994 if [ ! -x /bin/splash.bin ]; then
995 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
996 elif [ -z "$THEME" ]; then
997 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
998 echo "Generating bootsplashes skipped." 1>&2
999 else
1000 for res in $BOOT_SPLASH_RESOLUTIONS; do
1001 if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1002 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1003 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1004 else
1005 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1006 fi
1007 done
1008 fi
1009fi
1010
35164381 1011rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
This page took 0.20843 seconds and 4 git commands to generate.