Thanks to this article – how to create a Windows Image for OpenStack Glance repository. After uploading the image, I created a separate flavor for Windows VMs with 2 vCPUs, 4GB RAM, and 40GB disk. However, when the Windows VM is booted, I noticed the hard disk space of 20GB, instead of 40GB! Also, the
Disk Management showed 20GB as unallocated. Your tutorial on how to Increase the virtual disk size of a Windows 10 VM on QEMU-KVM solves the issue. But can this be automated? So whenever the flavor is selected, it should automatically extend Windows virtual disk size to fit the disk size of the flavor. – Sahana.
Automatically extend Windows virtual disk size
As explained in my earlier articles, we use Cloudbase Solution’s Cloudbase-Init to configure the system for use in a cloud environment. Cloudbase-Init has the ability to execute user-provided scripts, usually found in the default path
C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\LocalScripts, through a specific plugin for doing it. Depending on the platform used, the files should be valid PowerShell, Python, Batch, or Bash scripts.
Extend a volume by using PowerShell
After the VM is prepared the last thing to be done is to create PowerShell scripts and place them in the Cloudbase-init default path for executing LocalScripts. These scripts run at every boot. So in case if you resize the VM, it should automatically consider extending the disk size.
Step 1: Open the notepad with the administrator privilege. Copy and paste the below script into it.
# Variable specifying the drive you want to extend $drive_letter = "C" # Script to get the partition sizes and then resize the volume $size = (Get-PartitionSupportedSize -DriveLetter $drive_letter) Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax
Save the file as
volumeExtend.ps1 into the path:
C:\Program Files (x86)\Cloudbase Solutions\Cloudbase-Init\LocalScripts
Step 2: You can follow the guide Increase the virtual disk size of the Windows 10 VM on QEMU-KVM to delete the Windows Recovery Partition.
Step 3: Gracefully shut down the VM and copy it to your OpenStack cloud.
Step 4: Boot your Windows VM and check the disk size to see if it has taken the complete size of your flavor.