#
# based on mkinitrd from RedHat
-RCSID='$Id: geninitrd,v 2.24 2002/11/27 17:56:24 wiget Exp $'
+RCSID='$Id: geninitrd,v 2.36 2003/08/09 23:42:04 baggins Exp $'
PATH=/sbin:$PATH
export PATH
# 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-probe -ide-probe-mod -ide-disk"
+PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
+PREIDEMODSOLD="-ide-probe -ide-probe-mod -ide-disk"
target=""
kernel=""
force=""
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 " [--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]" 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
depfile=/lib/modules/$kernel/modules.dep
- if test -f $depfile ; then
+ 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 .o.gz if not given,
+ # 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 ".o.gz"}' |
+ awk '/\./ {print;next} {print $0 "'$modext'.gz"}' |
awk '{gsub("/","\\/");print}')
mods=$(awk '
BEGIN { here = 0 }
/(.*)/ { gsub(/\\/," "); if (here) print }
' $depfile | xargs)
- # fallback to .o
+ # fallback to $modext
if [ "$mods" = "" ] ; then
module=$(echo "$module" | \
- awk '{gsub("\.o\.gz$","\.o",$0);print}')
+ awk '{gsub("\'$modext'\.gz$","\'$modext'",$0);print}')
fi
mods=$(awk '
BEGIN { here = 0 }
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| LC_ALL=C sort -u`"
+ 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
}
find_modules_ide() {
- for n in $PREIDEMODS; do
+ 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
+ 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() {
findmodule "cciss"
elif is_yes "`echo "$1" | awk '/\/dev\/ataraid\// { print "yes"; }'`"; then
findmodule "ataraid"
- ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile| LC_ALL=C sort -u`"
+ 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 !"
--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;}'`"
;;
usage
fi
+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
s="$MNTIMAGE/etc/startup"
-if test -f /sbin/bsp-raidless ; then
+if [ -f /sbin/bsp-raidless ] ; then
inst /sbin/bsp-raidless "$RCFILE"
else
inst /sbin/bsp "$RCFILE"
fi
+if is_yes "$USEINSMODSTATIC" ; then
+ inst "$INSMOD" $MNTIMAGE/bin/insmod.static
+fi
+
echo "# autogenerated startup" > "$s"
echo "" >> "$s"
MODULE2="`my_dirname "$MODULE"`"
NAME2=`basename "$MODULE" .gz`
MODULE2=$MODULE2/$NAME2
- module="`echo $MODULE | awk -F/ '{ $0=$NF } /.o$/ { $0=substr($0,1,length($0)-2); } { print $0; }'`"
+ 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
echo "without options."
fi
fi
- echo "insmod /lib/modules/$kernel/$MODULE2 $options" >> "$s"
+ echo "$insmod /lib/modules/$kernel/$MODULE2 $options" >> "$s"
done
# TODO: rewrite for bsp
#fi
if is_yes "$USERAIDSTART" && is_yes "$raidfound" ; then
- [ -n "$verbose" ] && echo "Adding raidstart to initrd"
- inst "$raidtab" "$MNTIMAGE/etc/raidtab"
- # don't use raidless version
- inst /sbin/bsp "$RCFILE"
+ 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
# needed to determine md-version
if [ "$rootdev" != /dev/md0 ] ; then
# this works fine with and without devfs
cp -HR $f $MNTIMAGE/$f
done
-
- echo "raidstart $rootdev" >> "$s"
fi
if is_yes "$uselvm" ; then
echo "lvm vgchange -T -a y" >> "$s"
echo "umount /tmp" >> "$s"
echo "umount /proc" >> "$s"
- echo "umount /devfs" >> "$s"
+ # fail to umount
+ #echo "umount /devfs" >> "$s"
fi
chmod +x "$RCFILE"