]> git.proxmox.com Git - grub2.git/blame - tests/partmap_test.in
* util/grub-mkrescue.in: Fix loongson filename.
[grub2.git] / tests / partmap_test.in
CommitLineData
5626056f
CW
1#! /bin/sh
2set -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 19parted=parted
56672f4a 20grubshell=@builddir@/grub-shell
21
37ba07eb
VS
22. "@builddir@/grub-core/modinfo.sh"
23
56672f4a 24create_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
31check_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
44list_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 58case "${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 ;;
89esac
90imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
91outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
56672f4a 92
93#
94# MSDOS partition types
95#
96
97echo "Checking MSDOS partition types..."
98
99# 0 primary
37ba07eb
VS
100create_disk_image "${imgfile}" 64
101${parted} -a none -s "${imgfile}" mklabel msdos
102list_parts part_msdos "${imgfile}" "${outfile}"
103check_output "${outfile}" $disk
56672f4a 104
105# 1 primary
37ba07eb
VS
106create_disk_image "${imgfile}" 64
107${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M
108list_parts part_msdos "${imgfile}" "${outfile}"
109check_output "${outfile}" $disk $disk,msdos1
56672f4a 110
111# 2 primary
37ba07eb
VS
112create_disk_image "${imgfile}" 128
113${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M
114list_parts part_msdos "${imgfile}" "${outfile}"
115check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2
56672f4a 116
117# 3 primary
37ba07eb
VS
118create_disk_image "${imgfile}" 128
119${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M
120list_parts part_msdos "${imgfile}" "${outfile}"
121check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3
56672f4a 122
123# 4 primary
37ba07eb
VS
124create_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
126list_parts part_msdos "${imgfile}" "${outfile}"
127check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 $disk,msdos4
56672f4a 128
129# 1 primary, 1 extended
37ba07eb
VS
130create_disk_image "${imgfile}" 128
131${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100%
132list_parts part_msdos "${imgfile}" "${outfile}"
133check_output "${outfile}" $disk $disk,msdos1
56672f4a 134
135# 1 primary, 1 extended, 1 logical
37ba07eb
VS
136create_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
138list_parts part_msdos "${imgfile}" "${outfile}"
139check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5
56672f4a 140
141# 1 primary, 1 extended, 2 logical
37ba07eb
VS
142create_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
144list_parts part_msdos "${imgfile}" "${outfile}"
145check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6
56672f4a 146
147# 1 primary, 1 extended, 3 logical
37ba07eb
VS
148create_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
150list_parts part_msdos "${imgfile}" "${outfile}"
151check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7
56672f4a 152
153# 1 primary, 1 extended, 4 logical
37ba07eb
VS
154create_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
156list_parts part_msdos "${imgfile}" "${outfile}"
157check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 $disk,msdos8
56672f4a 158
159
160#
161# GPT partition types
162#
163
164echo "Checking GPT partition types..."
165
166# 0 parts
37ba07eb
VS
167create_disk_image "${imgfile}" 64
168${parted} -a none -s "${imgfile}" mklabel gpt
169list_parts part_gpt "${imgfile}" "${outfile}"
170check_output "${outfile}" $disk
56672f4a 171
172# 1 parts
37ba07eb
VS
173create_disk_image "${imgfile}" 64
174${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M
175list_parts part_gpt "${imgfile}" "${outfile}"
176check_output "${outfile}" $disk $disk,gpt1
56672f4a 177
178# 2 parts
37ba07eb
VS
179create_disk_image "${imgfile}" 128
180${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M
181list_parts part_gpt "${imgfile}" "${outfile}"
182check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2
56672f4a 183
184# 3 parts
37ba07eb
VS
185create_disk_image "${imgfile}" 128
186${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M
187list_parts part_gpt "${imgfile}" "${outfile}"
188check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3
56672f4a 189
190# 4 parts
37ba07eb
VS
191create_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
193list_parts part_gpt "${imgfile}" "${outfile}"
194check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4
56672f4a 195
196# 5 parts
37ba07eb
VS
197create_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
199list_parts part_gpt "${imgfile}" "${outfile}"
200check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5
56672f4a 201
202# 6 parts
37ba07eb
VS
203create_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
205list_parts part_gpt "${imgfile}" "${outfile}"
206check_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
215echo "Checking SUN partition types..."
216
217# 0 parts
37ba07eb
VS
218create_disk_image "${imgfile}" 64
219${parted} -a none -s "${imgfile}" mklabel sun
220list_parts part_sun "${imgfile}" "${outfile}"
221check_output "${outfile}" $disk
56672f4a 222
223# 1 parts
37ba07eb
VS
224create_disk_image "${imgfile}" 64
225${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M
226list_parts part_sun "${imgfile}" "${outfile}"
227check_output "${outfile}" $disk $disk,sun1
56672f4a 228
229# 2 parts
37ba07eb
VS
230create_disk_image "${imgfile}" 128
231${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M
232list_parts part_sun "${imgfile}" "${outfile}"
233check_output "${outfile}" $disk $disk,sun1 $disk,sun2
56672f4a 234
235# 3 parts
37ba07eb
VS
236create_disk_image "${imgfile}" 128
237${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M
238list_parts part_sun "${imgfile}" "${outfile}"
239check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4
56672f4a 240
241# 4 parts
37ba07eb
VS
242create_disk_image "${imgfile}" 128
243${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M
244list_parts part_sun "${imgfile}" "${outfile}"
245check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5
56672f4a 246
247# 5 parts
37ba07eb
VS
248create_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
250list_parts part_sun "${imgfile}" "${outfile}"
251check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6
56672f4a 252
253# 6 parts
37ba07eb
VS
254create_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
256list_parts part_sun "${imgfile}" "${outfile}"
257check_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
268echo "Checking APPLE partition types..."
269
270# 0 parts
37ba07eb
VS
271create_disk_image "${imgfile}" 64
272${parted} -a none -s "${imgfile}" mklabel mac
273list_parts part_apple "${imgfile}" "${outfile}"
274check_output "${outfile}" $disk $disk,apple1 $disk,apple2
56672f4a 275
276# 1 parts
37ba07eb
VS
277create_disk_image "${imgfile}" 64
278${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M
279list_parts part_apple "${imgfile}" "${outfile}"
280check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3
56672f4a 281
282# 2 parts
37ba07eb
VS
283create_disk_image "${imgfile}" 128
284${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M
285list_parts part_apple "${imgfile}" "${outfile}"
286check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 $disk,apple4
56672f4a 287
288# 3 parts
37ba07eb
VS
289create_disk_image "${imgfile}" 128
290${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M
291list_parts part_apple "${imgfile}" "${outfile}"
292check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5
56672f4a 293
294# 4 parts
37ba07eb
VS
295create_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
297list_parts part_apple "${imgfile}" "${outfile}"
298check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6
56672f4a 299
300# 5 parts
37ba07eb
VS
301create_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
303list_parts part_apple "${imgfile}" "${outfile}"
304check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7
56672f4a 305
306# 6 parts
37ba07eb
VS
307create_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
309list_parts part_apple "${imgfile}" "${outfile}"
310check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8