I took another look at this.

The problem (in my case) is in find_device ().

    # Usage: find_device file
    # Find block device on which the file resides.
    find_device () {
        # For now, this uses the program `df' to get the device name, but is
        # this really portable?
        tmp_fname=`df $1/ | sed -n 's%.*\(/dev/[^   ]*\).*%\1%p'`

This breaks when chrooted into a non-running system, if mtab doesn't reflect 
the partition layout.  (df its gets partition info from /etc/mtab.  If mtab 
reflects a different partition layout, then df reports the wrong 
partitions).

I have confirmed that manually correcting the mtab entry for / is sufficient 
for grub-install to complete.  (/boot may be needed as well, no /boot 
partition on this box).

A possible fix might be to parse /etc/fstab instead.  Attached is a patch to 
do this.  The current version does not attempt to handle partitions mounted 
using uids/labels.  Is it worthwhile trying to extend the patch, or is 
there a better approach?

Unless I hear otherwise, I'll file a bug on coreutils in a few days about 
the wrong df output.

HTH 
Andrew V.
--- /sbin/grub-install	2005-04-19 09:39:44.000000000 +1000
+++ /shared/grub-install	2006-01-26 05:34:49.000000000 +1100
@@ -261,18 +261,32 @@
 # Usage: find_device file
 # Find block device on which the file resides.
 find_device () {
-    # For now, this uses the program `df' to get the device name, but is
-    # this really portable?
-    tmp_fname=`df $1/ | sed -n 's%.*\(/dev/[^ 	]*\).*%\1%p'`
+    tmp_filename="$1"
+    
+    # we get called once with $1=null 
+    # look for the root partion if $1="" 
+    if test -z "$tmp_filename" ; then
+        tmp_filename="/"
+    fi
+ 
+    tmp_devicename=""    
+    while ( test -z "$tmp_devicename" ) ; do
+        # get parse /etc/fstab	
+        tmp_devicename=`cat /etc/fstab | sed -n \
+            -e"s%^[ \t]*\(/dev/[^ \t]\{3,5\}\)[^/]*$tmp_filename[ \t].*%\1%p"`
+    
+        # lop off last directory segment for next iteration.
+         tmp_filename=`dirname "$tmp_filename"`
+    done
 
-    if test -z "$tmp_fname"; then
+    if ( test -z "$tmp_devicename" ) ; then
 	echo "Could not find device for $1" 2>&1
 	exit 1
     fi
 
-	tmp_fname=`resolve_symlink $tmp_fname`
+    tmp_devicename=`resolve_symlink $tmp_devicename`
 
-    echo "$tmp_fname"
+    echo "$tmp_devicename"
 }
 
 # Check the arguments.

Reply via email to