--- /stuff/slackware/non-public/alien/slackware64/source/a/mkinitrd/mkinitrd	2008-11-30 15:35:58.000000000 +0100
+++ /stuff/slackware/non-public/slackware-current/source/a/mkinitrd/mkinitrd	2008-12-17 21:09:08.000000000 +0100
@@ -25,9 +25,19 @@
 # to add support for mkinitrd.conf - No additional license terms added
 # Modified by Alan Hicks <alan@slackware.com> 27 November 2007 to enable
 # passing arguments to kernel modules - No additional license terms added
-# volkderdi - feel free to remove these :)
+# volkerdi - feel free to remove these :)
 # Modified by Eric Hameleers <alien@slackware.com> 3 April 2008
 # to add support custom keymaps - No additional license terms added
+# Modified by Patrick Volkerding <volkerdi@slackware.com> 17 Dec 2008
+# Added support to bail out if kernel modules are requested for a kernel
+# version that is not installed (thanks to Eric Hameleers), be more
+# verbose about showing modules added to the initrd (thanks to
+# Ellington Santos), and if "mount" returns /dev/root as the root device,
+# use readlink to resolve the device pointed to by the /dev/root
+# symlink, changed modprobe to use --ignore-install to avoid catching
+# custom "install" lines and causing /sbin/modprobe to be copied to the
+# initrd (thanks to Ken Milmore).
+# Of course, license terms remain unchanged.
 
 MKINITRD_VERSION=1.3.3
 
@@ -277,6 +287,12 @@
   esac
 done
 
+# If kernel modules are needed but the kernel version is absent, exit now:
+if [ ! -d /lib/modules/$KERNEL_VERSION ]; then
+  echo "ERROR: No /lib/modules/$KERNEL_VERSION kernel modules tree found for kernel \"$KERNEL_VERSION\""
+  exit 1
+fi
+
 # If clearing source tree was requested, do that first
 if [ "$CLEAR_TREE" = "1" ]; then
   clear_source_tree
@@ -290,10 +306,13 @@
 # If $ROOTDEV and $ROOTFS are not set, assume we want the
 # values for the currently mounted /
 # (unless we find that values are already set in the initrd-tree):
-if [ -z "$ROOTDEV" -a -z "$(cat $SOURCE_TREE/rootdev)" ]; then
+if [ -z "$ROOTDEV" -a -z "$(cat $SOURCE_TREE/rootdev 2> /dev/null)" ]; then
   ROOTDEV=$(mount | grep ' on / ' | cut -f 1 -d ' ')
+  if [ "$ROOTDEV" = "/dev/root" ]; then # find real root device
+    ROOTDEV="/dev/$(readlink /dev/root)"
+  fi
 fi
-if [ -z "$ROOTFS" -a -z "$(cat $SOURCE_TREE/rootfs)" ]; then
+if [ -z "$ROOTFS" -a -z "$(cat $SOURCE_TREE/rootfs 2> /dev/null)" ]; then
   ROOTFS=$(mount | grep ' on / ' | cut -f 5 -d ' ')
 fi
 # If needed, write them in the initrd-tree:
@@ -433,8 +451,8 @@
   fi
 
   # Get MODULE deps and prepare insmod lines
-  /sbin/modprobe --set-version $KERNEL_VERSION --show-depends $MODULE 2> /dev/null \
-    | cut -f 2 -d ' ' | while read SRCMOD; do
+  /sbin/modprobe --set-version $KERNEL_VERSION --show-depends --ignore-install $MODULE 2> /dev/null \
+    | grep "^insmod " | cut -f 2 -d ' ' | while read SRCMOD; do
 
     if ! grep -q "$SRCMOD" $SOURCE_TREE/load_kernel_modules 2>/dev/null ; then
       LINE="$(echo "insmod -v $SRCMOD" | sed -e "s/$KERNEL_VERSION/\$(uname -r)/")"
@@ -452,8 +470,8 @@
       echo "$LINE" >> $SOURCE_TREE/load_kernel_modules
     fi
 
-    if [ -r "$SRCMOD" ]; then
-      cp -a --parents $SRCMOD $SOURCE_TREE
+    if cp -a --parents $SRCMOD $SOURCE_TREE 2> /dev/null; then
+      echo "OK: $SRCMOD added."
     else
       echo "WARNING:  Could not find module \"$SRCMOD\""
     fi
