Increase disk size for build and then shrink image
Currently, not all updates are installed due to insufficient disk size during build. Just increasing the disk size would result in a larger image, which is not great.
So we need to increase the disk during the build, and then shrink the image according to the used space.
@111653 prepared a script to shrink the filesystem:
# Get information about the system drive
$systemDrive = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -eq 'C' }
# Get the used space on the system drive
$usedSpaceGB = [math]::Round($systemDrive.Used / 1GB, 2)
# Add 2 GB to the used space
$updatedSizeGB = $usedSpaceGB + 2
# Convert Variable
$updatedSizeBytes = $updatedSizeGB * 1GB
# Resize the system partition with the updated size
Resize-Partition -DriveLetter 'C' -Size $updatedSizeBytes
Then once the image is created it can be shrinked with:
qemu-img resize created-image "${UPDATED_SIZE_GB}G"
TODO:
-
Fix the powershell script -
Figure out how to propagate $updatedSizeGB
to packer/build environment -
Call shrink command when image build is complete
Edited by Zdeněk Vydra