|
63 | 63 |
|
64 | 64 | $| = 1; |
65 | 65 |
|
| 66 | +# The size of each partition, in MB and sectors. |
| 67 | +my $part_size_mb = 512; |
| 68 | +my $part_size_sectors = 1024 * 1024 * $part_size_mb / 512; |
| 69 | + |
| 70 | +# Create the handle. |
66 | 71 | my $g = Sys::Guestfs->new (); |
67 | 72 | my $backend = $g->get_backend (); |
68 | 73 |
|
|
106 | 111 | print "seed: $seed\n"; |
107 | 112 | print "partition type: $part_type\n"; |
108 | 113 | print "nr partitions: $nr_parts\n"; |
| 114 | +print "partition size: ${part_size_mb}M ($part_size_sectors sectors)\n"; |
109 | 115 | print "expand: $expand\n"; |
110 | 116 | print "no extra part: $no_extra_partition\n"; |
111 | 117 | print "source format: $source_format\n"; |
|
150 | 156 | # Size of the source disk. It's always roughly nr_parts * size of |
151 | 157 | # each partition + a bit extra. For btrfs we have to choose a large |
152 | 158 | # partition size. |
153 | | -my $source_size = (10 + $nr_parts * 512) * 1024 * 1024; |
| 159 | +my $source_size = (10 + $nr_parts * $part_size_mb) * 1024 * 1024; |
154 | 160 |
|
155 | 161 | # Create the source disk. |
156 | 162 | my $source_file = "test-virt-resize-source.img"; |
|
214 | 220 |
|
215 | 221 | if ($part_type eq "gpt") { |
216 | 222 | for (my $i = 1; $i <= $nr_parts; ++$i) { |
217 | | - my $end = $start + 1024*1024 - 1; |
| 223 | + my $end = $start + $part_size_sectors - 1; |
218 | 224 | $g->part_add ("/dev/sda", "primary", $start, $end); |
219 | 225 | $start = $end+1; |
220 | 226 | } |
221 | 227 | } else { |
222 | 228 | # MBR is nuts ... |
223 | 229 | for ($i = 1; $i <= $nr_parts; ++$i) { |
224 | 230 | if ($i <= 3) { |
225 | | - my $end = $start + 1024*1024 - 1; |
| 231 | + my $end = $start + $part_size_sectors - 1; |
226 | 232 | $g->part_add ("/dev/sda", "primary", $start, $end); |
227 | 233 | $start = $end+1; |
228 | 234 | } |
|
237 | 243 | # confusing thing about them is we have to take into |
238 | 244 | # account the sector that contains the linked list of |
239 | 245 | # logical partitions, hence -2/+2 below. |
240 | | - my $end = $start + 1024*1024 - 2; |
| 246 | + my $end = $start + $part_size_sectors - 2; |
241 | 247 | $g->part_add ("/dev/sda", "logical", $start, $end); |
242 | 248 | $start = $end+2; |
243 | 249 | } |
|
298 | 304 | $target_size += 260; |
299 | 305 | } |
300 | 306 | } else { |
301 | | - $target_size += 512; # remain at original size |
| 307 | + $target_size += $part_size_mb; # remain at original size |
302 | 308 | } |
303 | 309 | } |
304 | 310 | $target_size += 10; |
|
0 commit comments