Skip to content

Commit 482476a

Browse files
authored
Image Customizer: Set VHDX block-size to 2 MiB. (#10880)
Currently, the size of outputted VHDX files can be substantially larger than VHD or qcow2 files. This behavior occurs because `qemu-img` dynamically sets the block-size based on the size of the disk. And larger blocks sizes means the file format is less space efficient, which results in a larger image file. This change sets the block-size to 2 MiB for VHDX files. This matches the `qemu-img` defaults for VHD and QCOW2. For reference, Windows seems to use a default block-size of 1 MiB for VHDX files.
1 parent 1dcc313 commit 482476a

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

toolkit/tools/pkg/imagecustomizerlib/imagecustomizer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,12 @@ func toQemuImageFormat(imageFormat string) (string, string) {
466466
case ImageFormatVhdFixed:
467467
return QemuFormatVpc, "subformat=fixed,force_size"
468468

469+
case ImageFormatVhdx:
470+
// For VHDX, qemu-img dynamically picks the block-size based on the size of the disk.
471+
// However, this can result in a significantly larger file size than other formats.
472+
// So, use a fixed block-size of 2 MiB to match the block-sizes used for qcow2 and VHD.
473+
return ImageFormatVhdx, "block_size=2097152"
474+
469475
default:
470476
return imageFormat, ""
471477
}

0 commit comments

Comments
 (0)