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