~hamo/ubuntu/precise/grub2/grub2.hi_res

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#! /bin/sh -e
#
# Copyright (C) 2010  Free Software Foundation, Inc.
#
# GRUB is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GRUB is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GRUB.  If not, see <http://www.gnu.org/licenses/>.

parted=parted
grubshell=@builddir@/grub-shell

create_disk_image () {
    name=$1
    size=$2
    qemu-img create ${name} ${size} >/dev/null
}

check_output () {
    outfile=$1
    shift

    for disk in $@; do
	if ! grep "($disk)" ${outfile} >/dev/null
	then
	    echo "($disk): disk/partiton not found"
	    exit 1
	fi
    done
}

list_parts () {
    mod=$1;
    shift;
    imgfile=$1
    shift
    outfile=$1
    shift

    echo ls | ${grubshell} --boot=cd --qemu-opts="-hda ${imgfile}" \
	--modules=$mod | tr -d "\n\r" > ${outfile}
    cat ${outfile}
    echo
}

imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
outfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1

#
# MSDOS partition types
#

echo "Checking MSDOS partition types..."

# 0 primary
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel msdos
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0

# 1 primary
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M 
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1

# 2 primary
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2

# 3 primary
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3

# 4 primary
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3 hd0,msdos4

# 1 primary, 1 extended
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100%
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1

# 1 primary, 1 extended, 1 logical
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5

# 1 primary, 1 extended, 2 logical
create_disk_image ${imgfile} 128M
${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
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6

# 1 primary, 1 extended, 3 logical
create_disk_image ${imgfile} 128M
${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
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7

# 1 primary, 1 extended, 4 logical
create_disk_image ${imgfile} 128M
${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
list_parts part_msdos ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7 hd0,msdos8


#
# GPT partition types
#

echo "Checking GPT partition types..."

# 0 parts
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel gpt
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0

# 1 parts
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M 
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,gpt1

# 2 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2

# 3 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3

# 4 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 4 20M 30M mkpart 5 30M 40M
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4

# 5 parts
create_disk_image ${imgfile} 128M
${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
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5

# 6 parts
create_disk_image ${imgfile} 128M
${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
list_parts part_gpt ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5 hd0,gpt6


#
# SUN partition types
#
# It seems partition #3 is reserved for whole disk by parted.
#

echo "Checking SUN partition types..."

# 0 parts
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel sun
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0

# 1 parts
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M 
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,sun1

# 2 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,sun1 hd0,sun2

# 3 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4

# 4 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5

# 5 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6

# 6 parts
create_disk_image ${imgfile} 128M
${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
list_parts part_sun ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6 hd0,sun7


#
# Apple partition types
#
# Partition table itself is part of some partition, so there is always
# a partition by default.  But I don't understand why GRUB displays
# two partitions by default :-(
#

echo "Checking APPLE partition types..."

# 0 parts
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel mac
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2

# 1 parts
create_disk_image ${imgfile} 64M
${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3

# 2 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3 hd0,apple4

# 3 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5

# 4 parts
create_disk_image ${imgfile} 128M
${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6

# 5 parts
create_disk_image ${imgfile} 128M
${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
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7

# 6 parts
create_disk_image ${imgfile} 128M
${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
list_parts part_apple ${imgfile} ${outfile}
check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7 hd0,apple8