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)

Screen Shot 2013-08-21 at 14.42.25

And then I have a volume that looks like this in the disk manager

Screen Shot 2013-08-21 at 14.43.05

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.

Screen Shot 2013-08-21 at 14.52.50

Now it is time to re-create the virtual disk and then the virtual machine..

Screen Shot 2013-08-21 at 14.54.07

And then when I started the virtual machine and connect to it, the size of the disk is 30 GB

Screen Shot 2013-08-21 at 15.05.58

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 🙂



Hey Niklas
great article but cant compile too in visual studio.
are you willing sharing the binaries?


@Nikos Hi Nikos, I have updated the blog post with the binary!


thanks Niklas for your upload. its extremely too difficult for a non developer as me to compile a few lines of code.
That’s the power of community SHARING.

please sorry and ignore my previews comment.

Neil Mackenzie

Why shrink the disk?

With Windows Azure Disks you are billed only for the occupied space on the disk. A recent Windows Azure enhancement introduced the TRIM capability which means that when you delete a file on the VHD the space backing it is reclaimed by the Storage System so that you are no longer billed for it. This is a Windows Server 2012 feature. This post by Mike Wood describes what is going on:


Well if you read, the reason was because I wanted to test to expand a disk and as the new was already 127 GB I wanted to shrink it first and then expand.. 🙂 the preview iaas win 2012 templates was 30 GB large and with some patches and updates that is to small!


Hi Niklas, I was wondering, this tool probably doesn’t work with the new ARM format of storages, does it? When I try to shrink my VHD, I get an error:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly ‘Microsoft.WindowsAzure.Storage, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.
at WindowsAzureDiskResizer.Program.ResizeVhdBlob(Int64 newSize, Uri blobUri, String accountName, String accountKey)
at WindowsAzureDiskResizer.Program.Main(String[] args)

I’m not a .NET developer so I don’t know… but it looks like that new storages come from different class than Microsoft.WindowsAzure.Storage or whatever.

On the other hand, I don’t get this error with the original WindowsAzureDiskResizer tool – there I can only see that VHD cannot be shrinked, only expanded.

Thanks in advance for an answer,

Leave a comment


email* (not published)