--- setup.original	2006-02-22 13:02:32.000000000 -0600
+++ setup	2006-02-22 23:07:57.000000000 -0600
@@ -123,6 +123,50 @@
 	done
 }
 
+get_grub_map() {
+	rm /tmp/dev.map
+	dodialog infobox "Generating GRUB device map...\nThis could take a while.\n\n Please be patient."	
+	$DESTDIR/sbin/grub --no-floppy --device-map /tmp/dev.map >/tmp/grub.log 2>&1 <<EOF
+quit
+EOF
+}
+
+mapdev() {
+	partition_flag=0
+	device_found=0
+	devs=`cat /tmp/dev.map | grep -v fd | sed 's/ *\t/ /' | sed ':a;$!N;$!ba;s/\n/ /g'`
+	linuxdevice=`echo $1 | cut -b1-8`
+	if [ "`echo $1 | egrep '[0-9]$'`" ]; then
+		# /dev/hdXY
+		pnum=`echo $1 | cut -b9-`
+		pnum=$(($pnum-1))
+		partition_flag=1
+	fi
+	for  dev in $devs
+	do
+	    if [ "(" = `echo $dev | cut -b1` ]; then
+		grubdevice="$dev"
+	    else
+		if [ "$dev" = "$linuxdevice" ]; then
+			device_found=1
+			break   
+		fi
+	   fi
+	done	
+	if [ "$device_found" = "1" ]; then
+		if [ "$partition_flag" = "0" ]; then
+			echo "$grubdevice"
+		else
+			grubdevice_stringlen=${#grubdevice}
+			let grubdevice_stringlen--
+			grubdevice=`echo $grubdevice | cut -b1-$grubdevice_stringlen`
+			echo "$grubdevice,$pnum)"
+		fi
+	else
+		echo " DEVICE NOT FOUND"
+	fi
+}
+
 convertdev() {
 	# assume a /dev/hdX or /dev/hdXY name
 	letter=`echo $1 | cut -b8`
@@ -935,13 +979,14 @@
 }
 
 dogrub() {
+	get_grub_map	
 	if [ ! -f $DESTDIR/boot/grub/menu.lst ]; then
 		msg "Error: Couldn't find $DESTDIR/boot/grub/menu.lst.  Is GRUB installed?"
 		return 1
 	fi
 	# try to auto-configure GRUB...
 	if [ "$PART_ROOT" != "" -a "$S_GRUB" != "1" ]; then
-		grubdev=`convertdev $PART_ROOT`
+		grubdev=`mapdev $PART_ROOT`
 		# look for a separately-mounted /boot partition
 		bootdev=`mount | grep $DESTDIR/boot | cut -d' ' -f 1`
 		if [ "$grubdev" != "" -o "$bootdev" != "" ]; then
@@ -954,7 +999,7 @@
 			echo "title  Arch Linux" >>$DESTDIR/boot/grub/menu.lst
 			subdir=
 			if [ "$bootdev" != "" ]; then
-				grubdev=`convertdev $bootdev`
+				grubdev=`mapdev $bootdev`
 			else
 				subdir="/boot"
 			fi
@@ -992,8 +1037,8 @@
 			bootpart=$PART_ROOT
 		fi
 	fi
-	bootpart=`convertdev $bootpart`
-	bootdev=`convertdev $ROOTDEV`
+	bootpart=`mapdev $bootpart`
+	bootdev=`mapdev $ROOTDEV`
 	if [ "$bootpart" = "" ]; then
 		msg "Error: Missing/Invalid root device: $bootpart"
 		return 1
