summarylogtreecommitdiffstats
path: root/use_grub-probe_in_grub-install.patch
blob: d6d5bc78bc1d59f8ed5b629073d9809078a830ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Index: b/util/grub-install.in
===================================================================
--- a/util/grub-install.in
+++ b/util/grub-install.in
@@ -137,106 +137,12 @@
 	exit 1
     fi
 
-    # Break the device name into the disk part and the partition part.
-    case "$host_os" in
-    linux*)
 	# Find an actual physical device if we're passed a RAID device
 	case $1 in
-		/dev/md*)  set -- `getraid_mdadm $1`
+		/dev/md* | /dev/md/*)  set -- `getraid_mdadm $1`
 	esac
-	tmp_disk=`echo "$1" | sed -e 's%\([sh]d[a-z]\)[0-9]*$%\1%' \
-				  -e 's%\(d[0-9]*\)p[0-9]*$%\1%' \
-				  -e 's%\(fd[0-9]*\)$%\1%' \
-				  -e 's%/part[0-9]*$%/disc%' \
-				  -e 's%\(c[0-7]d[0-9]*\).*$%\1%' \
-				  -e 's%\(e[0-9]\.[0-9]*\).*$%\1%'`
-	tmp_part=`echo "$1" | sed -e 's%.*/[sh]d[a-z]\([0-9]*\)$%\1%' \
-				  -e 's%.*d[0-9]*p%%' \
-				  -e 's%.*/fd[0-9]*$%%' \
-				  -e 's%.*/floppy/[0-9]*$%%' \
-				  -e 's%.*/\(disc\|part\([0-9]*\)\)$%\2%' \
-				  -e 's%.*c[0-7]d[0-9]*p*%%' \
-				  -e 's%.*e[0-9]\.[0-9]*p%%' \
-				  -e 's%.*e[0-9]\.[0-9]*\$%%'`
-	;;
-    gnu*)
-	tmp_disk=`echo "$1" | sed 's%\([sh]d[0-9]*\).*%\1%'`
-	tmp_part=`echo "$1" | sed "s%$tmp_disk%%"` ;;
-    freebsd* | kfreebsd*-gnu)
-	tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([saw]d[0-9]*\).*$%\1%' \
-			    | sed 's%r\{0,1\}\(da[0-9]*\).*$%\1%'`
-	tmp_part=`echo "$1" \
-	    | sed "s%.*/r\{0,1\}[saw]d[0-9]\(s[0-9]*[a-h]\)%\1%" \
-       	    | sed "s%.*/r\{0,1\}da[0-9]\(s[0-9]*[a-h]\)%\1%"`
-	;;
-    netbsd* | knetbsd*-gnu)
-	tmp_disk=`echo "$1" | sed 's%r\{0,1\}\([sw]d[0-9]*\).*$%r\1d%' \
-	    | sed 's%r\{0,1\}\(fd[0-9]*\).*$%r\1a%'`
-	tmp_part=`echo "$1" \
-	    | sed "s%.*/r\{0,1\}[sw]d[0-9]\([abe-p]\)%\1%"`
-	;;
-    *)
-	echo "grub-install does not support your OS yet." 1>&2
-	exit 1 ;;
-    esac
-
-    # Get the drive name.
-    tmp_drive=`grep -v '^#' $device_map | grep "$tmp_disk *$" \
-	| sed 's%.*\(([hf]d[0-9][a-z0-9,]*)\).*%\1%'`
-
-    # If not found, print an error message and exit.
-    if test "x$tmp_drive" = x; then
-	echo "$1 does not have any corresponding BIOS drive." 1>&2
-	exit 1
-    fi
 
-    if test "x$tmp_part" != x; then
-	# If a partition is specified, we need to translate it into the
-	# GRUB's syntax.
-	case "$host_os" in
-	linux*)
-	    echo "$tmp_drive" | sed "s%)$%,`expr $tmp_part - 1`)%" ;;
-	gnu*)
-	    if echo $tmp_part | grep "^s" >/dev/null; then
-		tmp_pc_slice=`echo $tmp_part \
-		    | sed "s%s\([0-9]*\)[a-z]*$%\1%"`
-		tmp_drive=`echo "$tmp_drive" \
-		    | sed "s%)%,\`expr "$tmp_pc_slice" - 1\`)%"`
-	    fi
-	    if echo $tmp_part | grep "[a-z]$" >/dev/null; then
-		tmp_bsd_partition=`echo "$tmp_part" \
-		    | sed "s%[^a-z]*\([a-z]\)$%\1%"`
-		tmp_drive=`echo "$tmp_drive" \
-		    | sed "s%)%,$tmp_bsd_partition)%"`
-	    fi
-	    echo "$tmp_drive" ;;
-	freebsd* | kfreebsd*-gnu)
-	    if echo $tmp_part | grep "^s" >/dev/null; then
-		tmp_pc_slice=`echo $tmp_part \
-		    | sed "s%s\([0-9]*\)[a-h]*$%\1%"`
-		tmp_drive=`echo "$tmp_drive" \
-		    | sed "s%)%,\`expr "$tmp_pc_slice" - 1\`)%"`
-	    fi
-	    if echo $tmp_part | grep "[a-h]$" >/dev/null; then
-		tmp_bsd_partition=`echo "$tmp_part" \
-		    | sed "s%s\{0,1\}[0-9]*\([a-h]\)$%\1%"`
-		tmp_drive=`echo "$tmp_drive" \
-		    | sed "s%)%,$tmp_bsd_partition)%"`
-	    fi
-	    echo "$tmp_drive" ;;
-	netbsd* | knetbsd*-gnu)
-	    if echo $tmp_part | grep "^[abe-p]$" >/dev/null; then
-		tmp_bsd_partition=`echo "$tmp_part" \
-		    | sed "s%\([a-p]\)$%\1%"`
-		tmp_drive=`echo "$tmp_drive" \
-		    | sed "s%)%,$tmp_bsd_partition)%"`
-	    fi
-	    echo "$tmp_drive" ;;
-	esac
-    else
-	# If no partition is specified, just print the drive name.
-	echo "$tmp_drive"
-    fi
+	GRUB_LEGACY_0_BASED_PARTITIONS=1 grub-probe --device-map=${device_map} -t drive -d "$1"
 }
 
 # Usage: resolve_symlink file
@@ -265,9 +171,7 @@
 # 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_fname=`grub-probe --device-map=${device_map} -t device $1/`
 
     if test -z "$tmp_fname"; then
 	echo "Could not find device for $1" 2>&1
@@ -384,22 +288,7 @@
 if test -f "$device_map"; then
     :
 else
-    # Create a safe temporary file.
-    test -n "$mklog" && log_file=`$mklog`
-
-    # Before all invocations of the grub shell, call sync to make sure
-    # the raw device is in sync with any bufferring in filesystems.
-    sync
- 
-    $grub_shell --batch $no_floppy --device-map=$device_map <<EOF >$log_file
-quit
-EOF
-    if grep "Error [0-9]*: " $log_file >/dev/null; then
-	cat $log_file 1>&2
-	exit 1
-    fi
-
-    rm -f $log_file
+    grub-mkdevicemap $no_floppy --device-map=$device_map
 fi
 
 # Make sure that there is no duplicated entry.