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