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