partmap_test.in 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. parted=parted
  18. grubshell=@builddir@/grub-shell
  19. create_disk_image () {
  20. name=$1
  21. size=$2
  22. qemu-img create ${name} ${size} >/dev/null
  23. }
  24. check_output () {
  25. outfile=$1
  26. shift
  27. for disk in $@; do
  28. if ! grep "($disk)" ${outfile} >/dev/null
  29. then
  30. echo "($disk): disk/partiton not found"
  31. exit 1
  32. fi
  33. done
  34. }
  35. list_parts () {
  36. mod=$1;
  37. shift;
  38. imgfile=$1
  39. shift
  40. outfile=$1
  41. shift
  42. echo ls | ${grubshell} --boot=cd --qemu-opts="-hda ${imgfile}" \
  43. --modules=$mod | tr -d "\n\r" > ${outfile}
  44. cat ${outfile}
  45. echo
  46. }
  47. imgfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  48. outfile=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
  49. #
  50. # MSDOS partition types
  51. #
  52. echo "Checking MSDOS partition types..."
  53. # 0 primary
  54. create_disk_image ${imgfile} 64M
  55. ${parted} -a none -s ${imgfile} mklabel msdos
  56. list_parts part_msdos ${imgfile} ${outfile}
  57. check_output ${outfile} hd0
  58. # 1 primary
  59. create_disk_image ${imgfile} 64M
  60. ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M
  61. list_parts part_msdos ${imgfile} ${outfile}
  62. check_output ${outfile} hd0 hd0,msdos1
  63. # 2 primary
  64. create_disk_image ${imgfile} 128M
  65. ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M
  66. list_parts part_msdos ${imgfile} ${outfile}
  67. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2
  68. # 3 primary
  69. create_disk_image ${imgfile} 128M
  70. ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M
  71. list_parts part_msdos ${imgfile} ${outfile}
  72. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3
  73. # 4 primary
  74. create_disk_image ${imgfile} 128M
  75. ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart primary 20M 30M mkpart primary 30M 40M
  76. list_parts part_msdos ${imgfile} ${outfile}
  77. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos2 hd0,msdos3 hd0,msdos4
  78. # 1 primary, 1 extended
  79. create_disk_image ${imgfile} 128M
  80. ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100%
  81. list_parts part_msdos ${imgfile} ${outfile}
  82. check_output ${outfile} hd0 hd0,msdos1
  83. # 1 primary, 1 extended, 1 logical
  84. create_disk_image ${imgfile} 128M
  85. ${parted} -a none -s ${imgfile} mklabel msdos mkpart primary 0 10M mkpart primary 10M 20M mkpart extended 20M 100% mkpart logical 20M 30M
  86. list_parts part_msdos ${imgfile} ${outfile}
  87. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5
  88. # 1 primary, 1 extended, 2 logical
  89. create_disk_image ${imgfile} 128M
  90. ${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
  91. list_parts part_msdos ${imgfile} ${outfile}
  92. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6
  93. # 1 primary, 1 extended, 3 logical
  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% mkpart logical 20M 30M mkpart logical 30M 40M mkpart logical 40M 50M
  96. list_parts part_msdos ${imgfile} ${outfile}
  97. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7
  98. # 1 primary, 1 extended, 4 logical
  99. create_disk_image ${imgfile} 128M
  100. ${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
  101. list_parts part_msdos ${imgfile} ${outfile}
  102. check_output ${outfile} hd0 hd0,msdos1 hd0,msdos5 hd0,msdos6 hd0,msdos7 hd0,msdos8
  103. #
  104. # GPT partition types
  105. #
  106. echo "Checking GPT partition types..."
  107. # 0 parts
  108. create_disk_image ${imgfile} 64M
  109. ${parted} -a none -s ${imgfile} mklabel gpt
  110. list_parts part_gpt ${imgfile} ${outfile}
  111. check_output ${outfile} hd0
  112. # 1 parts
  113. create_disk_image ${imgfile} 64M
  114. ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M
  115. list_parts part_gpt ${imgfile} ${outfile}
  116. check_output ${outfile} hd0 hd0,gpt1
  117. # 2 parts
  118. create_disk_image ${imgfile} 128M
  119. ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M
  120. list_parts part_gpt ${imgfile} ${outfile}
  121. check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2
  122. # 3 parts
  123. create_disk_image ${imgfile} 128M
  124. ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 3 20M 30M
  125. list_parts part_gpt ${imgfile} ${outfile}
  126. check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3
  127. # 4 parts
  128. create_disk_image ${imgfile} 128M
  129. ${parted} -a none -s ${imgfile} mklabel gpt mkpart 1 0 10M mkpart 2 10M 20M mkpart 4 20M 30M mkpart 5 30M 40M
  130. list_parts part_gpt ${imgfile} ${outfile}
  131. check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4
  132. # 5 parts
  133. create_disk_image ${imgfile} 128M
  134. ${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
  135. list_parts part_gpt ${imgfile} ${outfile}
  136. check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5
  137. # 6 parts
  138. create_disk_image ${imgfile} 128M
  139. ${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
  140. list_parts part_gpt ${imgfile} ${outfile}
  141. check_output ${outfile} hd0 hd0,gpt1 hd0,gpt2 hd0,gpt3 hd0,gpt4 hd0,gpt5 hd0,gpt6
  142. #
  143. # SUN partition types
  144. #
  145. # It seems partition #3 is reserved for whole disk by parted.
  146. #
  147. echo "Checking SUN partition types..."
  148. # 0 parts
  149. create_disk_image ${imgfile} 64M
  150. ${parted} -a none -s ${imgfile} mklabel sun
  151. list_parts part_sun ${imgfile} ${outfile}
  152. check_output ${outfile} hd0
  153. # 1 parts
  154. create_disk_image ${imgfile} 64M
  155. ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M
  156. list_parts part_sun ${imgfile} ${outfile}
  157. check_output ${outfile} hd0 hd0,sun1
  158. # 2 parts
  159. create_disk_image ${imgfile} 128M
  160. ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M
  161. list_parts part_sun ${imgfile} ${outfile}
  162. check_output ${outfile} hd0 hd0,sun1 hd0,sun2
  163. # 3 parts
  164. create_disk_image ${imgfile} 128M
  165. ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M
  166. list_parts part_sun ${imgfile} ${outfile}
  167. check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4
  168. # 4 parts
  169. create_disk_image ${imgfile} 128M
  170. ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M
  171. list_parts part_sun ${imgfile} ${outfile}
  172. check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5
  173. # 5 parts
  174. create_disk_image ${imgfile} 128M
  175. ${parted} -a none -s ${imgfile} mklabel sun mkpart 0 10M mkpart 10M 20M mkpart 20M 30M mkpart 30M 40M mkpart 40M 50M
  176. list_parts part_sun ${imgfile} ${outfile}
  177. check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6
  178. # 6 parts
  179. create_disk_image ${imgfile} 128M
  180. ${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
  181. list_parts part_sun ${imgfile} ${outfile}
  182. check_output ${outfile} hd0 hd0,sun1 hd0,sun2 hd0,sun4 hd0,sun5 hd0,sun6 hd0,sun7
  183. #
  184. # Apple partition types
  185. #
  186. # Partition table itself is part of some partition, so there is always
  187. # a partition by default. But I don't understand why GRUB displays
  188. # two partitions by default :-(
  189. #
  190. echo "Checking APPLE partition types..."
  191. # 0 parts
  192. create_disk_image ${imgfile} 64M
  193. ${parted} -a none -s ${imgfile} mklabel mac
  194. list_parts part_apple ${imgfile} ${outfile}
  195. check_output ${outfile} hd0 hd0,apple1 hd0,apple2
  196. # 1 parts
  197. create_disk_image ${imgfile} 64M
  198. ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M
  199. list_parts part_apple ${imgfile} ${outfile}
  200. check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3
  201. # 2 parts
  202. create_disk_image ${imgfile} 128M
  203. ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M
  204. list_parts part_apple ${imgfile} ${outfile}
  205. check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple3 hd0,apple4
  206. # 3 parts
  207. create_disk_image ${imgfile} 128M
  208. ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M
  209. list_parts part_apple ${imgfile} ${outfile}
  210. check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5
  211. # 4 parts
  212. create_disk_image ${imgfile} 128M
  213. ${parted} -a none -s ${imgfile} mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M
  214. list_parts part_apple ${imgfile} ${outfile}
  215. check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6
  216. # 5 parts
  217. create_disk_image ${imgfile} 128M
  218. ${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
  219. list_parts part_apple ${imgfile} ${outfile}
  220. check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7
  221. # 6 parts
  222. create_disk_image ${imgfile} 128M
  223. ${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
  224. list_parts part_apple ${imgfile} ${outfile}
  225. check_output ${outfile} hd0 hd0,apple1 hd0,apple2 hd0,apple4 hd0,apple5 hd0,apple6 hd0,apple7 hd0,apple8