Shrinking the C: System VHD disk in Azure IaaS
Today I have been working with Azure and the disk size. In our lab environment we started out when the Azure Iaas role was still in preview and it had a limit that not until now have appeared as a problem. The system VHD in the preview version was only 30 GB and now when the c:\windows\winSxS folder has grown with patches and install files to about 14 GB the volume is beyond full :-/ and yes the SQL service running on the server is installed on another partition..
And as you can read on this blog post it is not an option to try to remove the files inside the winSxS folder!
The different options on how to do an resize of an disk in an Azure Iaas VM when doing a search is quite cumbersome but I found this guy Maarten Balliauw that made a console app that can fix the stuff and this without installing new VM´s or downloading the VHD.
Now to test how to do it I created a new VM and this get a OS disk with 127 GB and I wanted it to be 30 GB so I had to shrink it. The binary that Maarten have does not include the latest addition with the shrink option, so I asked my colleague to compile it for me as I do not have Visual Studio installed (at least not yet), Thank you Tim!
UPDATE -> Download Tims compiled binary here : shrinkAzure
So to do a shrink with the latest source and a friend with a compiler.
- Shrink the partition with powershell or disk management tool (if you do not the OS partition will be corrupt if shrink the vhd beyond this)
- Shutdown the VM
- Delete the VM -or- detach the disk if it’s not the OS disk
- Delete the cloud service if you have created it to be able to create a new with the same name
- In the Windows Azure portal, delete the disk (retain the data!) do that the lease Windows Azure has on it is removed
- Run WindowsAzureDiskResizer
- In the Windows Azure portal, recreate the disk based on the existing blob
- Recreate the VM -or- reattach the disk if it’s not the OS disk
- Start the VM
So I start shrinking the volume inside the Azure VM. As you might notice I have shrink it to just below 30 GB (30GB -1MB)
And then I have a volume that looks like this in the disk manager
Next step is to delete the VM and also the delete the disk (retain data) and as Maarten says I can then use his tool, if I do not delete the disk from the Iaas it will fail. And here I enter 30 GB disk size, and if I would not have done the volume just 1 MB below 30GB I get a corrupt OS volume, the tool does not check the volumes inside the VHD..
Of course I could have done a VHD size of 31 GB but this was just for testing and seeing what happens.. I did also remove the Cloud Service so that I could use that name after I was done to get the old url to the new VM.
Now it is time to re-create the virtual disk and then the virtual machine..
And then when I started the virtual machine and connect to it, the size of the disk is 30 GB
I am looking forward to the day that Azure runs on Windows 2012 R2 Hyper-V and the VM´s in the Iaas role can be configured with Gen2 and you can change the vhdx size on the fly when the VM is running 🙂