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