BOOT_ARRAY=`df /boot | awk '/dev/{print $1}'`
if [ -n "$BOOT_ARRAY" ] ; then
  # Select only active disks (skip spares)
  case "$BOOT_ARRAY" in
  /dev/md* )
    DISKS=`mdadm --query --detail $BOOT_ARRAY | awk '/active sync/{print $7}'| sed '
s!/dev/!!g
s/,/ /g
s/[0-9]//g
'`
    for d in $DISKS
    do
      dpart=`mdadm --query --detail $BOOT_ARRAY | awk '/dev\/'$d'/ {print $7}'| sed 's!/dev/'$d'!!g'`
      dpart=`expr $dpart - 1`
      eval PART_$d=$dpart
    done
    ;;
  /dev/sd*|/dev/hd*)
    DISKS=`echo "$BOOT_ARRAY" | sed '
s!/dev/!!g
s/,/ /g
s/[0-9]//g
'`
    dpart=`echo "$BOOT_ARRAY" | sed 's!/dev/'$DISKS'!!g'`
    dpart=`expr $dpart - 1`
    eval PART_$d=$dpart
    ;;
  * )
    DISKS=""
    ;;
  esac

  for d in $DISKS
  do
    eval dpart=\$PART_$d
    echo bootspec setting grub on /dev/$d: to hd0,$dpart
    cat <<EOGRUB | /sbin/grub --batch
device (hd0) /dev/$d
root (hd0,$dpart)
setup (hd0)
quit
EOGRUB

  done
fi


