]> git.pld-linux.org Git - projects/geninitrd.git/blobdiff - geninitrd
- when comparing pci IDs make sure they will be compared as strings
[projects/geninitrd.git] / geninitrd
index 0418eec35b4835b04c8f068026a0b1ec87924c90..fb1611c8cd19b6c491fa4363426db780105a5bc4 100755 (executable)
--- a/geninitrd
+++ b/geninitrd
 #      by Jacek Konieczny <jajcus@pld.org.pl>
 #
 # based on mkinitrd from RedHat
-#
+
+RCSID='$Id: geninitrd,v 2.36 2003/08/09 23:42:04 baggins Exp $'
 PATH=/sbin:$PATH
 export PATH
 
-VERSION=%VERSIONTAG%
+VERSION="`echo "$RCSID"|awk '{print $3}'`"
 
 . /etc/rc.d/init.d/functions
 
 COMPRESS="yes"
-FS="rom"
-PROBESCSI="yes"
-PROBEIDE="yes"
-PROBERAID="yes"
-USEBSP="yes"
-
-if [ -f /etc/sysconfig/geninitrd ] ; then
-       . /etc/sysconfig/geninitrd
-fi
-
-if is_yes $USEBSP ; then
-       [ ! -x /sbin/bsp ] && USEBSP="no"
-fi
+# INITRDFS is set later (catch obsoleted FS option)
+#INITRDFS="rom"
+USERAIDSTART="yes"
+USEMDADMSTATIC="no"
+USEINSMODSTATIC="no"
+uselvm="no"
+# it should be safe to remove scsi_mod from here, but I'm not sure...
+PRESCSIMODS="-scsi_mod unknown -sd_mod"
+PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
+PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
 target=""
 kernel=""
 force=""
 verbose=""
 MODULES=""
 img_vers=""
-modulefile=/etc/modules.conf
-if [ "`uname -m`" = "ia64" ]; then
-       IMAGESIZE=3000
-else
-       IMAGESIZE=1500
-fi
-PRESCSIMODS="scsi_mod unknown sd_mod"
-PREIDEMODS="ide-mod ide-probe ide-probe-mod ide-disk"
+modulefile="/etc/modules.conf"
+raidtab="/etc/raidtab"
 fstab="/etc/fstab"
+insmod="insmod"
+modext=".o"
 
 usage () {
        echo "usage: `basename $0` [--version] [-v] [-f] [--ifneeded] [--preload <module>]" 1>&2
-       echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-ide-modules]" 1>&2
-       echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" 1>&2 
-       echo "       [--fs=rom|ext2|cram] [--no-bsp]" 1>&2
+       echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" 1>&2
+       echo "       [--initrdfs=rom|ext2|cram] [--modules-conf=<modules.conf>]" 1>&2
+       echo "       [--with-raidstart] [--without-raidstart] [--with-insmod-static]" 1>&2
+       echo "       [--with-mdadm-static]" 1>&2
        echo "       <initrd-image> <kernel-version>" 1>&2
        echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" 1>&2
        exit 1
 }
 
 
-my_find() {
-       for name in `ls`
-       do
-               if [ -d $name ]; then
-                       if [ "$name" != "build" ]; then
-                               (cd $name;my_find $1/$name $2)
-                       fi
+my_dirname() {
+       echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
+}
+
+find_depmod () {
+       typeset mods module f level depfile first
+
+       depfile=/lib/modules/$kernel/modules.dep
+       
+       if [ -f $depfile ] ; then
+               : ok
+       else
+               echo "Error: no $depfile ! Run depmod and rerun geninitrd." 1>&2
+               exit 1
+       fi
+       
+       # prepend / if no path given, append $modext.gz if not given,
+       # quote /
+       origmodule="$2"
+       module=$(echo "$2" | \
+                awk '/\// {print;next} {print "/" $0}' | \
+                awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
+                awk '{gsub("/","\\/");print}')
+       mods=$(awk '
+BEGIN { here = 0 }
+/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
+/:/ { here = 0 }
+/(.*)/ { gsub(/\\/," "); if (here) print }
+' $depfile | xargs)
+
+       # fallback to $modext
+       if [ "$mods" = "" ] ; then
+           module=$(echo "$module" | \
+                   awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
+       fi 
+       mods=$(awk '
+BEGIN { here = 0 }
+/'"$module"':(.*)/ { gsub(/:/," "); gsub(/\\/," "); print; here = 1; next }
+/:/ { here = 0 }
+/(.*)/ { gsub(/\\/," "); if (here) print }
+' $depfile | xargs)
+
+       if [ "$mods" = "" ] ; then
+               if [ "$1" != silent ] ; then
+                       echo "$origmodule: module not found in $depfile" 1>&2
+               fi
+               if ! is_no "$EXIT_IF_MISSING" ; then 
+                       exit 1
                else
-                       if [ -f $name -a "$name" = "$2" ]; then
-                               echo $1/$name
-                       fi
+                       echo "If $origmodule isn't compiled in kernel then this initrd may not start your system". 1>&2
+               fi
+       fi
+       
+       level=$3
+       if [ "$level" = "" ] ; then
+               level=0
+       fi
+       level=$(awk "BEGIN{print $level + 1}")
+       if [ $level -gt 20 ] ; then
+               echo "$origmodule: cycle in $depfile" 1>&2
+               exit 1
+       fi
+       
+       first=
+       for f in $mods ; do
+               if [ "$first" = "" ] ; then
+                       first=$f
+               else
+                       find_depmod $1 $f $level
                fi
        done
+       
+       echo $first
 }
 
-my_dirname() {
-       echo $1|awk -F/ '{print substr($0, 0, length($0) - length($NF));}'
+addmodule() {
+       fmPath=$1
+       skiperrors=$2
+
+       if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
+               if [ -n "$skiperrors" ]; then
+                       return
+               fi
+
+               echo "module $fmPath present in modules.dep, but not in filesystem (kernel = $kernel)" 1>&2
+               exit 1
+       fi
+
+       # only need to add each module once
+       # quote /
+       tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
+       if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
+               MODULES="$MODULES $fmPath"
+       fi
 }
 
 findmodule() {
        skiperrors=""
        modName=$1
+
        if [ "$(echo $modName | awk '{print(substr($0,1,1));}')" = "-" ]; then
                skiperrors=1
                modName="$(echo $modName | awk '{print(substr($0,2));}')"
        fi
 
+       # what's that?
        if [ "$modName" = "pluto" ]; then
                findmodule fc4
                findmodule soc
@@ -90,43 +164,27 @@ findmodule() {
                findmodule socal
        fi
 
-       fmPath="`(cd /lib/modules/$kernel; my_find . "$modName.o")`"
-
-       if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
-               if [ -n "$skiperrors" ]; then
-                       return
+       if [ -n "$skiperrors" ]; then
+               allModulesToFind=`find_depmod silent $modName`
+       else
+               allModulesToFind=`find_depmod normal $modName`
+               if [ $? != 0 ] ; then
+                       exit 1
                fi
-
-               # ignore the absence of the scsi modules
-               for n in $PRESCSIMODS; do
-                       if [ "$n" = "$modName" ]; then
-                               return;
-                       fi
-               done;
-
-               # ignore the absence of the ide modules
-               for n in $PREIDEMODS; do
-                       if [ "$n" = "$modName" ]; then
-                               return;
-                       fi
-               done;
-    
-               echo "No module $modName found for kernel $kernel" 1>&2
-               exit 1
-       fi
-
-       # only need to add each module once
-       tmpFmPath="`echo "$fmPath"|awk -F/ '{for(i=1;i<NF;i++) { printf("%s\\\\/",$i); } { print $NF; }}'`"
-       if is_yes "`echo "$MODULES" | awk '/"'$tmpFmPath'"/ { print "yes"; }' `" ; then : ; else
-               MODULES="$MODULES $fmPath"
        fi
+       
+       for mod in $allModulesToFind ; do
+               mod=$(echo $mod | \
+                     awk '{sub(/^\/lib\/modules\/[^\/]*\//,"");print}')
+               addmodule $mod "$skiperrors"
+       done
 }
 
 inst() {
        if [ "$#" != "2" ];then
                echo "usage: inst <file> <destination>"
                return
-       fi 
+       fi
        [ -n "$verbose" ] && echo "$1 -> $2"
        cp "$1" "$2"
 }
@@ -136,128 +194,409 @@ get_label_ext2 () {
 }
 
 get_uuid_ext2 () {
-       /sbin/tune2fs -l $1 2> /dev/null | awk  -F: '/UUID:/ {gsub(" ",""); print $2}'
+       /sbin/tune2fs -l $1 2> /dev/null | awk -F: '/UUID:/ {gsub(" ",""); print $2}'
 }
 
 get_label_xfs () {
-    /sbin/xfs_admin -l $1 2> /dev/null
+       /usr/sbin/xfs_db -x -p xfs_admin -c label -r "$1"|awk -F= '{sub("^\"","", $2); sub("\"$", "", $2); print $2}'
+
 }
 
 get_uuid_xfs () {
-    /sbin/xfs_admin -u $1 2> /dev/null
+       /usr/sbin/xfs_db -x -p xfs_admin -c uuid -r "$1"|awk -F= '{print $2}'
 }
 
-find_root() { 
+find_root() {
        eval `awk '/^[\t ]*#/ {next} {if ( $2 == "/" ) {print "rootdev=\"" $1 "\"\nrootFs=\"" $3 "\""}}' $fstab`
        case $rootdev in
        LABEL=*)
-               case $rootFs in
-               ext2) 
-                       if [ ! -x /sbin/e2label ] ; then
-                               echo "/sbin/e2label is missing" 1>&2
-                               exit 1
+               if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
+                       rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
+                       if [ -n "$rootdev2" ] ; then
+                               rootdev=$rootdev2
+                               rootdev_found=1
                        fi
-                       get_label="get_label_ext2"
-                       ;;
-#              xfs)
-#                      if [ ! -x /sbin/xfs_admin ] ; then
-#                              echo "/sbin/xfs_admin is missing" 1>&2
-#                              exit 1
-#                      fi
-#                      get_label="get_label_xfs"
-#                      ;;
-               *)
-                       echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
-                       exit 1
-                       ;;
-               esac
-               if [ ! -r /proc/partitions ] ; then
-                       echo '/proc/partitions is not readable'; 1>&2
-                       exit 1
                fi
-               label=${rootdev#"LABEL="}
-               for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
-                       if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
-                               if [ -n "$verbose" ] ; then
-                                       echo "Using $dev as device for rootfs"
+               if [ "$rootdev_found." != "1." ] ; then
+                       case $rootFs in
+                       ext2|ext3)
+                               if [ ! -x /sbin/e2label ] ; then
+                                       echo "/sbin/e2label is missing" 1>&2
+                                       exit 1
                                fi
-                           rootdev=$dev
-                           rootdev_found=1
-                           break
-                       fi
-               done
-               if [ "$rootdev_found" != 1 ] ; then
-                   echo "geninitrd can't find real device for LABEL=$label" 1>&2
-                   exit 1
+                               get_label="get_label_ext2"
+                               ;;
+                       xfs)
+                               if [ ! -x /usr/sbin/xfs_db ] ; then
+                                       echo "/usr/sbin/xfs_db is missing" 1>&2
+                                       exit 1
+                               fi
+                               get_label="get_label_xfs"
+                               ;;
+                       *)
+                               echo "LABEL on $rootFs in not supported by geninitrd" 1>&2
+                               exit 1
+                               ;;
+                       esac
+                       if [ ! -r /proc/partitions ] ; then
+                               echo '/proc/partitions is not readable'; 1>&2
+                               exit 1
+                       fi
+                       label=${rootdev#"LABEL="}
+                       for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
+                               if [ -r $dev ] && [ "$label" = "`$get_label $dev`" ] ; then
+                                       if [ -n "$verbose" ] ; then
+                                               echo "Using $dev as device for rootfs"
+                                       fi
+                                       rootdev=$dev
+                                       rootdev_found=1
+                                       break
+                               fi
+                       done
+                       if [ "$rootdev_found." != "1." ] ; then
+                               echo "geninitrd can't find real device for LABEL=$label" 1>&2
+                               exit 1
+                       fi
                fi
                ;;
        UUID=*)
-               case $rootFs in
-               ext2) 
-                       if [ ! -x /sbin/tune2fs ] ; then
-                               echo "/sbin/tune2fs is missing" 1>&2
+               if [ -x /sbin/findfs -a \( "$rootFs." = "ext2." -o "$rootFs." = "ext3." \) ] ; then
+                       rootdev2="`/sbin/findfs $rootdev 2>/dev/null`"
+                       if [ -n "$rootdev2" ] ; then
+                               rootdev=$rootdev2
+                               rootdev_found=1
+                       fi
+               fi
+               if [ "$rootdev_found." != "1." ] ; then
+                       case $rootFs in
+                       ext2|ext3)
+                               if [ ! -x /sbin/tune2fs ] ; then
+                                       echo "/sbin/tune2fs is missing" 1>&2
+                                       exit 1
+                               fi
+                               get_uuid="get_uuid_ext2"
+                               ;;
+                       xfs)
+                               if [ ! -x /usr/sbin/xfs_db ] ; then
+                                       echo "/usr/sbin/xfs_db is missing" 1>&2
+                                       exit 1
+                               fi
+                               get_label="get_uuid_xfs"
+                               ;;
+                       *)
+                               echo "UUID on $rootFs in not supported by geninitrd" 1>&2
+                               exit 1
+                               ;;
+                       esac
+                       if [ ! -r /proc/partitions ] ; then
+                               echo '/proc/partitions is not readable'; 1>&2
                                exit 1
                        fi
-                       get_uuid="get_uuid_ext2"
+                       uuid=${rootdev#"UUID="}
+                       for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
+                               if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
+                                       if [ -n "$verbose" ] ; then
+                                               echo "Using $dev as device for rootfs"
+                                       fi
+                                       rootdev=$dev
+                                       rootdev_found=1
+                                       break
+                               fi
+                       done
+                       if [ "$rootdev_found" != 1 ] ; then
+                               echo "geninitrd can't find real device for UUID=$uuid" 1>&2
+                               exit 1
+                       fi
+               fi
+               ;;
+       esac
+
+}
+
+find_modules_softraid() {
+       eval `awk -v rootdev="$1" 'BEGIN {
+       found="no";
+       dev_list="";
+}
+
+{
+       gsub("\t"," ");
+       gsub("  +", " ");
+       gsub("^ ","");
+       if (/^[\t ]*#/)
+               next;
+       if (/^raiddev/) {
+               if ($2 == rootdev) {
+                       found="yes";
+               } else {
+                       if (found == "yes") {
+                               exit 0;
+                       };
+               };
+       };
+       if (found == "yes") {
+               if ($1 == "device") {
+                       dev_list = dev_list " " $2;
+               };
+               if ($1 == "raid-level") {
+                       raidlevel=$2;
+               }
+       };
+}
+
+END {
+       print "raidfound=" found "\nraidlevel=" raidlevel "\ndev_list=\"" dev_list "\"\n";
+}' $raidtab `
+       if is_yes "$raidfound" ; then
+               case "$raidlevel" in
+               [0145])
+                       findmodule "raid$raidlevel"
+                       ;;
+               linear)
+                       findmodule "linear"
                        ;;
-#              xfs)
-#                      if [ ! -x /sbin/xfs_admin ] ; then
-#                              echo "/sbin/xfs_admin is missing" 1>&2
-#                              exit 1
-#                      fi
-#                      get_label="get_uuid_xfs"
-#                      ;;
                *)
-                       echo "UUID on $rootFs in not supported by geninitrd" 1>&2
-                       exit 1
+                       echo "raid level $number (in $raidtab) not recognized" 1>&2
                        ;;
                esac
-               if [ ! -r /proc/partitions ] ; then
-                       echo '/proc/partitions is not readable'; 1>&2
+       fi
+       for device in $dev_list; do
+               find_modules_for $device
+       done
+}
+
+find_modules_scsi() {
+       for n in $PRESCSIMODS; do
+               if [ "X$n" = "Xunknown" ] ; then
+                       if [ "$pack_version" -ge "002005" ]; then
+                               modulefile=/etc/modprobe.conf
+                       fi
+                       if [ ! -f "$modulefile" ]; then
+                               modulefile=/etc/conf.modules
+                       fi
+                       if [ -f "$modulefile" ]; then
+                               scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
+                               for n in $scsimodules; do
+                       # for now allow scsi modules to come from anywhere. There are some
+                       # RAID controllers with drivers in block
+                                       findmodule "$n"
+                               done
+                       fi
+               else
+                       findmodule "$n"
+               fi
+       done
+}
+
+find_modules_ide() {
+       if [ "$pack_version_long" -lt "002004021" ]; then
+           [ -n "$verbose" ] && echo "Finding IDE modules for kernels <= 2.4.20"
+           for n in $PREIDEMODSOLD; do
+               findmodule "$n"
+           done
+       else
+           tryauto=1
+           for n in $PREIDEMODS; do
+               if [ "X$n" = "Xunknown" ] ; then
+                   if [ "$pack_version" -ge "002005" ]; then
+                               modulefile=/etc/modprobe.conf
+                   fi
+                   if [ ! -f "$modulefile" ]; then
+                       modulefile=/etc/conf.modules
+                   fi
+                   if [ -f "$modulefile" ]; then
+                        [ -n "$verbose" ] && echo "Finding IDE modules using ide_hostadapter"
+                       idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
+                       for n in $idemodules; do
+                           tryauto=0;
+                           findmodule "$n"
+                       done
+                   fi
+
+                   if [ "$tryauto" -eq 1 ]; then
+                       [ -n "$verbose" ] && echo "Finding IDE modules using PCI ID database"
+                       idemodules=""
+                       for n in $(awk ' { print $2 } ' /proc/bus/pci/devices); do
+                           eval `awk -v pciid="$n" 'BEGIN {
+}
+               
+{
+       gsub("\t"," ");
+       gsub("  +", " ");
+       gsub("^ ","");
+       if (/^[\t ]*#/)
+               next;
+       compmod = $1 "";        # make sure comparison type will be string
+                               # cause pci IDs are hexadecimal numeric
+       if (compmod == pciid) {
+               module=$2;
+               min_kernel=$3;
+               max_kernel=$3;
+               exit 0;
+       }
+}
+
+END {
+       print "module=" module "\nmin_kernel=" min_kernel "\nmax_kernel=\"" max_kernel "\"\n";
+}' /usr/share/pci-database/ide.pci`
+                           if [ -n "$module" ]; then
+                               echo "$module"
+                               gomin=1
+                               gomax=1
+                               [ -n "$min_kernel" -a "$pack_version_long" -lt "$min_kernel" ] && gomin=0
+                               [ -n "$max_kernel" -a "$pack_version_long" -gt "$max_kernel" ] && gomax=0
+                               [ "$gomax" -ne 0 -a "$gomin" -ne 0 ] && idemodules="$idemodules $module"
+                           fi
+                       done
+                       idemodules=$(for n in $idemodules; do echo "$n"; done | xargs)
+                       for n in $idemodules; do
+                           findmodule "$n"
+                       done
+                   fi
+               fi
+               findmodule "$n"
+           done
+       fi
+}
+
+find_modules_for() {
+       if is_yes "`echo "$1" | awk '/^\/dev\/md/ { print "yes"; }'`"; then
+               find_modules_softraid "$1"
+       elif is_yes "$(echo "$1" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
+               find_modules_scsi
+       elif is_yes "`echo "$1" | awk '/^\/dev\/(hd|ide|ataraid)/ { print "yes"; }'`" ; then
+               find_modules_ide
+       elif is_yes "`echo "$1" | awk '/\/dev\/rd\// { print "yes"; }'`" ; then
+               findmodule "DAC960"
+       elif is_yes "`echo "$1" | awk '/\/dev\/ida\// { print "yes"; }'`" ; then
+               findmodule "cpqarray"
+       elif is_yes "`echo "$1" | awk '/\/dev\/cciss\// { print "yes"; }'`" ; then
+               findmodule "cciss"
+       elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
+               findmodule "ataraid"
+               ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
+               if -n "$ataraidmodules" ; then
+                       # FIXME: think about modules compiled in kernel
+                       echo "ERROR: ataraid_hostadapter alias not defined in $modulefile !"
+                       echo "Please set it and run $0 again."
                        exit 1
                fi
-               uuid=${rootdev#"UUID="}
-               for dev in `awk 'BEGIN {getline;getline} {print "/dev/" $4}' /proc/partitions` ; do
-                       if [ -r $dev ] && [ "$uuid" = "`$get_uuid $dev`" ] ; then
-                               if [ -n "$verbose" ] ; then
-                                       echo "Using $dev as device for rootfs"
-                               fi
-                           rootdev=$dev
-                           rootdev_found=1
-                           break
-                       fi
+               for n in $ataraidmodules; do
+                       findmodule "$n"
                done
-               if [ "$rootdev_found" != 1 ] ; then
-                   echo "geninitrd can't find real device for UUID=$uuid" 1>&2
-                   exit 1
+       # check to see if we need to set up a loopback filesystem
+       elif is_yes "`echo "$1" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
+               echo "Sorry, root on loop device isn't supported." 1>&2
+               exit 1
+               # TODO: rewrite for bsp and make nfs ready
+               if [ ! -x /sbin/losetup ]; then
+                       echo "losetup is missing"
+                       exit 1
+               fi
+               key="^# $(echo $1 | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
+               if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
+                       echo "The root filesystem is on a $1, but there is no magic entry in $fstab" 1>&2
+                       echo "for this device. Consult the geninitrd man page for more information" 1>&2
+                       exit 1
                fi
-               ;;
-       esac
 
+               line="`awk '/'$key'/ { print $0; }' $fstab`"
+               loopDev="$(echo $line | awk '{print $3}')"
+               loopFs="$(echo $line | awk '{print $4}')"
+               loopFile="$(echo $line | awk '{print $5}')"
+
+               BASICMODULES="$BASICMODULES -loop"
+               findmodule "-$loopFs"
+               BASICMODULES="$BASICMODULES -${loopFs}"
+               # don't have any clue, how is this supposed to work
+       elif ls -l "$1"|awk '{if (/^b/) { if ($5 == "58,") { exit 0; } else { exit 1; } } else { exit 1; }}'; then
+               if [ ! -f /sbin/initrd-lvm ] ; then
+                       echo "ERROR: root on LVM but /sbin/initrd-lvm not found."
+                       echo "Please install lvm-initrd package and rerun $0."
+                       exit 1
+               fi
+               if [ -n "$PVDEVICES" ] ; then
+                       for device in $PVDEVICES; do
+                               find_modules_for $device
+                       done
+               else
+                       echo "ERROR: Sorry, but searching for PV isn't implemented yet."
+                       echo "Use PVDEVICES in /etc/sysconfig/geninitrd to set it."
+                       exit 1
+               fi
+               findmodule "-lvm"
+               findmodule "-lvm-mod"
+               uselvm="yes"
+       fi
 }
 
+if [ -r /etc/sysconfig/geninitrd ] ; then
+       . /etc/sysconfig/geninitrd
+fi
+
+if [ "x" = "x$INITRDFS" ] ; then
+       if [ "x" = "x$FS" ] ; then
+               # default value
+               INITRDFS="rom"
+       else
+               echo "Warning: FS configuration options is obsoleted. Use INITRDFS instead" 1>&2
+               INITRDFS="$FS"
+       fi
+fi
+
+if [ ! -x /sbin/bsp ] ; then 
+       echo "/sbin/bsp is missing !"
+       exit 1
+fi
+if [ "`uname -m`" = "ia64" ]; then
+       IMAGESIZE=3000
+else
+       IMAGESIZE=1500
+fi
 while [ $# -gt 0 ]; do
        case $1 in
-       --no-bsp)
-               USEBSP="no"
+       --fstab=*)
+               fstab="`echo $1 | awk -F= '{print $2;}'`"
                ;;
-       --fstab*)
-               if is_yes "`echo $1 | awk '/=/ { print "yes"; }'`" ; then
-                       fstab="`echo $1 | awk -F= '{print $2;}'`"
-               else
-                       fstab="$2"
-                       shift
-               fi                  
+       --fstab)
+               fstab="$2"
+               shift
                ;;
-       --with*)
-               if is_yes "`echo $1 | awk '/=/ { print "yes"; }'`" ; then
-                       modname="`echo $1 | awk -F= '{print $2;}'`"
-               else
-                       modname="$2"
-                       shift
-               fi                  
-
-               BASICMODULES="$BASICMODULES $modname"
+       --modules-conf=*)
+               modulefile="`echo $1 | awk -F= '{print $2;}'`"
+               ;;
+       --modules-conf)
+               modulefile="$2"
+               shift
+               ;;
+       --raidtab=*)
+               raidtab="`echo $1 | awk -F= '{print $2;}'`"
+               ;;
+       --raidtab)
+               raidtab="$2"
+               shift
+               ;;
+       --use-raidstart|--with-raidstart)
+               USERAIDSTART="yes"
+               ;;
+       --without-raidstart)
+               USERAIDSTART="no"
+               ;;
+       --use-mdadm-static|--with-mdadm-static)
+               USEMDADMSTATIC="yes"
+               ;;
+       --use-insmod-static|--with-insmod-static)
+               USEINSMODSTATIC="yes"
+               ;;
+       --without-insmod-static)
+               USEINSMODSTATIC="no"
+               ;;
+       --with=*)
+               BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
+               ;;
+       --with)
+               BASICMODULES="$BASICMODULES $2"
+               shift
                ;;
        --version)
                echo "geninitrd: version $VERSION"
@@ -275,31 +614,28 @@ while [ $# -gt 0 ]; do
        -f)
                force=1
                ;;
-       --preload*)
-               if is_yes "`echo $1 | awk '/=/ { print "yes"; }'`" ; then
-                       modname="`echo $1 | awk -F= '{print $2;}'`"
-               else
-                       modname="$2"
-                       shift
-               fi                  
-               PREMODS="$PREMODS $modname"
-               ;;
-       --omit-scsi-modules)
-               PRESCSIMODS=""
-               PROBESCSI="no";
+       --preload=*)
+               PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
                ;;
-       --omit-raid-modules)
-               PROBERAID="no";
+       --preload)
+               PREMODS="$PREMODS $2"
+               shift
                ;;
-       --omit-ide-modules)
-               PROBEIDE="no";
+       --fs=*)
+               echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
+               INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
                ;;
        --fs)
-               FS="$2"
+               echo "Warning: --fs option is obsoleted. Use --initrdfs instead" 1>&2
+               INITRDFS="$2"
                shift
                ;;
-       --fs=*)
-               FS="`echo $1 | awk -F= '{print $2;}'`"
+       --initrdfs=*)
+               INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
+               ;;
+       --initrdfs)
+               INITRDFS="$2"
+               shift
                ;;
        --image-version)
                img_vers=yes
@@ -322,7 +658,27 @@ if [ -z "$target" -o -z "$kernel" ]; then
        usage
 fi
 
-case "$FS" in
+pack_version="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d",$1,$2)}'`"
+pack_version_long="`echo "$kernel"|awk -F. '{print sprintf("%03d%03d%03d",$1,$2,$3)}'`"
+
+if [ "$pack_version" -ge "002005" ] ; then
+       modext=".ko"
+       insmod="insmod_ng"
+fi
+
+if is_yes "$USEINSMODSTATIC" ; then
+       insmod="insmod.static"
+       INSMOD="/sbin/insmod.static"
+       if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ] ; then
+               INSMOD="/sbin/insmod.static.modutils"
+       fi
+       if [ ! -f "$INSMOD" ] ; then
+               echo "insmod.static requested but /sbin/insmod.static not found !" >&2
+               exit 1
+       fi
+fi
+
+case "$INITRDFS" in
        ext2)
                if [ ! -x /sbin/mke2fs ]; then
                        echo "/sbin/mke2fs is missing" 1>&2
@@ -340,9 +696,9 @@ case "$FS" in
                        echo "/sbin/mkcramfs is missing" 1>&2
                        exit 1
                fi
-                ;;
+               ;;
        *)
-               echo "Filesystem $FS on initrd is not supported" 1>&2
+               echo "Filesystem $INITRDFS on initrd is not supported" 1>&2
                exit 1
                ;;
 esac
@@ -365,84 +721,26 @@ for n in $PREMODS; do
        findmodule "$n"
 done
 
-find_root
-
-if is_yes "$PROBESCSI" && is_yes "$(echo "$rootdev" | awk '/^\/dev\/sd/ { print "yes"; }')" ; then
-
-    for n in $PRESCSIMODS; do
-       if [ "$n" = "unknown" ] ; then
-               if [ ! -f "$modulefile" ]; then
-                       modulefile=/etc/conf.modules
-               fi
-               if [ -f "$modulefile" ]; then
-                       scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile| LC_ALL=C sort -u`"
-                       for n in $scsimodules; do
-               # for now allow scsi modules to come from anywhere.  There are some
-               # RAID controllers with drivers in block/
-                               findmodule "$n"
-                       done
-               fi
-       else
-               findmodule "$n"
-       fi
-    done
-
+# allow forcing loading SCSI and/or IDE modules
+if is_yes "$ADDSCSI" ; then
+       find_modules_scsi
 fi
 
-if is_yes "$PROBEIDE" && is_yes "`echo "$rootdev" | awk '/^\/dev\/hd/ { print "yes"; }'`" ; then
-    for n in $PREIDEMODS; do
-           findmodule "$n"
-    done
+if is_yes "$ADDIDE" ; then
+       find_modules_ide
 fi
 
-if is_yes "$PROBERAID" ; then
-    # load appropriate raid devices if necessary
-    if is_yes "`awk '/^\/dev\/md/ && ! /noauto/ { print "yes"; }' "$fstab"`" ; then
-       for number in $(awk '/^[\t ]*raid-level/ { print $2; }' /etc/raidtab | LC_ALL=C sort -u) ; do
-           case "$number" in
-           [0145])
-               findmodule "raid$number"
-               ;;
-           *)
-               echo "raid level $number (in /etc/raidtab) not recognized" 1>&2
-               ;;
-           esac
-       done
-    fi
-fi
+find_root
 
-# check to see if we need to set up a loopback filesystem
-if is_yes "`echo "$rootdev" | awk -F/ '{print($3);}' | awk '/loop/ { print "yes"; }'`" ; then
-       if [ ! -x /sbin/losetup ]; then
-               echo "losetup is missing"
-               exit 1
-       fi
-       key="^# $(echo $rootdev | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
-       if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
-               echo "The root filesystem is on a $rootdev, but there is no magic entry in $fstab" 1>&2
-               echo "for this device. Consult the geninitrd man page for more information" 1>&2
-               exit 1
-       fi
+find_modules_for "$rootdev"
 
-       line="`awk '/'$key'/ { print $0; }' $fstab`"
-       loopDev="$(echo $line | awk '{print $3}')"
-       loopFs="$(echo $line | awk '{print $4}')"
-       loopFile="$(echo $line | awk '{print $5}')"
-
-       BASICMODULES="$BASICMODULES -loop"
-       findmodule "-$loopFs"
-       BASICMODULES="$BASICMODULES -${loopFs}"
-       # don't have any clue, how is this supposed to work,
-       # anyway no bsp
-       USEBSP="no"
-else # Check for other filesystems
-       findmodule "-$rootFs"
-fi
+findmodule "-$rootFs"
 
-for n in $BASICMODULES; do 
+for n in $BASICMODULES; do
        findmodule "$n"
 done
 
+
 if [ -n "$ifneeded" -a -z "$MODULES" ]; then
        if [ -n "$verbose" ]; then
                echo "No modules are needed -- not building initrd image."
@@ -460,7 +758,7 @@ MNTPOINT="`mktemp -d /tmp/initrd.mnt-XXXXXX`"
 RCFILE="$MNTIMAGE/linuxrc"
 
 if [ -f "$MNTIMAGE" ]; then
-       echo "$MNTIMAGE already exists.  Remove it and try again" 1>&2
+       echo "$MNTIMAGE already exists. Remove it and try again" 1>&2
        exit 1
 fi
 
@@ -469,7 +767,7 @@ if [ -f "$IMAGE" ]; then
        exit 1
 fi
 
-if [ "$FS" = "ext2" ] ; then
+if [ "$INITRDFS" = "ext2" ] ; then
        dd if=/dev/zero of="$IMAGE" bs=1k count="$IMAGESIZE" 2> /dev/null
 
        # We have to "echo y |" so that it doesn't complain about $IMAGE not
@@ -493,77 +791,108 @@ for MODULE in $MODULES; do
        MODULEDIR="`my_dirname "$MODULE"`"
        mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
        cp $verbose -a "/lib/modules/$kernel/$MODULE" "$MNTIMAGE/lib/modules/$kernel/$MODULE"
+       gunzip "$MNTIMAGE/lib/modules/$kernel/$MODULE" 2> /dev/null
 done
 
 # mknod'ing the devices instead of copying them works both with and
 # without devfs...
 mknod "$MNTIMAGE/dev/console" c 5 1
 
-if is_yes "$USEBSP" ; then
-       s="$MNTIMAGE/etc/startup"
-       inst /sbin/bsp "$RCFILE"
-       echo "# autogenerated startup" > "$s"
-       echo "" >> "$s"
-    
-       for MODULE in $MODULES; do
-               module="`echo $MODULE | awk -F/ '{ $0=$NF } /.o$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
-               options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
-    
-               if [ -n "$verbose" ]; then
-                       echo "Loading module $module with options $options"
-               fi
-               echo "insmod /lib/modules/$kernel/$MODULE $options" >> "$s"
-       done
+s="$MNTIMAGE/etc/startup"
+
+if [ -f /sbin/bsp-raidless ] ; then
+       inst /sbin/bsp-raidless "$RCFILE"
 else
-       inst /bin/trash "$MNTIMAGE/bin/sh"
-       inst /sbin/insmod.static "$MNTIMAGE/bin/insmod"
-    
-       mknod "$MNTIMAGE/dev/null" c 1 3
-       mknod "$MNTIMAGE/dev/ram" b 1 1
-       mknod "$MNTIMAGE/dev/systty" c 4 0
-       for i in 1 2 3 4; do
-               mknod "$MNTIMAGE/dev/tty$i" c 4 1
-       done
-       mknod "$MNTIMAGE/dev/zero" c 1 5
-    
-       echo "#!/bin/sh" > "$RCFILE"
-       echo "" >> "$RCFILE"
-    
-       for MODULE in $MODULES; do
-               module="`echo $MODULE | awk -F/ '{ $0=$NF } /.o$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
-               if [ -f "$modulefile" ] ; then
-                       options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
+       inst /sbin/bsp "$RCFILE"
+fi
+
+if is_yes "$USEINSMODSTATIC" ; then
+       inst "$INSMOD" $MNTIMAGE/bin/insmod.static
+fi
+
+echo "# autogenerated startup" > "$s"
+echo "" >> "$s"
+
+for MODULE in $MODULES; do
+       MODULE2="`my_dirname "$MODULE"`"
+       NAME2=`basename "$MODULE" .gz`
+       MODULE2=$MODULE2/$NAME2
+       module="`echo $MODULE | awk -F/ '{ $0=$NF } /'$modext'$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
+       options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
+
+       if [ -n "$verbose" ]; then
+               /bin/echo -n "Loading module $module "
+               if [ -n "$options" ] ; then
+                       echo "with options $options."
                else
-                       options=
+                       echo "without options."
                fi
+       fi
+       echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$s"
+done
 
-               if [ -n "$verbose" ]; then
-                       echo "Loading module $module with options $options"
-               fi
-               echo "Add module $module to initrd."
-               echo "echo \"Loading $module module\"" >> "$RCFILE"
-               echo "insmod -k /lib/modules/$kernel/$MODULE $options" >> "$RCFILE"
-       done
+# TODO: rewrite for bsp
+#if [ -n "$loopDev" ]; then
+#      if [ ! -d /initrd ]; then
+#              mkdir /initrd
+#      fi
+#
+#      cp -a "$loopDev" "$MNTIMAGE/dev"
+#      cp -a "$rootdev" "$MNTIMAGE/dev"
+#      echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
+#      echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
+#      echo "echo Setting up loopback device $rootdev" >> $RCFILE
+#      echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
+#fi
+
+if is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
+       if is_yes "$USEMDADMSTATIC" ; then
+               [ -n "$verbose" ] && echo "Setting up mdadm"
+               inst /sbin/initrd-mdadm "$MNTIMAGE/bin/mdadm"
+               echo "mdadm --assemble $rootdev $dev_list" >> "$s"
+       else
+               [ -n "$verbose" ] && echo "Adding raidstart to initrd"
+               inst "$raidtab" "$MNTIMAGE/etc/raidtab"
+               # don't use raidless version
+               inst /sbin/bsp "$RCFILE"
+               echo "raidstart $rootdev" >> "$s"
+       fi
 
-       if [ -n "$loopDev" ]; then
-               if [ ! -d /initrd ]; then
-                       mkdir /initrd
-               fi
-    
-               cp -a "$loopDev" "$MNTIMAGE/dev"
-               cp -a "$rootdev" "$MNTIMAGE/dev"
-               echo "echo Mounting device containing loopback root filesystem" >> "$RCFILE"
-               echo "mount -t $loopFs $loopDev /loopfs" >> "$RCFILE"
-               echo "echo Setting up loopback device $rootdev" >> $RCFILE
-               echo "losetup $rootdev /loopfs$loopFile" >> "$RCFILE"
+       # needed to determine md-version
+       if [ "$rootdev" != /dev/md0 ] ; then
+               mknod $MNTIMAGE/dev/md0 b 9 0
        fi
+       
+       for f in $dev_list $rootdev ; do
+               # mkdir in case of devfs name
+               mkdir -p `my_dirname $f`
+               [ -n "$verbose" ] && echo "copying $f"
+               # this works fine with and without devfs
+               cp -HR $f $MNTIMAGE/$f
+       done
+fi
+
+if is_yes "$uselvm" ; then
+       [ -n "$verbose" ] && echo "Adding LVM support to initrd"
+       inst /sbin/initrd-lvm $MNTIMAGE/bin/lvm
+       mkdir $MNTIMAGE/tmp
+       mkdir $MNTIMAGE/proc
+       echo "mount none /proc proc" >> "$s"
+       echo "mount none /tmp tmpfs" >> "$s"
+       echo "mount none /dev devfs" >> "$s"
+       echo "lvm vgscan -T" >> "$s"
+       echo "lvm vgchange -T -a y" >> "$s"
+       echo "umount /tmp" >> "$s"
+       echo "umount /proc" >> "$s"
+       # fail to umount
+       #echo "umount /devfs" >> "$s"
 fi
 
 chmod +x "$RCFILE"
 
 (cd "$MNTIMAGE"; tar cf - .) | (cd "$MNTPOINT"; tar xf -)
 
-case "$FS" in
+case "$INITRDFS" in
        ext2)
                umount "$IMAGE"
                ;;
@@ -574,8 +903,8 @@ case "$FS" in
                mkcramfs "$MNTPOINT" "$IMAGE"
                ;;
        *)
-               echo "Filesystem $FS not supported by $0";
-esac           
+               echo "Filesystem $INITRDFS not supported by $0";
+esac
 
 if is_yes "$COMPRESS" ; then
        gzip -9 < "$IMAGE" > "$target"
This page took 0.135853 seconds and 4 git commands to generate.