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