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