Resize partitions in a virtual drive?

seedubya

Well-Known Member
Reaction score
1,019
Location
Carlow, Ireland
Host is running Server 2012R2 Standard. It has a volume, E:\, 2.54TB in size that stores a single virtual hard drive file.

The virtual hard drive is a VHDX file with 2 partitions, C and D. The C:\ partition is 905GB with only 86GB used and the D is 1.08 TB with 726 GB used. This was originally created from a physical machine. See screenshot below.

upload_2016-9-26_21-34-9.png

I need to:
  1. Shrink C: to, say 150GB.
  2. Move D:\ around in the resulting free space to be directly after C:|
  3. Increase the size of the virtual hard drive file to the max available on the drive
  4. Grow D:\ to fill the resulting space.
I'm getting stuck on Step 1. When I try to shrink the C:\ partition from inside the VM first it tells me that it can only be shrunk down to 470GB.

upload_2016-9-26_21-41-39.png

Anyone care to opine on what the "unmoveable files" are \ might be and if there's anything I can do about it?



If I then proceed it tells me it doesn't have enough free space to complete the operation


upload_2016-9-26_21-44-13.png


Can anybody suggest how to proceed from here? I'd be very grateful.

I suspect that I may have to increase the actual VHDX file size to the total of the two partitions or greater, to begin with but I'd like to hear from someone who has more than my suspicions!
 
Anyone care to opine on what the "unmoveable files" are \ might be and if there's anything I can do about it?
You need to optimize/defrag the drive first.

Personally, I would clone those partitions into separate virtual drives first, for greater flexibility. Then I'd do any necessary drive shrinking using Diskpart. I find shrinking rarely works from the GUI.

This is how I usually do it:
  • Mount the the VHD/VHDX in the host OS and defrag (optimize) it.
  • Run Diskpart from an elevated Command Prompt
In Diskpart:
  • select vdisk File="X:\Path-to-VHDs\VHD-to-compact.vhdx"
  • attach vdisk readonly
  • compact vdisk
  • detach vdisk

According to my notes, if this doesn't work first time, stay in Diskpart and repeat the commands but leave out the 'attach vdisk readonly' command the second time.
 
@MichaelEC Thanks Michael. Unfortunately that's non-commercial use only and, anyway, it won't work on server OSes

Muchas Gracias, @AndyM

@Moltuae thanks a mil for that. Is there a real need to clone the drives to new VHDX files? The reason I ask is that maintenance windows are scarce and short! Any step in the process that doesn't have to be done is good.

Next question ....

How will compacting the VHDx shrink the actual partition? I know it's not a "real" partition but the OS on there thinks it is!!
 
Last edited:
Is there a real need to clone the drives to new VHDX files? The reason I ask is that maintenance windows are scarce and short! Any step in the process that doesn't have to be done is good.

Next question ....

How will compacting the VHDx shrink the actual partition? I know it's not a "real" partition but the OS on there thinks it is!!
Sorry, I think I must've been suffering from a lack of caffeine when I replied earlier. Compacting the VHDx will do nothing to help shrink the partition; I think I must've been thinking of a job I was doing earlier this week. The optimize/defrag still applies when shrinking in the OS though; you need to move the data either way.

As for cloning the partitions to new VHDx files: Well, no, not strictly necessary it just gives more flexibility. For example, it allows you to store the virtual drives on different physical drives for better performance, it can make back-ups simpler (eg all VHDs containing data on one physical drive) and in some cases it can simplify DR if, for example, you need to quickly attach a data VHD to a different VM. With those reasons in mind, and the fact you need to resize/move partitions anyway, I think I'd probably go down the cloning route. Also, while it may take slightly longer to perform than resizing partitions, since you're just cloning, you can always revert back if things go wrong or you run out of time.

Oh, and you may also want to compact the new VHDx files afterwards, in which case my post above may actually become relevant ;)
 
Last edited:
Since Server 2k8 (and Vista for desktops)....Microsoft introduced partition resizing via the GUI...in disk manglement. Simple right clicks brought up options to resize.

However...as you noticed...it doesn't work well on system volumes. Pagefile.sys is one offender...but even if you move that, even if you defrag the volume, it's still....well...it still stucks on the system volume.

So yup you gotta turn to 3rd party tools for the system volume.....pick your favorite vendor...Paragon, Easeus, Acronis, etc. Yup their "server grade" packages are pricey.
 
A quick update, I took it down last night, copied the first VHDx just in case, attached it on the host, optimised it and resized.. We purchased a licence for Paragon for them, which we use ourselves in-house. After resizing I had to run a BCD repair as it wouldn't boot but after that it was 100% perfect.

Will start moving shares onto the newly enlarged data partition over the weekend.
 
Back
Top