]> git.proxmox.com Git - grub2.git/blame - tests/partmap_test.in
* grub-core/lib/mips/loongson/reboot.c (grub_reboot): Use 32-bit
[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
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
58case "${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 ;;
70esac
71imgfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
72outfile="`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"`" || exit 1
56672f4a 73
74#
75# MSDOS partition types
76#
77
78echo "Checking MSDOS partition types..."
79
80# 0 primary
37ba07eb
VS
81create_disk_image "${imgfile}" 64
82${parted} -a none -s "${imgfile}" mklabel msdos
83list_parts part_msdos "${imgfile}" "${outfile}"
84check_output "${outfile}" $disk
56672f4a 85
86# 1 primary
37ba07eb
VS
87create_disk_image "${imgfile}" 64
88${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M
89list_parts part_msdos "${imgfile}" "${outfile}"
90check_output "${outfile}" $disk $disk,msdos1
56672f4a 91
92# 2 primary
37ba07eb
VS
93create_disk_image "${imgfile}" 128
94${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M
95list_parts part_msdos "${imgfile}" "${outfile}"
96check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2
56672f4a 97
98# 3 primary
37ba07eb
VS
99create_disk_image "${imgfile}" 128
100${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M
101list_parts part_msdos "${imgfile}" "${outfile}"
102check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3
56672f4a 103
104# 4 primary
37ba07eb
VS
105create_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
107list_parts part_msdos "${imgfile}" "${outfile}"
108check_output "${outfile}" $disk $disk,msdos1 $disk,msdos2 $disk,msdos3 $disk,msdos4
56672f4a 109
110# 1 primary, 1 extended
37ba07eb
VS
111create_disk_image "${imgfile}" 128
112${parted} -a none -s "${imgfile}" mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100%
113list_parts part_msdos "${imgfile}" "${outfile}"
114check_output "${outfile}" $disk $disk,msdos1
56672f4a 115
116# 1 primary, 1 extended, 1 logical
37ba07eb
VS
117create_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
119list_parts part_msdos "${imgfile}" "${outfile}"
120check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5
56672f4a 121
122# 1 primary, 1 extended, 2 logical
37ba07eb
VS
123create_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
125list_parts part_msdos "${imgfile}" "${outfile}"
126check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6
56672f4a 127
128# 1 primary, 1 extended, 3 logical
37ba07eb
VS
129create_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
131list_parts part_msdos "${imgfile}" "${outfile}"
132check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7
56672f4a 133
134# 1 primary, 1 extended, 4 logical
37ba07eb
VS
135create_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
137list_parts part_msdos "${imgfile}" "${outfile}"
138check_output "${outfile}" $disk $disk,msdos1 $disk,msdos5 $disk,msdos6 $disk,msdos7 $disk,msdos8
56672f4a 139
140
141#
142# GPT partition types
143#
144
145echo "Checking GPT partition types..."
146
147# 0 parts
37ba07eb
VS
148create_disk_image "${imgfile}" 64
149${parted} -a none -s "${imgfile}" mklabel gpt
150list_parts part_gpt "${imgfile}" "${outfile}"
151check_output "${outfile}" $disk
56672f4a 152
153# 1 parts
37ba07eb
VS
154create_disk_image "${imgfile}" 64
155${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M
156list_parts part_gpt "${imgfile}" "${outfile}"
157check_output "${outfile}" $disk $disk,gpt1
56672f4a 158
159# 2 parts
37ba07eb
VS
160create_disk_image "${imgfile}" 128
161${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M
162list_parts part_gpt "${imgfile}" "${outfile}"
163check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2
56672f4a 164
165# 3 parts
37ba07eb
VS
166create_disk_image "${imgfile}" 128
167${parted} -a none -s "${imgfile}" mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M
168list_parts part_gpt "${imgfile}" "${outfile}"
169check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3
56672f4a 170
171# 4 parts
37ba07eb
VS
172create_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
174list_parts part_gpt "${imgfile}" "${outfile}"
175check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4
56672f4a 176
177# 5 parts
37ba07eb
VS
178create_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
180list_parts part_gpt "${imgfile}" "${outfile}"
181check_output "${outfile}" $disk $disk,gpt1 $disk,gpt2 $disk,gpt3 $disk,gpt4 $disk,gpt5
56672f4a 182
183# 6 parts
37ba07eb
VS
184create_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
186list_parts part_gpt "${imgfile}" "${outfile}"
187check_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
196echo "Checking SUN partition types..."
197
198# 0 parts
37ba07eb
VS
199create_disk_image "${imgfile}" 64
200${parted} -a none -s "${imgfile}" mklabel sun
201list_parts part_sun "${imgfile}" "${outfile}"
202check_output "${outfile}" $disk
56672f4a 203
204# 1 parts
37ba07eb
VS
205create_disk_image "${imgfile}" 64
206${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M
207list_parts part_sun "${imgfile}" "${outfile}"
208check_output "${outfile}" $disk $disk,sun1
56672f4a 209
210# 2 parts
37ba07eb
VS
211create_disk_image "${imgfile}" 128
212${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M
213list_parts part_sun "${imgfile}" "${outfile}"
214check_output "${outfile}" $disk $disk,sun1 $disk,sun2
56672f4a 215
216# 3 parts
37ba07eb
VS
217create_disk_image "${imgfile}" 128
218${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M
219list_parts part_sun "${imgfile}" "${outfile}"
220check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4
56672f4a 221
222# 4 parts
37ba07eb
VS
223create_disk_image "${imgfile}" 128
224${parted} -a none -s "${imgfile}" mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M
225list_parts part_sun "${imgfile}" "${outfile}"
226check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5
56672f4a 227
228# 5 parts
37ba07eb
VS
229create_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
231list_parts part_sun "${imgfile}" "${outfile}"
232check_output "${outfile}" $disk $disk,sun1 $disk,sun2 $disk,sun4 $disk,sun5 $disk,sun6
56672f4a 233
234# 6 parts
37ba07eb
VS
235create_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
237list_parts part_sun "${imgfile}" "${outfile}"
238check_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
249echo "Checking APPLE partition types..."
250
251# 0 parts
37ba07eb
VS
252create_disk_image "${imgfile}" 64
253${parted} -a none -s "${imgfile}" mklabel mac
254list_parts part_apple "${imgfile}" "${outfile}"
255check_output "${outfile}" $disk $disk,apple1 $disk,apple2
56672f4a 256
257# 1 parts
37ba07eb
VS
258create_disk_image "${imgfile}" 64
259${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M
260list_parts part_apple "${imgfile}" "${outfile}"
261check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3
56672f4a 262
263# 2 parts
37ba07eb
VS
264create_disk_image "${imgfile}" 128
265${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M
266list_parts part_apple "${imgfile}" "${outfile}"
267check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple3 $disk,apple4
56672f4a 268
269# 3 parts
37ba07eb
VS
270create_disk_image "${imgfile}" 128
271${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M
272list_parts part_apple "${imgfile}" "${outfile}"
273check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5
56672f4a 274
275# 4 parts
37ba07eb
VS
276create_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
278list_parts part_apple "${imgfile}" "${outfile}"
279check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6
56672f4a 280
281# 5 parts
37ba07eb
VS
282create_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
284list_parts part_apple "${imgfile}" "${outfile}"
285check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7
56672f4a 286
287# 6 parts
37ba07eb
VS
288create_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
290list_parts part_apple "${imgfile}" "${outfile}"
291check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8