]>
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 | ||
37ba07eb VS |
52 | echo ls | "${grubshell}" --qemu-opts="-hda ${imgfile}" \ |
53 | --modules=$mod | tr -d "\n\r" > "${outfile}" | |
54 | cat "${outfile}" | |
56672f4a | 55 | echo |
56 | } | |
57 | ||
37ba07eb VS |
58 | case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in |
59 | mips-qemu_mips | mipsel-qemu_mips | i386-qemu | i386-multiboot | i386-coreboot) | |
60 | disk=ata0 | |
61 | ;; | |
34b2bced VS |
62 | powerpc-ieee1275) |
63 | disk=ieee1275//pci@80000000/mac-io@4/ata-3@20000/disk@0 | |
64 | # QEMU firmware has bugs which prevent it from accessing hard disk. | |
65 | exit 0 | |
66 | ;; | |
37ba07eb VS |
67 | *) |
68 | disk=hd0 | |
69 | ;; | |
70 | esac | |
71 | imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 | |
72 | outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1 | |
56672f4a | 73 | |
74 | # | |
75 | # MSDOS partition types | |
76 | # | |
77 | ||
78 | echo "Checking MSDOS partition types..." | |
79 | ||
80 | # 0 primary | |
37ba07eb VS |
81 | create_disk_image "${imgfile}" 64 |
82 | ${parted} -a none -s "${imgfile}" mklabel msdos | |
83 | list_parts part_msdos "${imgfile}" "${outfile}" | |
84 | check_output "${outfile}" $disk | |
56672f4a | 85 | |
86 | # 1 primary | |
37ba07eb VS |
87 | create_disk_image "${imgfile}" 64 |
88 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M | |
89 | list_parts part_msdos "${imgfile}" "${outfile}" | |
90 | check_output "${outfile}" $disk $disk,msdos1 | |
56672f4a | 91 | |
92 | # 2 primary | |
37ba07eb VS |
93 | create_disk_image "${imgfile}" 128 |
94 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M | |
95 | list_parts part_msdos "${imgfile}" "${outfile}" | |
96 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 | |
56672f4a | 97 | |
98 | # 3 primary | |
37ba07eb VS |
99 | create_disk_image "${imgfile}" 128 |
100 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M | |
101 | list_parts part_msdos "${imgfile}" "${outfile}" | |
102 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 | |
56672f4a | 103 | |
104 | # 4 primary | |
37ba07eb VS |
105 | create_disk_image "${imgfile}" 128 |
106 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M | |
107 | list_parts part_msdos "${imgfile}" "${outfile}" | |
108 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 $disk,msdos4 | |
56672f4a | 109 | |
110 | # 1 primary, 1 extended | |
37ba07eb VS |
111 | create_disk_image "${imgfile}" 128 |
112 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% | |
113 | list_parts part_msdos "${imgfile}" "${outfile}" | |
114 | check_output "${outfile}" $disk $disk,msdos1 | |
56672f4a | 115 | |
116 | # 1 primary, 1 extended, 1 logical | |
37ba07eb VS |
117 | create_disk_image "${imgfile}" 128 |
118 | ${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M | |
119 | list_parts part_msdos "${imgfile}" "${outfile}" | |
120 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 | |
56672f4a | 121 | |
122 | # 1 primary, 1 extended, 2 logical | |
37ba07eb VS |
123 | create_disk_image "${imgfile}" 128 |
124 | ${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 | |
125 | list_parts part_msdos "${imgfile}" "${outfile}" | |
126 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 | |
56672f4a | 127 | |
128 | # 1 primary, 1 extended, 3 logical | |
37ba07eb VS |
129 | create_disk_image "${imgfile}" 128 |
130 | ${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 | |
131 | list_parts part_msdos "${imgfile}" "${outfile}" | |
132 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 | |
56672f4a | 133 | |
134 | # 1 primary, 1 extended, 4 logical | |
37ba07eb VS |
135 | create_disk_image "${imgfile}" 128 |
136 | ${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 | |
137 | list_parts part_msdos "${imgfile}" "${outfile}" | |
138 | check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 $disk,msdos8 | |
56672f4a | 139 | |
140 | ||
141 | # | |
142 | # GPT partition types | |
143 | # | |
144 | ||
145 | echo "Checking GPT partition types..." | |
146 | ||
147 | # 0 parts | |
37ba07eb VS |
148 | create_disk_image "${imgfile}" 64 |
149 | ${parted} -a none -s "${imgfile}" mklabel gpt | |
150 | list_parts part_gpt "${imgfile}" "${outfile}" | |
151 | check_output "${outfile}" $disk | |
56672f4a | 152 | |
153 | # 1 parts | |
37ba07eb VS |
154 | create_disk_image "${imgfile}" 64 |
155 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M | |
156 | list_parts part_gpt "${imgfile}" "${outfile}" | |
157 | check_output "${outfile}" $disk $disk,gpt1 | |
56672f4a | 158 | |
159 | # 2 parts | |
37ba07eb VS |
160 | create_disk_image "${imgfile}" 128 |
161 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M | |
162 | list_parts part_gpt "${imgfile}" "${outfile}" | |
163 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 | |
56672f4a | 164 | |
165 | # 3 parts | |
37ba07eb VS |
166 | create_disk_image "${imgfile}" 128 |
167 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M | |
168 | list_parts part_gpt "${imgfile}" "${outfile}" | |
169 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 | |
56672f4a | 170 | |
171 | # 4 parts | |
37ba07eb VS |
172 | create_disk_image "${imgfile}" 128 |
173 | ${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 4 20M 30M mkpart 5 30M 40M | |
174 | list_parts part_gpt "${imgfile}" "${outfile}" | |
175 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 | |
56672f4a | 176 | |
177 | # 5 parts | |
37ba07eb VS |
178 | create_disk_image "${imgfile}" 128 |
179 | ${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 | |
180 | list_parts part_gpt "${imgfile}" "${outfile}" | |
181 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5 | |
56672f4a | 182 | |
183 | # 6 parts | |
37ba07eb VS |
184 | create_disk_image "${imgfile}" 128 |
185 | ${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 | |
186 | list_parts part_gpt "${imgfile}" "${outfile}" | |
187 | check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5 $disk,gpt6 | |
56672f4a | 188 | |
189 | ||
190 | # | |
191 | # SUN partition types | |
192 | # | |
193 | # It seems partition #3 is reserved for whole disk by parted. | |
194 | # | |
195 | ||
196 | echo "Checking SUN partition types..." | |
197 | ||
198 | # 0 parts | |
37ba07eb VS |
199 | create_disk_image "${imgfile}" 64 |
200 | ${parted} -a none -s "${imgfile}" mklabel sun | |
201 | list_parts part_sun "${imgfile}" "${outfile}" | |
202 | check_output "${outfile}" $disk | |
56672f4a | 203 | |
204 | # 1 parts | |
37ba07eb VS |
205 | create_disk_image "${imgfile}" 64 |
206 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M | |
207 | list_parts part_sun "${imgfile}" "${outfile}" | |
208 | check_output "${outfile}" $disk $disk,sun1 | |
56672f4a | 209 | |
210 | # 2 parts | |
37ba07eb VS |
211 | create_disk_image "${imgfile}" 128 |
212 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M | |
213 | list_parts part_sun "${imgfile}" "${outfile}" | |
214 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 | |
56672f4a | 215 | |
216 | # 3 parts | |
37ba07eb VS |
217 | create_disk_image "${imgfile}" 128 |
218 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M | |
219 | list_parts part_sun "${imgfile}" "${outfile}" | |
220 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 | |
56672f4a | 221 | |
222 | # 4 parts | |
37ba07eb VS |
223 | create_disk_image "${imgfile}" 128 |
224 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M | |
225 | list_parts part_sun "${imgfile}" "${outfile}" | |
226 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 | |
56672f4a | 227 | |
228 | # 5 parts | |
37ba07eb VS |
229 | create_disk_image "${imgfile}" 128 |
230 | ${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M | |
231 | list_parts part_sun "${imgfile}" "${outfile}" | |
232 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 | |
56672f4a | 233 | |
234 | # 6 parts | |
37ba07eb VS |
235 | create_disk_image "${imgfile}" 128 |
236 | ${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 | |
237 | list_parts part_sun "${imgfile}" "${outfile}" | |
238 | check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6 $disk,sun7 | |
56672f4a | 239 | |
240 | ||
241 | # | |
242 | # Apple partition types | |
243 | # | |
244 | # Partition table itself is part of some partition, so there is always | |
245 | # a partition by default. But I don't understand why GRUB displays | |
246 | # two partitions by default :-( | |
247 | # | |
248 | ||
249 | echo "Checking APPLE partition types..." | |
250 | ||
251 | # 0 parts | |
37ba07eb VS |
252 | create_disk_image "${imgfile}" 64 |
253 | ${parted} -a none -s "${imgfile}" mklabel mac | |
254 | list_parts part_apple "${imgfile}" "${outfile}" | |
255 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 | |
56672f4a | 256 | |
257 | # 1 parts | |
37ba07eb VS |
258 | create_disk_image "${imgfile}" 64 |
259 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M | |
260 | list_parts part_apple "${imgfile}" "${outfile}" | |
261 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 | |
56672f4a | 262 | |
263 | # 2 parts | |
37ba07eb VS |
264 | create_disk_image "${imgfile}" 128 |
265 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M | |
266 | list_parts part_apple "${imgfile}" "${outfile}" | |
267 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 $disk,apple4 | |
56672f4a | 268 | |
269 | # 3 parts | |
37ba07eb VS |
270 | create_disk_image "${imgfile}" 128 |
271 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M | |
272 | list_parts part_apple "${imgfile}" "${outfile}" | |
273 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 | |
56672f4a | 274 | |
275 | # 4 parts | |
37ba07eb VS |
276 | create_disk_image "${imgfile}" 128 |
277 | ${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M | |
278 | list_parts part_apple "${imgfile}" "${outfile}" | |
279 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 | |
56672f4a | 280 | |
281 | # 5 parts | |
37ba07eb VS |
282 | create_disk_image "${imgfile}" 128 |
283 | ${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 | |
284 | list_parts part_apple "${imgfile}" "${outfile}" | |
285 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 | |
56672f4a | 286 | |
287 | # 6 parts | |
37ba07eb VS |
288 | create_disk_image "${imgfile}" 128 |
289 | ${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 | |
290 | list_parts part_apple "${imgfile}" "${outfile}" | |
291 | check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8 |