]> git.proxmox.com Git - grub2.git/blob - tests/partmap_test.in
* New Bazaar snapshot.
[grub2.git] / tests / partmap_test.in
1 #! /bin/sh -e
2 #
3 # Copyright (C) 2010 Free Software Foundation, Inc.
4 #
5 # GRUB is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # GRUB is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17
18 parted=/sbin/parted
19 grubshell=@builddir@/grub-shell
20
21 create_disk_image () {
22 name=$1
23 size=$2
24 qemu-img create ${name} ${size} >/dev/null
25 }
26
27 check_output () {
28 outfile=$1
29 shift
30
31 for disk in $@; do
32 if ! grep "($disk)" ${outfile} >/dev/null
33 then
34 echo "($disk): disk/partiton not found"
35 exit 1
36 fi
37 done
38 }
39
40 list_parts () {
41 mod=$1;
42 shift;
43 imgfile=$1
44 shift
45 outfile=$1
46 shift
47
48 echo ls | ${grubshell} --boot=cd --qemu-opts="-hda ${imgfile}" \
49 --modules=$mod | tr -d "\n\r" > ${outfile}
50 cat ${outfile}
51 echo
52 }
53
54 imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
55 outfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
56
57 #
58 # MSDOS partition types
59 #
60
61 echo "Checking MSDOS partition types..."
62
63 # 0 primary
64 create_disk_image ${imgfile} 64M
65 ${parted} -a none -s ${imgfile} mklabel msdos
66 list_parts part_msdos ${imgfile} ${outfile}
67 check_output ${outfile} hd0
68
69 # 1 primary
70 create_disk_image ${imgfile} 64M
71 ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M
72 list_parts part_msdos ${imgfile} ${outfile}
73 check_output ${outfile} hd0 hd0,msdos1
74
75 # 2 primary
76 create_disk_image ${imgfile} 128M
77 ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M
78 list_parts part_msdos ${imgfile} ${outfile}
79 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2
80
81 # 3 primary
82 create_disk_image ${imgfile} 128M
83 ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M
84 list_parts part_msdos ${imgfile} ${outfile}
85 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3
86
87 # 4 primary
88 create_disk_image ${imgfile} 128M
89 ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M
90 list_parts part_msdos ${imgfile} ${outfile}
91 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3 hd0,msdos4
92
93 # 1 primary, 1 extended
94 create_disk_image ${imgfile} 128M
95 ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100%
96 list_parts part_msdos ${imgfile} ${outfile}
97 check_output ${outfile} hd0 hd0,msdos1
98
99 # 1 primary, 1 extended, 1 logical
100 create_disk_image ${imgfile} 128M
101 ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M
102 list_parts part_msdos ${imgfile} ${outfile}
103 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5
104
105 # 1 primary, 1 extended, 2 logical
106 create_disk_image ${imgfile} 128M
107 ${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
108 list_parts part_msdos ${imgfile} ${outfile}
109 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6
110
111 # 1 primary, 1 extended, 3 logical
112 create_disk_image ${imgfile} 128M
113 ${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
114 list_parts part_msdos ${imgfile} ${outfile}
115 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7
116
117 # 1 primary, 1 extended, 4 logical
118 create_disk_image ${imgfile} 128M
119 ${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
120 list_parts part_msdos ${imgfile} ${outfile}
121 check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7 hd0,msdos8
122
123
124 #
125 # GPT partition types
126 #
127
128 echo "Checking GPT partition types..."
129
130 # 0 parts
131 create_disk_image ${imgfile} 64M
132 ${parted} -a none -s ${imgfile} mklabel gpt
133 list_parts part_gpt ${imgfile} ${outfile}
134 check_output ${outfile} hd0
135
136 # 1 parts
137 create_disk_image ${imgfile} 64M
138 ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M
139 list_parts part_gpt ${imgfile} ${outfile}
140 check_output ${outfile} hd0 hd0,gpt1
141
142 # 2 parts
143 create_disk_image ${imgfile} 128M
144 ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M
145 list_parts part_gpt ${imgfile} ${outfile}
146 check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2
147
148 # 3 parts
149 create_disk_image ${imgfile} 128M
150 ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M
151 list_parts part_gpt ${imgfile} ${outfile}
152 check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3
153
154 # 4 parts
155 create_disk_image ${imgfile} 128M
156 ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 4 20M 30M mkpart 5 30M 40M
157 list_parts part_gpt ${imgfile} ${outfile}
158 check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4
159
160 # 5 parts
161 create_disk_image ${imgfile} 128M
162 ${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
163 list_parts part_gpt ${imgfile} ${outfile}
164 check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5
165
166 # 6 parts
167 create_disk_image ${imgfile} 128M
168 ${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
169 list_parts part_gpt ${imgfile} ${outfile}
170 check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5 hd0,gpt6
171
172
173 #
174 # SUN partition types
175 #
176 # It seems partition #3 is reserved for whole disk by parted.
177 #
178
179 echo "Checking SUN partition types..."
180
181 # 0 parts
182 create_disk_image ${imgfile} 64M
183 ${parted} -a none -s ${imgfile} mklabel sun
184 list_parts part_sun ${imgfile} ${outfile}
185 check_output ${outfile} hd0
186
187 # 1 parts
188 create_disk_image ${imgfile} 64M
189 ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M
190 list_parts part_sun ${imgfile} ${outfile}
191 check_output ${outfile} hd0 hd0,sun1
192
193 # 2 parts
194 create_disk_image ${imgfile} 128M
195 ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M
196 list_parts part_sun ${imgfile} ${outfile}
197 check_output ${outfile} hd0 hd0,sun1 hd0,sun2
198
199 # 3 parts
200 create_disk_image ${imgfile} 128M
201 ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M
202 list_parts part_sun ${imgfile} ${outfile}
203 check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4
204
205 # 4 parts
206 create_disk_image ${imgfile} 128M
207 ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M
208 list_parts part_sun ${imgfile} ${outfile}
209 check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5
210
211 # 5 parts
212 create_disk_image ${imgfile} 128M
213 ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M
214 list_parts part_sun ${imgfile} ${outfile}
215 check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6
216
217 # 6 parts
218 create_disk_image ${imgfile} 128M
219 ${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
220 list_parts part_sun ${imgfile} ${outfile}
221 check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6 hd0,sun7
222
223
224 #
225 # Apple partition types
226 #
227 # Partition table itself is part of some partition, so there is always
228 # a partition by default. But I don't understand why GRUB displays
229 # two partitions by default :-(
230 #
231
232 echo "Checking APPLE partition types..."
233
234 # 0 parts
235 create_disk_image ${imgfile} 64M
236 ${parted} -a none -s ${imgfile} mklabel mac
237 list_parts part_apple ${imgfile} ${outfile}
238 check_output ${outfile} hd0 hd0,apple1 hd0,apple2
239
240 # 1 parts
241 create_disk_image ${imgfile} 64M
242 ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M
243 list_parts part_apple ${imgfile} ${outfile}
244 check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3
245
246 # 2 parts
247 create_disk_image ${imgfile} 128M
248 ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M
249 list_parts part_apple ${imgfile} ${outfile}
250 check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3 hd0,apple4
251
252 # 3 parts
253 create_disk_image ${imgfile} 128M
254 ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M
255 list_parts part_apple ${imgfile} ${outfile}
256 check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5
257
258 # 4 parts
259 create_disk_image ${imgfile} 128M
260 ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M
261 list_parts part_apple ${imgfile} ${outfile}
262 check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6
263
264 # 5 parts
265 create_disk_image ${imgfile} 128M
266 ${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
267 list_parts part_apple ${imgfile} ${outfile}
268 check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7
269
270 # 6 parts
271 create_disk_image ${imgfile} 128M
272 ${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
273 list_parts part_apple ${imgfile} ${outfile}
274 check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7 hd0,apple8