]> git.pld-linux.org Git - projects/geninitrd.git/blob - geninitrd
e8c4d3331d04f04a11ad75417149fb04011b048a
[projects/geninitrd.git] / geninitrd
1 #!/bin/sh
2
3 # geninitrd
4 #
5 #       by Jacek Konieczny <jajcus@pld-linux.org>
6 #
7 # based on mkinitrd from RedHat
8
9 RCSID='$Id$'
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 USESUSPEND="yes"
24 uselvm="no"
25 usenfs="no"
26 # it should be safe to remove scsi_mod from here, but I'm not sure...
27 PRESCSIMODS="-scsi_mod unknown -sd_mod"
28 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
29 PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
30 SUSPENDMODS="-suspend2_core -suspend2_lzf -suspend2_block_io -suspend2_swap -suspend_core -suspend_text -suspend_lzf -suspend_block_io -suspend_swap"
31 target=""
32 kernel=""
33 force=""
34 verbose=""
35 MODULES=""
36 img_vers=""
37 modulefile=""
38 raidtab="/etc/raidtab"
39 fstab="/etc/fstab"
40 insmod="insmod"
41 modext=".o"
42 rootdev_nr=0
43 # default bootsplash is off, if it have to be on, install bootsplash package
44 BOOT_SPLASH=no
45
46 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udev ]; then
47         USE_UDEV="yes"
48         UDEV_TMPFS="yes"
49         . /etc/udev/udev.conf
50 fi
51                             
52 usage () {
53         echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]" 
54         echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" 
55         echo "       [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]" 
56         echo "       [--with-raidstart] [--without-raidstart] [--with-insmod-static]" 
57         echo "       [--without-bootsplash] [--lvmtoolsversion=1|2] [--without-udev]"
58         echo "       [--without-suspend]"
59         echo "       <initrd-image> <kernel-version>" 
60         echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" 
61         exit 1
62 }
63
64
65 my_dirname() {
66         echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
67 }
68
69 find_depmod () {
70         typeset mods module f level depfile first
71
72         depfile=/lib/modules/$kernel/modules.dep
73         
74         if [ -f $depfile ] ; then
75                 : ok
76         else
77                 echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
78                 exit 1
79         fi
80         
81         # prepend / if no path given, append $modext.gz if not given,
82         # quote /
83         origmodule="$2"
84         module=$(echo "$2" | \
85                  awk '/\// {print;next} {print "/" $0}' | \
86                  awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
87                  awk '{gsub("/","\\/");print}')
88         mods=$(awk '
89 BEGIN { here = 0 }
90 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
91 /:/ { here = 0 }
92 /(.*)/ { gsub(/\\/," "); if (here) print }
93 ' $depfile | xargs)
94
95         # fallback to $modext
96         if [ "$mods" = "" ] ; then
97             module=$(echo "$module" | \
98                     awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
99         fi 
100         mods=$(awk '
101 BEGIN { here = 0 }
102 /'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
103 /:/ { here = 0 }
104 /(.*)/ { gsub(/\\/," "); if (here) print }
105 ' $depfile | xargs)
106
107         if [ "$mods" = "" ] ; then
108                 if [ "$1" != silent ] ; then
109                         echo "$origmodule: module not found in $depfile" 1>&2
110                 fi
111                 if ! is_no "$EXIT_IF_MISSING" ; then 
112                         exit 1
113                 else
114                         echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
115                 fi
116         fi
117         
118         level=$3
119         if [ "$level" = "" ] ; then
120                 level=0
121         fi
122         level=$(awk "BEGIN{print $level + 1}")
123         if [ $level -gt 20 ] ; then
124                 echo "$origmodule: cycle in $depfile" 1>&2
125                 exit 1
126         fi
127         
128         first=
129         for f in $mods ; do
130                 if [ "$first" = "" ] ; then
131                         first=$f
132                 else
133                         find_depmod $1 $f $level
134                 fi
135         done
136         
137         echo $first
138 }
139
140 addmodule() {
141         fmPath=$1
142         skiperrors=$2
143
144         if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
145                 if [ -n "$skiperrors" ]; then
146                         return
147                 fi
148
149                 echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
150                 exit 1
151         fi
152
153         # only need to add each module once
154         # quote /
155         tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
156         if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
157                 MODULES="$MODULES $fmPath"
158         fi
159 }
160
161 findmodule() {
162         skiperrors=""
163         modName=$1
164
165         if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
166                 skiperrors=1
167                 modName="$(echo $modName | awk '{print(substr($0,2));}')"
168         fi
169
170         # what's that?
171         if [ "$modName" = "pluto" ]; then
172                 findmodule fc4
173                 findmodule soc
174         fi
175         if [ "$modName" = "fcal" ]; then
176                 findmodule fc4
177                 findmodule socal
178         fi
179
180         if [ -n "$skiperrors" ]; then
181                 allModulesToFind=`find_depmod silent $modName`
182         else
183                 allModulesToFind=`find_depmod normal $modName`
184                 if [ $? != 0 ] ; then
185                         exit 1
186                 fi
187         fi
188         
189         for mod in $allModulesToFind ; do
190                 mod=$(echo $mod | \
191                       awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
192                 addmodule $mod "$skiperrors"
193         done
194 }
195
196 inst() {
197         if [ "$#" != "2" ];then
198                 echo "usage: inst <file> <destination>"
199                 return
200         fi
201         [ -n "$verbose" ] && echo "$1 -> $2"
202         cp "$1" "$2"
203 }
204
205 get_label_ext2 () {
206         /sbin/e2label $1 2> /dev/null
207 }
208
209 get_uuid_ext2 () {
210         /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
211 }
212
213 get_label_xfs () {
214         /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
215
216 }
217
218 get_uuid_xfs () {
219         /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
220 }
221
222 find_root() {
223         eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
224         case $rootdev in
225         LABEL=*)
226                 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
227                         rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
228                         if [ -n "$rootdev2" ] ; then
229                                 rootdev=$rootdev2
230                                 rootdev_found=1
231                         fi
232                 fi
233                 if [ "$rootdev_found." != "1." ] ; then
234                         case $rootFs in
235                         ext2|ext3)
236                                 if [ ! -x /sbin/e2label ] ; then
237                                         echo "/sbin/e2label is missing" 1>&2
238                                         exit 1
239                                 fi
240                                 get_label="get_label_ext2"
241                                 ;;
242                         xfs)
243                                 if [ ! -x /usr/sbin/xfs_db ] ; then
244                                         echo "/usr/sbin/xfs_db is missing" 1>&2
245                                         exit 1
246                                 fi
247                                 get_label="get_label_xfs"
248                                 ;;
249                         *)
250                                 echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
251                                 exit 1
252                                 ;;
253                         esac
254                         if [ ! -r /proc/partitions ] ; then
255                                 echo '/proc/partitions is not readable'; 1>&2
256                                 exit 1
257                         fi
258                         label=${rootdev#"LABEL="}
259                         for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
260                                 if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
261                                         if [ -n "$verbose" ] ; then
262                                                 echo "Using $dev as device for rootfs"
263                                         fi
264                                         rootdev=$dev
265                                         rootdev_found=1
266                                         break
267                                 fi
268                         done
269                         if [ "$rootdev_found." != "1." ] ; then
270                                 echo "geninitrd can't find real device for LABEL=$label" 1>&2
271                                 exit 1
272                         fi
273                 fi
274                 ;;
275         UUID=*)
276                 if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
277                         rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
278                         if [ -n "$rootdev2" ] ; then
279                                 rootdev=$rootdev2
280                                 rootdev_found=1
281                         fi
282                 fi
283                 if [ "$rootdev_found." != "1." ] ; then
284                         case $rootFs in
285                         ext2|ext3)
286                                 if [ ! -x /sbin/tune2fs ] ; then
287                                         echo "/sbin/tune2fs is missing" 1>&2
288                                         exit 1
289                                 fi
290                                 get_uuid="get_uuid_ext2"
291                                 ;;
292                         xfs)
293                                 if [ ! -x /usr/sbin/xfs_db ] ; then
294                                         echo "/usr/sbin/xfs_db is missing" 1>&2
295                                         exit 1
296                                 fi
297                                 get_label="get_uuid_xfs"
298                                 ;;
299                         *)
300                                 echo "UUID on $rootFs in not supported by geninitrd" 1>&2
301                                 exit 1
302                                 ;;
303                         esac
304                         if [ ! -r /proc/partitions ] ; then
305                                 echo '/proc/partitions is not readable'; 1>&2
306                                 exit 1
307                         fi
308                         uuid=${rootdev#"UUID="}
309                         for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
310                                 if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
311                                         if [ -n "$verbose" ] ; then
312                                                 echo "Using $dev as device for rootfs"
313                                         fi
314                                         rootdev=$dev
315                                         rootdev_found=1
316                                         break
317                                 fi
318                         done
319                         if [ "$rootdev_found" != 1 ] ; then
320                                 echo "geninitrd can't find real device for UUID=$uuid" 1>&2
321                                 exit 1
322                         fi
323                 fi
324                 ;;
325         esac
326         rootdev1=${rootdev}
327 }
328
329 find_modules_softraid() {
330         if [ -f /etc/mdadm.conf ] ; then
331             [ -n "$verbose" ] && echo "Finding RAID details using mdadm for rootdev=$1"
332             eval `/sbin/mdadm -v --examine  --scan --config=/etc/mdadm.conf | \
333                   awk -v rootdev="$1" '
334         BEGIN {
335                 found = "no";
336                 dev_list = "";
337                 raidlevel = ""
338                 rootdev_devfs = rootdev;
339                 if (rootdev ~ /\/dev\/md\/[0-9]/) {
340                     gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
341                 }
342         }
343
344         /^ARRAY/ {
345             if (($2 == rootdev) || ($2 == rootdev_devfs)) {
346                 raidlevel=$3;
347                 gsub(/level=/,NUL,raidlevel);
348                 if (raidlevel ~ /^raid[0-5]/) {
349                     gsub(/raid/,NUL,raidlevel);
350                 };
351                 found="yes";
352                 getline x;
353                 if (x ~ /devices=/) {
354                         dev_list = x;
355                         gsub("devices=", NUL, dev_list);
356                         gsub(",", " ", dev_list);
357                 }
358             }
359         }
360  
361         END {
362                 print "raidfound=" found;
363                 print "raidlevel=" raidlevel;
364                 print "dev_list=\"" dev_list "\"";
365         }'`
366         fi
367         if [ "$raidfound" != "yes" ]; then
368             [ -n "$verbose" ] && echo "Finding RAID details using raidtab for rootdev=$1"
369             eval `awk -v rootdev="$1" 'BEGIN {
370         found="no";
371         dev_list="";
372         rootdev_devfs = rootdev;
373         if (rootdev ~ /\/dev\/md\/[0-9]/) {
374             gsub(/\/dev\/md\//,"/dev/md",rootdev_devfs);
375         }
376 }
377
378 {
379         gsub("\t"," ");
380         gsub("  +", " ");
381         gsub("^ ","");
382         if (/^[\t ]*#/)
383                 next;
384         if (/^raiddev/) {
385                 if (($2 == rootdev) || ($2 == rootdev_devfs)) {
386                         found="yes";
387                 } else {
388                         if (found == "yes") {
389                                 exit 0;
390                         };
391                 };
392         };
393         if (found == "yes") {
394                 if ($1 == "device") {
395                         dev_list = dev_list " " $2;
396                 };
397                 if ($1 == "raid-level") {
398                         raidlevel=$2;
399                 }
400         };
401 }
402
403 END {
404         print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
405 }' $raidtab `
406         fi
407         
408         if is_yes "$raidfound" ; then
409                 case "$raidlevel" in
410                 [0145])
411                         findmodule "raid$raidlevel"
412                         ;;
413                 linear)
414                         findmodule "linear"
415                         ;;
416                 *)
417                         echo "raid level $number (in $raidtab) not recognized" 1>&2
418                         ;;
419                 esac
420         else
421                 echo "ERROR: RAID devices not found for \"$1\", check your configuration!" 1>&2
422                 exit 1
423         fi
424
425         rootdev_nr=$(( $rootdev_nr + 1 ))
426         eval "rootdev${rootdev_nr}=\"$1\""
427         eval "dev_list${rootdev_nr}=\"${dev_list}\""
428         
429         for device in $dev_list; do
430                 find_modules_for $device
431         done
432 }
433
434 find_modules_scsi() {
435         for n in $PRESCSIMODS; do
436                 if [ "X$n" = "Xunknown" ] ; then
437                         if [ -f "$modulefile" ]; then
438                                 scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
439                                 for n in $scsimodules; do
440                         # for now allow scsi modules to come from anywhere. There are some
441                         # RAID controllers with drivers in block
442                                         findmodule "$n"
443                                 done
444                         fi
445                 else
446                         findmodule "$n"
447                 fi
448         done
449 }
450
451 find_modules_ide() {
452         typeset rootdev
453
454         rootdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
455         if [ "$pack_version_long" -lt "002004021" ]; then
456             [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
457             for n in $PREIDEMODSOLD; do
458                 findmodule "$n"
459             done
460         else
461             tryauto=1
462             for n in $PREIDEMODS; do
463                 if [ "X$n" = "Xunknown" ] ; then
464                     if [ -f "$modulefile" ]; then
465                          [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
466                         idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
467                         for na in $idemodules; do
468                             tryauto=0;
469                             findmodule "$na"
470                         done
471                     fi
472
473                     if [ "$tryauto" -eq 1 ]; then
474                       if [ -r /usr/share/pci-database/ide.pci -a -r /proc/bus/pci/devices  ]; then
475                         [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
476                         if is_yes "${ide_only_root}"; then
477                           if [ -f /sys/block/${rootdev}/device/../../vendor -a -f /sys/block/${rootdev}/device/../../device ] ; then
478                             vendorid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../vendor)"
479                             deviceid="$(awk ' { gsub(/0x/,NUL); print $0 } ' /sys/block/${rootdev}/device/../../device)"
480                             searchpciid="${vendorid}${deviceid}"
481                           elif [ -f /proc/ide/${rootdev}/../config ]; then
482                             searchpciid="$(awk ' /pci bus/ { print $7$9 } ' /proc/ide/${rootdev}/../config)"
483                           fi
484                         fi
485                         if [ -z "${searchpciid}" ]; then
486                             searchpciid="$(awk ' { print $2 } ' /proc/bus/pci/devices)"
487                         fi
488                         idemodules=""
489                         for nb in $searchpciid; do
490                             eval `awk -v pciid="$nb" 'BEGIN {
491 }
492                 
493 {
494         gsub("\t"," ");
495         gsub("  +", " ");
496         gsub("^ ","");
497         if (/^[\t ]*#/)
498                 next;
499         compmod = $1 "";        # make sure comparison type will be string
500                                 # cause pci IDs are hexadecimal numeric
501         if (compmod == pciid) {
502                 module=$2;
503 #               min_kernel=$3;  # now in ide.pci $3,$4 = vendor and device name
504 #               max_kernel=$4;  #
505                 exit 0;
506         }
507 }
508
509 END {
510         print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
511 }' /usr/share/pci-database/ide.pci`
512                             [ -n "$module" ] && idemodules="$idemodules $module"
513                         done
514                         if is_yes "$(awk ' /ide=reverse/ { print "yes" } ' /proc/cmdline)"; then
515                                 new_idemodules=""
516                                 for nc in idemodules; do
517                                     new_idemodules="$nc $new_idemodules"
518                                 done
519                                 idemodules="${new_idemodules}"
520                         fi
521                         if [ -z "$idemodules" ]; then
522                             echo "WARNING: rootfs on IDE device but no related modules found, loading ide-generic."
523                             idemodules="ide-generic"
524                         fi
525                         for nd in $idemodules; do
526                             findmodule "-$nd"
527                         done
528                       else
529                          [ -r /usr/share/pci-database/ide.pci ] || echo "WARNING: /usr/share/pci-database/ide.pci missing."
530                          [ -r /proc/bus/pci/devices ] || echo "WARNING: /proc/bus/pci/devices missing."
531                          echo "Automatic IDE modules finding not available."
532                       fi
533                     fi
534                 else
535                         findmodule "$n"
536                 fi
537             done
538         fi
539 }
540
541 find_modules_for() {
542         if [ -z "$1" ]; then
543                 echo "ERROR: no argument passed to find_modules_for() - is your /etc/fstab correct?" >&2
544                 exit
545         elif is_yes "`echo "$1" | awk '/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:|\/dev\/nfs)/ { print "yes"; }'`"; then
546                 if [ ! -x /usr/bin/pcidev -a -z "$NFS_ETH_MODULES" ] ; then
547                     echo "ERROR: root on NFS but /usr/bin/pcidev not found." >&2
548                     echo "Please install correct pci-database package and rerun $0." >&2
549                     exit 1
550                 fi
551                 [ -z "$NFS_ETH_MODULES" ] && NFS_ETH_MODULES=$(/usr/bin/pcidev /m net | xargs)
552                 for m in $NFS_ETH_MODULES; do
553                     findmodule "$m"
554                 done
555                 findmodule "-ipv4"
556                 findmodule "nfs"
557                 usenfs="yes"
558                 echo "Remember to use \`root=/dev/ram0 init=/linuxrc' when starting kernel" >&2
559                 echo "or you will have problems like init(xx) being child process of swapper(1)." >&2
560         elif is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
561                 find_modules_softraid "$1"
562         elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
563                 find_modules_scsi
564         elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
565                 find_modules_ide "$1"
566         elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
567                 findmodule "DAC960"
568         elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
569                 findmodule "cpqarray"
570         elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
571                 findmodule "cciss"
572         elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
573                 find_modules_ide
574                 findmodule "ataraid"
575                 ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
576                 if -n "$ataraidmodules" ; then
577                         # FIXME: think about modules compiled in kernel
578                         echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
579                         echo "Please set it and run $0 again."
580                         exit 1
581                 fi
582                 for n in $ataraidmodules; do
583                         findmodule "$n"
584                 done
585         # check to see if we need to set up a loopback filesystem
586         elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
587                 echo "Sorry, root on loop device isn't supported." 1>&2
588                 exit 1
589                 # TODO: rewrite for bsp and make nfs ready
590                 if [ ! -x /sbin/losetup ]; then
591                         echo "losetup is missing"
592                         exit 1
593                 fi
594                 key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
595                 if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
596                         echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
597                         echo "for this device. Consult the geninitrd man page for more information" 1>&2
598                         exit 1
599                 fi
600
601                 line="`awk '/'$key'/ { print $0; }' $fstab`"
602                 loopDev="$(echo $line | awk '{print $3}')"
603                 loopFs="$(echo $line | awk '{print $4}')"
604                 loopFile="$(echo $line | awk '{print $5}')"
605
606                 BASICMODULES="$BASICMODULES -loop"
607                 findmodule "-$loopFs"
608                 BASICMODULES="$BASICMODULES -${loopFs}"
609                 # don't have any clue, how is this supposed to work
610         elif [ -e "$1" ] && ls -l "$1" 2> /dev/null | awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}' || /sbin/lvm lvdisplay "$1" > /dev/null 2>&1 ; then
611                 if [ ! -f /sbin/initrd-lvm -o ! -x /sbin/lvdisplay -o ! -x /sbin/pvdisplay ] ; then
612                         echo "ERROR: root on LVM but /sbin/initrd-lvm, /sbin/lvdisplay and /sbin/pvdisplay not found." >&2
613                         echo "Please install lvm(2) and lvm(2)-initrd package and rerun $0." >&2
614                         exit 1
615                 fi
616                 if [ -z "$LVMTOOLSVERSION" ] ; then 
617                     LVMTOOLSVERSION=$(/sbin/initrd-lvm vgchange --version 2>/dev/null|head -n 1|awk '{gsub("vgchange: Logical Volume Manager ",NIL); gsub("LVM version:     ",NIL); gsub(/\..*/,NIL); print $1}')
618                     if [ -z "$LVMTOOLSVERSION" ] ; then
619                             echo "ERROR: Can't determine LVM tools version. Please set LVMTOOLSVERSION" >&2
620                             echo "and rerun $0." >&2
621                             exit 1
622                     fi
623                 fi
624                 if [ -z "$PVDEVICES" ] ; then
625                     VGVOLUME=$(/sbin/lvdisplay -c "$1" 2> /dev/null | awk -F":" ' { print $2 } ')
626                     PVDEVICES=$(/sbin/pvdisplay -c | awk -F":" -v vg="$VGVOLUME" ' BEGIN { devices="" } { if ($2 == vg) { devices = devices " " $1 } } END { print devices } ')
627                 fi
628                 if [ -n "$PVDEVICES" ] ; then
629                         for device in $PVDEVICES; do
630                                 find_modules_for $device
631                         done
632                 else
633                         echo "ERROR: I wasn't able to find PV (via lvdisplay and pvdisplay)." >&2 
634                         echo "You can try to set PVDEVICES in /etc/sysconfig/geninitrd." >&2
635                         exit 1
636                 fi
637                 if [ "$LVMTOOLSVERSION" = "2" ]; then
638                     findmodule "-dm-mod"
639                 elif [ "$LVMTOOLSVERSION" = "1" ]; then
640                     findmodule "-lvm"
641                     findmodule "-lvm-mod"
642                 else
643                         echo "ERROR: LVM version $LVMTOOLSVERSION is not supported yet." >&2
644                         exit 1
645                 fi
646                 uselvm="yes"
647         fi
648 }
649
650 modules_install() {
651         modules="$1"
652
653         for mod in $modules; do
654                 MODULEDIR="`my_dirname "$mod"`"
655                 mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
656                 cp $verbose -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
657                 gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
658         done
659 }
660
661 modules_add_linuxrc() {
662         modules="$1"
663         linuxrc="$2"
664  
665         for mod in $modules; do
666                 MODULE2="`my_dirname "$mod"`"
667                 NAME2=`basename "$mod" .gz`
668                 MODULE2=$MODULE2/$NAME2
669                 module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
670                 options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
671                 eval sleep_var="MODULE_${module}_SLEEP"
672
673                 if [ -n "$verbose" ]; then
674                         echo -n "Loading module [$module] "
675                         if [ -n "$options" ] ; then
676                                 echo -n "with options [$options]"
677                         else
678                                 echo -n "without options"
679                         fi
680                         if [ -n "$sleep_var" ]; then
681                                 echo " and $sleep_var sleep."
682                         else
683                                 echo "."
684                         fi
685                 fi
686                 echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$linuxrc"
687                 if [ -n "${sleep_var}" ]; then
688                         echo "usleep $sleep_var" >> "$linuxrc"
689                 fi
690         done
691 }
692
693 if [ -r /etc/sysconfig/geninitrd ] ; then
694         . /etc/sysconfig/geninitrd
695 fi
696
697 if [ -r /etc/sysconfig/bootsplash ] ; then
698         . /etc/sysconfig/bootsplash
699 fi
700
701 if [ ! -x /bin/initrd-busybox ] ; then 
702         echo "/bin/initrd-busybox is missing !"
703         exit 1
704 fi
705 case "$(uname -m)" in
706     ia64|amd64|x86_64|sparc64)
707         IMAGESIZE=3000
708         ;;
709     *)
710         IMAGESIZE=1500
711         ;;
712 esac
713
714 while [ $# -gt 0 ]; do
715         case $1 in
716         --fstab=*)
717                 fstab="`echo $1 | awk -F= '{print $2;}'`"
718                 ;;
719         --fstab)
720                 fstab="$2"
721                 shift
722                 ;;
723         --modules-conf=*)
724                 modulefile="`echo $1 | awk -F= '{print $2;}'`"
725                 ;;
726         --modules-conf)
727                 modulefile="$2"
728                 shift
729                 ;;
730         --raidtab=*)
731                 raidtab="`echo $1 | awk -F= '{print $2;}'`"
732                 ;;
733         --raidtab)
734                 raidtab="$2"
735                 shift
736                 ;;
737         --use-raidstart|--with-raidstart)
738                 USERAIDSTART="yes"
739                 ;;
740         --without-raidstart)
741                 USERAIDSTART="no"
742                 ;;
743         --use-insmod-static|--with-insmod-static)
744                 USEINSMODSTATIC="yes"
745                 ;;
746         --without-insmod-static)
747                 USEINSMODSTATIC="no"
748                 ;;
749         --without-bootsplash)
750                 BOOT_SPLASH="no"
751                 ;;
752         --without-suspend)
753                 USESUSPEND="no";
754                 ;;
755         --lvmtoolsversion=|--lvmversion=)
756                 LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
757                 ;;
758         --lvmtoolsversion|--lvmversion)
759                 LVMTOOLSVERSION="$2"
760                 shift
761                 ;;
762         --without-udev)
763                 USE_UDEV=
764                 ;;
765         --with=*)
766                 BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
767                 ;;
768         --with)
769                 BASICMODULES="$BASICMODULES $2"
770                 shift
771                 ;;
772         --version)
773                 echo "geninitrd: version $VERSION"
774                 exit 0
775                 ;;
776         -v)
777                 verbose=-v
778                 ;;
779         --nocompress)
780                 COMPRESS="no"
781                 ;;
782         --ifneeded)
783                 ifneeded=1
784                 ;;
785         -f)
786                 force=1
787                 ;;
788         --preload=*)
789                 PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
790                 ;;
791         --preload)
792                 PREMODS="$PREMODS $2"
793                 shift
794                 ;;
795         --fs=*)
796                 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
797                 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
798                 ;;
799         --fs)
800                 echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
801                 INITRDFS="$2"
802                 shift
803                 ;;
804         --initrdfs=*)
805                 INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
806                 ;;
807         --initrdfs)
808                 INITRDFS="$2"
809                 shift
810                 ;;
811         --image-version)
812                 img_vers=yes
813                 ;;
814         --ide-only-root)
815                 ide_only_root="yes"
816                 ;;
817         *)
818                 if [ -z "$target" ]; then
819                         target="$1"
820                 elif [ -z "$kernel" ]; then
821                         kernel="$1"
822                 else
823                         usage
824                 fi
825                 ;;
826         esac
827
828         shift
829 done
830
831 if [ -z "$target" -o -z "$kernel" ]; then
832         usage
833 fi
834
835 pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
836 pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
837
838 if [ "x" = "x$INITRDFS" ] ; then
839         if [ "x" = "x$FS" ] ; then
840                 # default value
841 #               if [ "$pack_version" -ge "002005" ] ; then
842 #                   INITRDFS="initramfs"
843 #               else
844                     INITRDFS="rom"
845 #               fi
846         else
847                 echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
848                 INITRDFS="$FS"
849         fi
850 fi
851
852 if [ "$pack_version" -lt "002006" ] ; then
853         USE_UDEV=
854 fi
855 [ -z "$USE_UDEV" ] && UDEV_TMPFS=
856     
857 if [ "$pack_version" -ge "002005" ] ; then
858         modext=".ko"
859         insmod="insmod"
860 fi
861
862 if is_yes "$USEINSMODSTATIC" ; then
863         insmod="insmod.static"
864         INSMOD="/sbin/insmod.static"
865         if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
866                 INSMOD="/sbin/insmod.static.modutils"
867         fi
868         if [ ! -f "$INSMOD" ] ; then
869                 echo "insmod.static requested but /sbin/insmod.static not found !" >&2
870                 exit 1
871         fi
872 fi
873
874 case "$INITRDFS" in
875         ext2)
876                 if [ ! -x /sbin/mke2fs ]; then
877                         echo "/sbin/mke2fs is missing" 1>&2
878                         exit 1
879                 fi
880                 ;;
881         rom)
882                 if [ ! -x /sbin/genromfs ]; then
883                         echo "/sbin/genromfs is missing" 1>&2
884                         exit 1
885                 fi
886                 ;;
887         cram)
888                 if [ ! -x /sbin/mkcramfs ]; then
889                         echo "/sbin/mkcramfs is missing" 1>&2
890                         exit 1
891                 fi
892                 ;;
893         initramfs)
894                 if [ ! -x /bin/cpio ]; then
895                         echo "/bin/cpio is missing" 1>&2
896                         exit 1
897                 fi
898                 if [ ! -x /usr/bin/find ]; then
899                         echo "/usr/bin/find is missing" 1>&2
900                         exit 1
901                 fi
902                 ;;
903         *)
904                 echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
905                 exit 1
906                 ;;
907 esac
908
909 if [ -n "$img_vers" ]; then
910         target="$target-$kernel"
911 fi
912
913 if [ -z "$force" -a -f "$target" ]; then
914         echo "$target already exists." 1>&2
915         exit 1
916 fi
917
918 if [ ! -d "/lib/modules/$kernel" ]; then
919         echo "/lib/modules/$kernel is not a directory." 1>&2
920         exit 1
921 fi
922
923 if [ ! -f /proc/mounts ]; then
924         echo "WARNING: /proc filesystem not mounted, may cause wrong results or failure." 1>&2
925 fi
926
927 if [ "$pack_version" -lt "002005" ]; then
928         modulefile=/etc/modules.conf
929         if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
930                 modulefile=/etc/conf.modules
931         fi
932 else
933         modulefile=/etc/modprobe.conf
934 fi
935  
936 for n in $PREMODS; do
937         findmodule "$n"
938 done
939
940 # allow forcing loading SCSI and/or IDE modules
941 if is_yes "$ADDSCSI" ; then
942         find_modules_scsi
943 fi
944
945 if is_yes "$ADDIDE" ; then
946         find_modules_ide
947 fi
948
949 find_root
950
951 org_rootdev="$rootdev1"
952
953 find_modules_for "$rootdev1"
954
955 findmodule "-$rootFs"
956
957 for n in $BASICMODULES; do
958         findmodule "$n"
959 done
960
961 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
962         if [ -n "$verbose" ]; then
963                 echo "No modules are needed -- not building initrd image."
964         fi
965         exit 0
966 fi
967
968 if [ -n "$verbose" ]; then
969         echo "Using modules: $MODULES"
970 fi
971
972 MNTIMAGE="`mktemp -d /tmp/initrd.XXXXXX`"
973 IMAGE="`mktemp -u /tmp/initrd.img-XXXXXX`"
974 MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
975 RCFILE="$MNTIMAGE/linuxrc"
976
977 if [ -f "$MNTIMAGE" ]; then
978         echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
979         exit 1
980 fi
981
982 if [ -f "$IMAGE" ]; then
983         echo "$IMAGE already exists. Remove it and try again" 1>&2
984         exit 1
985 fi
986
987 if [ "$INITRDFS" = "ext2" ] ; then
988         dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
989
990         # We have to "echo y |" so that it doesn't complain about $IMAGE not
991         # being a block device
992         echo y | mke2fs -F "$IMAGE" "$IMAGESIZE" >/dev/null 2>/dev/null
993
994         mkdir -p "$MNTPOINT"
995         mount -o loop -t ext2 "$IMAGE" "$MNTPOINT"
996 else
997         mkdir -p "$MNTPOINT"
998 fi
999
1000
1001 mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
1002
1003
1004 # We don't need this directory, so let's save space
1005 rm -rf "$MNTPOINT"/lost+found
1006
1007 modules_install "$MODULES"
1008
1009 # mknod'ing the devices instead of copying them works both with and
1010 # without devfs...
1011 mknod "$MNTIMAGE/dev/console" c 5 1
1012 mknod "$MNTIMAGE/dev/null" c 1 3
1013 mknod "$MNTIMAGE/dev/zero" c 1 5
1014
1015 s="$RCFILE"
1016 ln -s /linuxrc $MNTIMAGE/init
1017
1018 inst /bin/initrd-busybox "$MNTIMAGE/bin/sh"
1019 ln -s sh "$MNTIMAGE/bin/busybox"
1020
1021 if is_yes "$USEINSMODSTATIC" ; then
1022         inst "$INSMOD" $MNTIMAGE/bin/insmod.static
1023 fi
1024
1025 cat > "$s" <<EOF
1026 #! /bin/sh
1027
1028 set -x
1029 EOF
1030 chmod 755 "$s"
1031
1032 modules_add_linuxrc "$MODULES" "$s"
1033
1034 # TODO: rewrite for busybox
1035 #if [ -n "$loopDev" ]; then
1036 #       if [ ! -d /initrd ]; then
1037 #               mkdir /initrd
1038 #       fi
1039 #
1040 #       cp -a "$loopDev" "$MNTIMAGE/dev"
1041 #       cp -a "$rootdev1" "$MNTIMAGE/dev"
1042 #       echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
1043 #       echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
1044 #       echo "echo Setting up loopback device $rootdev1" >> $RCFILE
1045 #       echo "losetup $rootdev1 /loopfs$loopFile" >> "$RCFILE"
1046 #fi
1047
1048 initrd_gen_suspend() {
1049         MODULES=""
1050         for mod in $SUSPENDMODS; do
1051             is_yes "$BOOT_SPLASH" && [ "$mod" = "-suspend-text" ] && mod="-suspend_bootsplash"
1052             findmodule "$mod"
1053         done
1054         modules_install "$MODULES"
1055         mkdir -p $MNTIMAGE/sys
1056         mkdir -p $MNTIMAGE/proc
1057 cat << EOF >> "$s"
1058 mount -t proc none /proc
1059 if [ "\$(awk ' /resume2=/  { print "yes"; } ' /proc/cmdline)" = "yes" ]; then
1060 EOF
1061         modules_add_linuxrc "$MODULES" "$s"
1062 cat << EOF >> "$s"
1063                 echo > /proc/software_suspend/activate
1064 fi
1065 umount /proc
1066 EOF
1067 }
1068
1069 initrd_gen_udev() {
1070         [ -n "$verbose" ] && echo "Setting up udev..."
1071         mkdir -p $MNTIMAGE/sbin
1072         mkdir -p $MNTIMAGE/proc
1073         mkdir -p $MNTIMAGE/etc/udev
1074         
1075         inst /sbin/initrd-udev $MNTIMAGE/sbin/udev
1076         ln -s udev $MNTIMAGE/sbin/udevstart
1077         inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
1078
1079         ln -s udev $MNTIMAGE/sbin/hotplug
1080
1081         if is_yes "$USE_UDEV"; then
1082                 if is_yes "$UDEV_TMPFS"; then
1083                     cat >> "$s" << EOF
1084 echo Creating /dev
1085 mount -o mode=0755 -t tmpfs none /dev
1086 mknod /dev/console c 5 1
1087 mknod /dev/null c 1 3
1088 mknod /dev/zero c 1 5
1089 mkdir /dev/pts
1090 mkdir /dev/shm
1091 EOF
1092                 fi
1093                 cat >> "$s" << EOF
1094 mount -t proc none /proc
1095 echo Starting udev
1096 /sbin/udevstart
1097 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
1098 umount /proc
1099 EOF
1100         fi
1101 }
1102
1103 initrd_gen_softraid() {
1104         [ -n "$verbose" ] && echo "Setting up mdadm..."
1105         
1106         if [ ! -x /sbin/initrd-mdadm -a ! -x /sbin/initrd-mdassemble ] ; then
1107                 echo "/sbin/initrd-mdadm and /sbin/initrd-mdassemble are missing !"
1108                 exit 1
1109         fi
1110
1111         if [ -x /sbin/initrd-mdassemble ] ; then
1112             do_mdassemble=1
1113             inst /sbin/initrd-mdassemble "$MNTIMAGE/bin/mdassemble"
1114         else
1115             do_mdassemble=0
1116             inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
1117         fi
1118             
1119         # LVM on RAID case
1120         do_md0=1
1121         for nr in `seq 1 $rootdev_nr`; do
1122             eval cr_rootdev="\$rootdev${nr}"
1123             eval cr_dev_list="\$dev_list${nr}"
1124             [ -n "$verbose" ] && echo "Setting up array ($cr_rootdev = $cr_dev_list)"
1125
1126             [ "$cr_rootdev" = "/dev/md0" ] && do_md0=0
1127             
1128             if [ "$do_mdassemble" -eq 1 ] ; then
1129                 echo "DEVICE $cr_dev_list" >> "$MNTIMAGE/etc/mdadm.conf"
1130                 cr_dev_list_md="$(echo "$cr_dev_list" | xargs | awk ' { gsub(/ +/,",",$0); print $0; }')"
1131                 echo "ARRAY $cr_rootdev devices=$cr_dev_list_md" >> "$MNTIMAGE/etc/mdadm.conf"
1132             else
1133                 echo "mdadm --assemble $cr_rootdev $cr_dev_list" >> "$s"
1134             fi
1135
1136             for f in $cr_dev_list $cr_rootdev ; do
1137                 # mkdir in case of devfs name
1138                 mkdir -p $MNTIMAGE/`my_dirname $f`
1139                 [ -n "$verbose" ] && echo "copying $f"
1140                 # this works fine with and without devfs
1141                 cp -HR $f $MNTIMAGE/$f
1142             done
1143         done
1144
1145         if [ "$do_mdassemble" -eq 1 ] ; then
1146             echo "mdassemble" >> "$s"
1147         fi
1148
1149         # needed to determine md-version
1150         if [ "$do_md0" -eq 1 ] ; then
1151                 mknod $MNTIMAGE/dev/md0 b 9 0
1152         fi
1153 }
1154
1155 initrd_gen_nfs() {
1156         # use root=/dev/ram0 init=/linuxrc when starting kernel or you will
1157         # have problems like init(XX) being child process of swapper(1).
1158         [ -n "$verbose" ] && echo "Adding rootfs on NFS support to initrd (dhcp)"
1159         mknod "$MNTIMAGE/dev/urandom" c 1 8
1160         mkdir "$MNTIMAGE/newroot"
1161         echo "ifconfig lo 127.0.0.1 up" >> "$s"
1162         echo "route add -net 127.0.0.0 netmask 255.0.0.0 lo" >> "$s"
1163         echo "ifconfig eth0 0.0.0.0 up" >> "$s"
1164         echo "udhcpc -i eth0 -f -q -s /bin/setdhcp"  >> "$s"
1165         cat << EOF > "$MNTIMAGE/bin/setdhcp"
1166 #!/bin/sh
1167 [ "\$1" != "bound" ] && exit
1168 [ -n "\$broadcast" ] && BROADCAST="broadcast \$broadcast"
1169 [ -n "\$subnet" ] && NETMASK="netmask \$subnet"
1170 set -x
1171 ifconfig \$interface \$ip \$BROADCAST \$NETMASK up
1172 set +x
1173 if [ -n "\$router" ]; then
1174     for r in \$router; do
1175         set -x
1176         route add default gw \$r dev \$interface
1177         set +x
1178     done
1179 fi
1180 if [ -n "\$rootpath" ]; then
1181     set -x
1182     mount -n -t nfs -o ro,nolock,posix,tcp,wsize=8192,rsize=8192 \$rootpath /newroot
1183     set +x
1184 else
1185     set +x
1186     echo "Missing rootpath in what DHCP server sent to us. Failing..."
1187     echo "All seen variables are listed below:"
1188     set
1189     set -x
1190 fi
1191 EOF
1192         chmod 755 "$MNTIMAGE/bin/setdhcp"
1193         echo "cd /newroot" >> "$s"
1194         echo "pivot_root . initrd" >> "$s"
1195         echo "[ -x /sbin/chroot ] && exec /sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1196         echo "exec /usr/sbin/chroot . /sbin/init -i < dev/console > dev/console 2>&1" >> "$s"
1197 }
1198
1199 initrd_gen_lvm() {
1200         [ -n "$verbose" ] && echo "Adding LVM support to initrd"
1201         inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
1202         mkdir -p $MNTIMAGE/etc
1203         mkdir -p $MNTIMAGE/tmp
1204         mkdir -p $MNTIMAGE/proc
1205         mkdir -p $MNTIMAGE/newroot
1206         if ! is_yes "$USE_UDEV"; then
1207                 mkdir -p $MNTIMAGE/dev/mapper
1208                 mknod $MNTIMAGE/dev/mapper/control c 10 63
1209                 for device in $PVDEVICES; do
1210                         cp -HR $device $MNTIMAGE
1211                 done
1212         fi
1213         echo "mount -t proc none /proc" >> "$s"
1214         echo "mount -t tmpfs none /tmp" >> "$s"
1215         if [ "$LVMTOOLSVERSION" = "1" ] ; then
1216                 echo "lvm vgscan -T" >> "$s"
1217                 echo "lvm vgchange -T -a y $VGVOLUME" >> "$s"
1218                 echo "umount /tmp" >> "$s"
1219                 # fail to umount
1220                 echo "umount /dev" >> "$s"
1221                 echo "umount /proc" >> "$s"
1222         else
1223                 echo "cat /etc/lvm.conf > /tmp/lvm.conf" >> "$s"
1224                 echo "global {" > "$MNTIMAGE/etc/lvm.conf"
1225                 echo "  locking_type = 0" >> "$MNTIMAGE/etc/lvm.conf"
1226                 echo "  locking_dir = \"/tmp\"" >> "$MNTIMAGE/etc/lvm.conf"
1227                 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1228                 echo "devices {" >> "$MNTIMAGE/etc/lvm.conf"
1229                 echo "  sysfs_scan=0" >> "$MNTIMAGE/etc/lvm.conf"
1230                 if is_yes "$raidfound"; then
1231                         echo "  md_component_detection = 1" >> "$MNTIMAGE/etc/lvm.conf"
1232                 fi
1233                 lvm dumpconfig | awk '/filter=/' >> "$MNTIMAGE/etc/lvm.conf"
1234                 echo "}" >> "$MNTIMAGE/etc/lvm.conf"
1235                 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure" >> "$s"
1236                 echo "LVM_SYSTEM_DIR=/tmp lvm vgchange --ignorelockingfailure -a y $VGVOLUME" >> "$s"
1237                 echo "LVM_SYSTEM_DIR=/tmp lvm vgscan --ignorelockingfailure --mknodes" >> "$s"
1238                 # Find out major/minor
1239                 echo "majmin=\"\`LVM_SYSTEM_DIR=/tmp lvm lvdisplay --ignorelockingfailure -c $org_rootdev\`\"" >> "$s"
1240                 echo "majmin=\"\${majmin#*/}\"" >> "$s"
1241                 echo "majmin=\"\${majmin#*:*:*:*:*:*:*:*:*:*:*:*}\"" >> "$s"
1242                 echo "major=\"\${majmin%:*}\"" >> "$s"
1243                 echo "minor=\"\${majmin#*:}\"" >> "$s"
1244                 # Pass it to kernel
1245                 echo "val=\$((256 * \$major + \$minor))" >> "$s"
1246                 echo "echo \$val > /proc/sys/kernel/real-root-dev" >> "$s"
1247                 echo "umount /tmp" >> "$s"
1248                 echo "umount /proc" >> "$s"
1249         fi
1250 }
1251
1252 initrd_gen_procdata() {
1253         [ -n "$verbose" ] && echo "Adding rootfs finding based on root= option support."
1254         mkdir -p $MNTIMAGE/proc
1255 cat << EOF >> "$s"
1256 set +x
1257 mount -t proc none /proc
1258 root="\$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,\$0); gsub(/ .*/,NIL,\$0); print \$0; } ' /proc/cmdline)"
1259 if [ -n "\$root" ]; then
1260     rootnr="\$(busybox awk -v root="\$root" ' { if (\$4 == root) { print 256*\$1+\$2; } } ' /proc/partitions)"
1261     if [ -n "\$rootnr" ]; then
1262         echo "\$rootnr" > /proc/sys/kernel/real-root-dev
1263     fi
1264 fi
1265 umount /proc
1266 set -x
1267 EOF
1268 }
1269
1270 # main generation
1271
1272 if is_yes "$USE_UDEV"; then
1273         initrd_gen_udev
1274 fi
1275
1276 if is_yes "$USESUSPEND"; then
1277         initrd_gen_suspend
1278 fi
1279
1280 if is_yes "$usenfs" ; then
1281         initrd_gen_nfs
1282 elif is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
1283         initrd_gen_softraid
1284         if is_yes "$uselvm" ; then
1285                 initrd_gen_lvm
1286         fi
1287 elif is_yes "$uselvm" ; then
1288         initrd_gen_lvm
1289 else
1290         initrd_gen_procdata
1291 fi
1292
1293 chmod +x "$RCFILE"
1294
1295 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
1296
1297 case "$INITRDFS" in
1298         ext2)
1299                 umount "$IMAGE"
1300                 ;;
1301         rom)
1302                 genromfs -f "$IMAGE" -d "$MNTPOINT" -V "PLD initrd for kernel $kernel"
1303                 ;;
1304         cram)
1305                 mkcramfs "$MNTPOINT" "$IMAGE"
1306                 ;;
1307         initramfs)
1308                 (cd $MNTPOINT ; find . | cpio -H newc -o > "$IMAGE")
1309                 ;;
1310         *)
1311                 echo "Filesystem $INITRDFS not supported by $0";
1312 esac
1313
1314 if is_yes "$COMPRESS" ; then
1315         gzip -9 < "$IMAGE" > "$target"
1316 else
1317         cp -a "$IMAGE" "$target"
1318 fi
1319
1320 if is_yes "$BOOT_SPLASH"; then
1321         if [ ! -x /bin/splash.bin ]; then
1322                 echo "Failed to execute /bin/splash.bin. Is bootsplash package installed?" 1>&2
1323         elif [ -z "$THEME" ]; then
1324                 echo "Please configure your /etc/sysconfig/bootsplash first." 1>&2
1325                 echo "Generating bootsplashes skipped." 1>&2
1326         else
1327             if [ -n "$BOOT_SPLASH_RESOLUTIONS" ]; then
1328                 for res in $BOOT_SPLASH_RESOLUTIONS; do
1329                         if [ -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" ]; then
1330                                 /bin/splash.bin -s -f "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg" >> "$target" && \
1331                                 [ -n "$verbose" ] && echo "Added $res $THEME theme to initrd."
1332                         else
1333                                 echo "/etc/bootsplash/themes/$THEME/config/bootsplash-$res.cfg doesn't exist, skipped" 1>&2
1334                         fi
1335                 done
1336              else
1337                  echo "No BOOT_SPLASH_RESOLUTIONS specified in /etc/sysconfig/bootsplash." 1>&2
1338                  echo "Not adding bootsplash to initrd." 1>&2
1339              fi
1340         fi
1341 fi
1342
1343 rm -rf "$MNTIMAGE" "$MNTPOINT" "$IMAGE"
This page took 0.113433 seconds and 2 git commands to generate.