Skip to content

Commit b8c08dc

Browse files
committed
resize/test-virt-resize.pl: Fix calculation of target disk
We didn't calculate the size of the target disk correctly. If a partition is resized then we pass the parameter --resize=(+|-)256M to virt-resize, but the target disk calculation chose an unrelated value. Example failure: seed: 3834767396 partition type: mbr nr partitions: 3 partition size: 1024M (2097152 sectors) expand: 0 no extra part: 0 source format: raw target format: raw filesystem: ext2 LV expand: partition 1: sda1 ext2 resize partition 2: sda2 ext2 - partition 3: sda3 ext2 shrink virt-resize --format raw --output-format raw --resize /dev/sda1=-256M --shrink /dev/sda3 test-virt-resize-source.img test-virt-resize-target.img [ 0.0] Examining test-virt-resize-source.img virt-resize: error: /dev/sda3: This partition contains a ext2 filesystem which will be damaged by shrinking it below 406016000 bytes (user asked to shrink it to 41648128 bytes). If you want to shrink this partition, you need to use the ‘--resize-force’ option, but that could destroy any data on this partition. (This error came from ‘--shrink’ option on the command line.) If reporting bugs, run virt-resize with debugging enabled and include the complete output: virt-resize -v -x [...] command: 'virt-resize --format raw --output-format raw --resize /dev/sda1=-256M --shrink /dev/sda3 test-virt-resize-source.img test-virt-resize-target.img' failed: 256 FAIL test-virt-resize.pl (exit status: 2)
1 parent d85a2af commit b8c08dc

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

resize/test-virt-resize.pl

+7-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,13 @@
305305
# will be resized.
306306
my $target_size = 0;
307307
for ($i = 1; $i <= $nr_parts; ++$i) {
308-
if ($parts[$i]->{resize} || $parts[$i]->{expand_shrink}) {
308+
if ($parts[$i]->{resize}) {
309+
if ($expand) {
310+
$target_size += $part_size_mb + 256;
311+
} else {
312+
$target_size += $part_size_mb - 256;
313+
}
314+
} elsif ($parts[$i]->{expand_shrink}) {
309315
if ($expand) {
310316
$target_size += $expand_target_size_mb;
311317
} else {

0 commit comments

Comments
 (0)