Index: util/grub-mkconfig_lib.in
===================================================================
--- util/grub-mkconfig_lib.in	(revision 2607)
+++ util/grub-mkconfig_lib.in	(working copy)
@@ -25,6 +25,17 @@
 
 grub_probe=${sbindir}/`echo grub-probe | sed ${transform}`
 
+case "`uname 2>/dev/null`" in
+  FreeBSD*)
+    grub_readlink=realpath
+    grub_getdevice="stat -f %d"
+    ;;
+  *)
+    grub_readlink="readlink -f"
+    grub_getdevice="stat -c %d"
+    ;;
+esac
+
 grub_warn ()
 {
   echo "Warning: $@" >&2
@@ -39,7 +50,7 @@
   fi
 
   # canonicalize
-  if path=`readlink -f $path` ; then : ; else
+  if path=`$grub_readlink $path` ; then : ; else
     return 1
   fi
 
@@ -50,12 +61,12 @@
     dir=`echo $path | sed -e "s,/[^/]*$,,g"`
   fi
 
-  num=`stat -c %d $dir`
+  num=`$grub_getdevice $dir`
 
   # this loop sets $dir to the root directory of the filesystem we're inspecting
   while : ; do
-    parent=`readlink -f $dir/..`
-    if [ "x`stat -c %d $parent`" = "x$num" ] ; then : ; else
+    parent=`$grub_readlink $dir/..`
+    if [ "x`$grub_getdevice $parent`" = "x$num" ] ; then : ; else
       # $parent is another filesystem; we found it.
       break
     fi
