]>
Commit | Line | Data |
---|---|---|
5626056f CW |
1 | #! /bin/sh |
2 | set -e | |
3 | ||
8901b00c | 4 | # Copyright (C) 2010 Free Software Foundation, Inc. |
5 | # | |
6 | # GRUB is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # GRUB is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU General Public License | |
17 | # along with GRUB. If not, see <http://www.gnu.org/licenses/>. | |
56672f4a | 18 | |
4ebff753 | 19 | parted=parted |
56672f4a | 20 | grubshell=@builddir@/grub-shell |
21 | ||
37ba07eb VS |
22 | . "@builddir@/grub-core/modinfo.sh" |
23 | ||
56672f4a | 24 | create_disk_image () { |
3fd8bae5 | 25 | name="$1" |
56672f4a | 26 | size=$2 |
3fd8bae5 VS |
27 | rm -f "${name}" |
28 | dd if=/dev/zero of="${name}" bs=512 count=1 seek=$((size * 2048 - 1)) status=noxfer > /dev/null | |
56672f4a | 29 | } |
30 | ||
31 | check_output () { | |
32 | outfile=$1 | |
33 | shift | |
34 | ||
37ba07eb VS |
35 | for dsk in $@; do |
36 | if ! grep "($dsk)" "${outfile}" >/dev/null | |
56672f4a | 37 | then |
37ba07eb | 38 | echo "($dsk): disk/partiton not found" |
56672f4a | 39 | exit 1 |
40 | fi | |
41 | done | |
42 | } | |
43 | ||
44 | list_parts () { | |
45 | mod=$1; | |
46 | shift; | |
37ba07eb | 47 | imgfile="$1" |
56672f4a | 48 | shift |
37ba07eb | 49 | outfile="$1" |
56672f4a | 50 | shift |
51 | ||
dbc56d8f | 52 | echo ls | "${grubshell}" --qemu-opts="-$qemudisk ${imgfile}" \ |
37ba07eb VS |
53 | --modules=$mod | tr -d "\n\r" > "${outfile}" |
54 | cat "${outfile}" | |
56672f4a | 55 | echo |
56 | } | |
57 | ||
37ba07eb | 58 | case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in |
eac49cff | 59 | mips-qemu_mips | mipsel-qemu_mips | i386-qemu | i386-multiboot | i386-coreboot | mipsel-loongson) |
37ba07eb | 60 | disk=ata0 |
dbc56d8f | 61 | qemudisk=hda |
37ba07eb | 62 | ;; |
34b2bced VS |
63 | powerpc-ieee1275) |
64 | disk=ieee1275//pci@80000000/mac-io@4/ata-3@20000/disk@0 | |
dbc56d8f | 65 | qemudisk=hda |
6aff0107 | 66 | # QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label. |
34b2bced VS |
67 | exit 0 |
68 | ;; | |
c9d586ea VS |
69 | sparc64-ieee1275) |
70 | disk=ieee1275//pci@1fe\,0/pci-ata@5/ide0@500/disk@0 | |
71 | qemudisk=hda | |
6aff0107 | 72 | # QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label. |
c9d586ea VS |
73 | exit 0 |
74 | ;; | |
dbc56d8f VS |
75 | i386-ieee1275) |
76 | disk=ieee1275/d | |
77 | qemudisk=hdb | |
6aff0107 | 78 | # QEMU firmware has bugs which prevent it from accessing hard disk w/o recognised label. |
a3d566d4 | 79 | exit 0 |
dbc56d8f | 80 | ;; |
6aff0107 VS |
81 | mips-arc) |
82 | # ARC firmware has bugs which prevent it from accessing hard disk w/o dvh disklabel. | |
83 | exit 0 | |
84 | ||
37ba07eb VS |
85 | *) |
86 | disk=hd0 | |
f9d40055 | 87 | qemudisk=hda |
37ba07eb VS |
88 | ;; |
89 | esac | |
90 | imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 | |
91 | outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 | |
56672f4a | 92 | |
93 | # | |
94 | # MSDOS partition types | |
95 | # | |
96 | ||
97 | echo "Checking MSDOS partition types..." | |
98 | ||
99 | # 0 primary | |
37ba07eb VS |
100 | create_disk_image "${imgfile}" 64 |
101 | ${parted} -a none -s "${imgfile}" mklabel msdos | |
102 | list_parts part_msdos "${imgfile}" "${outfile}" | |
103 | check_output "${outfile}" $disk | |
56672f4a | 104 | |
105 | # 1 primary | |
37ba07eb VS |
106 | create_disk_image "${imgfile}" 64 |
107 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M | |
108 | list_parts part_msdos "${imgfile}" "${outfile}" | |
109 | check_output "${outfile}" $disk $disk,msdos1 | |
56672f4a | 110 | |
111 | # 2 primary | |
37ba07eb VS |
112 | create_disk_image "${imgfile}" 128 |
113 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M | |
114 | list_parts part_msdos "${imgfile}" "${outfile}" | |
115 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 | |
56672f4a | 116 | |
117 | # 3 primary | |
37ba07eb VS |
118 | create_disk_image "${imgfile}" 128 |
119 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M | |
120 | list_parts part_msdos "${imgfile}" "${outfile}" | |
121 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 | |
56672f4a | 122 | |
123 | # 4 primary | |
37ba07eb VS |
124 | create_disk_image "${imgfile}" 128 |
125 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M | |
126 | list_parts part_msdos "${imgfile}" "${outfile}" | |
127 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 $disk,msdos4 | |
56672f4a | 128 | |
129 | # 1 primary, 1 extended | |
37ba07eb VS |
130 | create_disk_image "${imgfile}" 128 |
131 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% | |
132 | list_parts part_msdos "${imgfile}" "${outfile}" | |
133 | check_output "${outfile}" $disk $disk,msdos1 | |
56672f4a | 134 | |
135 | # 1 primary, 1 extended, 1 logical | |
37ba07eb VS |
136 | create_disk_image "${imgfile}" 128 |
137 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M | |
138 | list_parts part_msdos "${imgfile}" "${outfile}" | |
139 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 | |
56672f4a | 140 | |
141 | # 1 primary, 1 extended, 2 logical | |
37ba07eb VS |
142 | create_disk_image "${imgfile}" 128 |
143 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M mkpart logical 30M 40M | |
144 | list_parts part_msdos "${imgfile}" "${outfile}" | |
145 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 | |
56672f4a | 146 | |
147 | # 1 primary, 1 extended, 3 logical | |
37ba07eb VS |
148 | create_disk_image "${imgfile}" 128 |
149 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M mkpart logical 30M 40M mkpart logical 40M 50M | |
150 | list_parts part_msdos "${imgfile}" "${outfile}" | |
151 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 | |
56672f4a | 152 | |
153 | # 1 primary, 1 extended, 4 logical | |
37ba07eb VS |
154 | create_disk_image "${imgfile}" 128 |
155 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M mkpart logical 30M 40M mkpart logical 40M 50M mkpart logical 50M 60M | |
156 | list_parts part_msdos "${imgfile}" "${outfile}" | |
157 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 $disk,msdos8 | |
56672f4a | 158 | |
159 | ||
160 | # | |
161 | # GPT partition types | |
162 | # | |
163 | ||
164 | echo "Checking GPT partition types..." | |
165 | ||
166 | # 0 parts | |
37ba07eb VS |
167 | create_disk_image "${imgfile}" 64 |
168 | ${parted} -a none -s "${imgfile}" mklabel gpt | |
169 | list_parts part_gpt "${imgfile}" "${outfile}" | |
170 | check_output "${outfile}" $disk | |
56672f4a | 171 | |
172 | # 1 parts | |
37ba07eb VS |
173 | create_disk_image "${imgfile}" 64 |
174 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M | |
175 | list_parts part_gpt "${imgfile}" "${outfile}" | |
176 | check_output "${outfile}" $disk $disk,gpt1 | |
56672f4a | 177 | |
178 | # 2 parts | |
37ba07eb VS |
179 | create_disk_image "${imgfile}" 128 |
180 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M | |
181 | list_parts part_gpt "${imgfile}" "${outfile}" | |
182 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 | |
56672f4a | 183 | |
184 | # 3 parts | |
37ba07eb VS |
185 | create_disk_image "${imgfile}" 128 |
186 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M | |
187 | list_parts part_gpt "${imgfile}" "${outfile}" | |
188 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 | |
56672f4a | 189 | |
190 | # 4 parts | |
37ba07eb VS |
191 | create_disk_image "${imgfile}" 128 |
192 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 4 20M 30M mkpart 5 30M 40M | |
193 | list_parts part_gpt "${imgfile}" "${outfile}" | |
194 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 | |
56672f4a | 195 | |
196 | # 5 parts | |
37ba07eb VS |
197 | create_disk_image "${imgfile}" 128 |
198 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M mkpart 4 30M 40M mkpart 5 40M 50M | |
199 | list_parts part_gpt "${imgfile}" "${outfile}" | |
200 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5 | |
56672f4a | 201 | |
202 | # 6 parts | |
37ba07eb VS |
203 | create_disk_image "${imgfile}" 128 |
204 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M mkpart 4 30M 40M mkpart 5 40M 50M mkpart 6 50M 60M | |
205 | list_parts part_gpt "${imgfile}" "${outfile}" | |
206 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5 $disk,gpt6 | |
56672f4a | 207 | |
208 | ||
209 | # | |
210 | # SUN partition types | |
211 | # | |
212 | # It seems partition #3 is reserved for whole disk by parted. | |
213 | # | |
214 | ||
215 | echo "Checking SUN partition types..." | |
216 | ||
217 | # 0 parts | |
37ba07eb VS |
218 | create_disk_image "${imgfile}" 64 |
219 | ${parted} -a none -s "${imgfile}" mklabel sun | |
220 | list_parts part_sun "${imgfile}" "${outfile}" | |
221 | check_output "${outfile}" $disk | |
56672f4a | 222 | |
223 | # 1 parts | |
37ba07eb VS |
224 | create_disk_image "${imgfile}" 64 |
225 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M | |
226 | list_parts part_sun "${imgfile}" "${outfile}" | |
227 | check_output "${outfile}" $disk $disk,sun1 | |
56672f4a | 228 | |
229 | # 2 parts | |
37ba07eb VS |
230 | create_disk_image "${imgfile}" 128 |
231 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M | |
232 | list_parts part_sun "${imgfile}" "${outfile}" | |
233 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 | |
56672f4a | 234 | |
235 | # 3 parts | |
37ba07eb VS |
236 | create_disk_image "${imgfile}" 128 |
237 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M | |
238 | list_parts part_sun "${imgfile}" "${outfile}" | |
239 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 | |
56672f4a | 240 | |
241 | # 4 parts | |
37ba07eb VS |
242 | create_disk_image "${imgfile}" 128 |
243 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M | |
244 | list_parts part_sun "${imgfile}" "${outfile}" | |
245 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 | |
56672f4a | 246 | |
247 | # 5 parts | |
37ba07eb VS |
248 | create_disk_image "${imgfile}" 128 |
249 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M | |
250 | list_parts part_sun "${imgfile}" "${outfile}" | |
251 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 | |
56672f4a | 252 | |
253 | # 6 parts | |
37ba07eb VS |
254 | create_disk_image "${imgfile}" 128 |
255 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M mkpart 50M 60M | |
256 | list_parts part_sun "${imgfile}" "${outfile}" | |
257 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 $disk,sun7 | |
56672f4a | 258 | |
259 | ||
260 | # | |
261 | # Apple partition types | |
262 | # | |
263 | # Partition table itself is part of some partition, so there is always | |
264 | # a partition by default. But I don't understand why GRUB displays | |
265 | # two partitions by default :-( | |
266 | # | |
267 | ||
268 | echo "Checking APPLE partition types..." | |
269 | ||
270 | # 0 parts | |
37ba07eb VS |
271 | create_disk_image "${imgfile}" 64 |
272 | ${parted} -a none -s "${imgfile}" mklabel mac | |
273 | list_parts part_apple "${imgfile}" "${outfile}" | |
274 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 | |
56672f4a | 275 | |
276 | # 1 parts | |
37ba07eb VS |
277 | create_disk_image "${imgfile}" 64 |
278 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M | |
279 | list_parts part_apple "${imgfile}" "${outfile}" | |
280 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 | |
56672f4a | 281 | |
282 | # 2 parts | |
37ba07eb VS |
283 | create_disk_image "${imgfile}" 128 |
284 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M | |
285 | list_parts part_apple "${imgfile}" "${outfile}" | |
286 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 $disk,apple4 | |
56672f4a | 287 | |
288 | # 3 parts | |
37ba07eb VS |
289 | create_disk_image "${imgfile}" 128 |
290 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M | |
291 | list_parts part_apple "${imgfile}" "${outfile}" | |
292 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 | |
56672f4a | 293 | |
294 | # 4 parts | |
37ba07eb VS |
295 | create_disk_image "${imgfile}" 128 |
296 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M | |
297 | list_parts part_apple "${imgfile}" "${outfile}" | |
298 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 | |
56672f4a | 299 | |
300 | # 5 parts | |
37ba07eb VS |
301 | create_disk_image "${imgfile}" 128 |
302 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M | |
303 | list_parts part_apple "${imgfile}" "${outfile}" | |
304 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 | |
56672f4a | 305 | |
306 | # 6 parts | |
37ba07eb VS |
307 | create_disk_image "${imgfile}" 128 |
308 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M mkpart f 50M 60M | |
309 | list_parts part_apple "${imgfile}" "${outfile}" | |
310 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8 |