|
67 | 67 | my $part_size_mb = 512;
|
68 | 68 | my $part_size_sectors = 1024 * 1024 * $part_size_mb / 512;
|
69 | 69 |
|
| 70 | +my $expand_target_size_mb = 800; |
| 71 | +my $shrink_target_size_mb = 260; |
| 72 | + |
70 | 73 | # Create the handle.
|
71 | 74 | my $g = Sys::Guestfs->new ();
|
72 | 75 | my $backend = $g->get_backend ();
|
|
258 | 261 | # do nothing - it's the extended partition
|
259 | 262 | } elsif ($content eq "lvm") {
|
260 | 263 | $g->pvcreate ($dev);
|
261 |
| - # If shrinking, shrink the PV to < 260MB. |
| 264 | + # If shrinking, shrink the PV to < shrink size. |
262 | 265 | if (!$expand) {
|
263 |
| - $g->pvresize_size ($dev, 256 * 1024 * 1024); |
| 266 | + $g->pvresize_size ($dev, ($shrink_target_size_mb-4) * 1024 * 1024); |
264 | 267 | }
|
265 | 268 | } else {
|
266 | 269 | $g->mkfs ($content, $dev);
|
267 |
| - # If shrinking, shrink the filesystem to < 260MB. |
| 270 | + # If shrinking, shrink the filesystem to < shrink size. |
268 | 271 | if (!$expand) {
|
269 | 272 | if ($content eq "ext2") {
|
270 |
| - $g->resize2fs_size ($dev, 256 * 1024 * 1024); |
| 273 | + $g->resize2fs_size ($dev, |
| 274 | + ($shrink_target_size_mb-4) * 1024 * 1024); |
271 | 275 | } elsif ($content eq "btrfs") {
|
272 | 276 | $g->mount ($dev, "/");
|
273 |
| - $g->btrfs_filesystem_resize ("/", size => 256 * 1024 * 1024); |
| 277 | + $g->btrfs_filesystem_resize |
| 278 | + ("/", |
| 279 | + size => ($shrink_target_size_mb-4) * 1024 * 1024); |
274 | 280 | $g->umount_all ();
|
275 | 281 | } elsif ($content eq "ntfs") {
|
276 |
| - $g->ntfsresize ($dev, size => 256 * 1024 * 1024); |
| 282 | + $g->ntfsresize |
| 283 | + ($dev, |
| 284 | + size => ($shrink_target_size_mb-4) * 1024 * 1024); |
277 | 285 | } else {
|
278 | 286 | die "internal error: content = $content";
|
279 | 287 | }
|
|
299 | 307 | for ($i = 1; $i <= $nr_parts; ++$i) {
|
300 | 308 | if ($parts[$i]->{resize} || $parts[$i]->{expand_shrink}) {
|
301 | 309 | if ($expand) {
|
302 |
| - $target_size += 800; |
| 310 | + $target_size += $expand_target_size_mb; |
303 | 311 | } else {
|
304 |
| - $target_size += 260; |
| 312 | + $target_size += $shrink_target_size_mb; |
305 | 313 | }
|
306 | 314 | } else {
|
307 | 315 | $target_size += $part_size_mb; # remain at original size
|
|
0 commit comments