How to copy a virtual drive

I saw a few of the related topics but none really answered my question. Here's the issue: I have a Windows Server 2012 virtual machine Hyper-V with Microsoft Exchange installed on it. Long story short, I made the boot drive way too large, and it won't let me compact it now.  It also has a data drive for the mailbox database.  What I'd like to do is just copy the contents of the original boot drive into a second much smaller boot drive, connect this VM to the new boot drive, and then delete the old drive.

What's the best way to do this?&

September 30th, 2014 6:29pm

In a Server 2012 R2 VM, here are the steps (no copying is needed):

  1. In the VM, in computer Management/Disk Management, right-click on drive c: and Shrink volume: 
  2. In Hyper-V Manager Edit the vDisk and Shrink the Volume: 

If this is a Gen 2 VM, no need to down the machine to shrink or expand boot/system disk. This is due to the fact that it is on a SCSI controller. 

If this is a Gen 1 VM (Boot/system disk on IDE controller), you'll need to down the VM after you shrink the disk in the VM, and before you can shrink it in the Host.

Free Windows Admin Tool Kit Click here and download it now
September 30th, 2014 6:38pm

First off, the GUI you posted is for Windows Server 2008.  This server is 2012 and Disk Management is run through Server Manager on a different GUI.

Second, there is no option to Shrink the drive in Disk Management.  Only to Extend.

Furthermore, when I try to Compact the .vhd in Hyper-V, it spits out an error.  A rather nasty one which tends to crash all of Hyper-V.

Which leads me to think the best option is to just create a new .vhd, copy the contents onto it, and boot the machine with the new boot .vhd.

September 30th, 2014 6:49pm

In fact, now that I look at it, nowhere do I see an option to Shrink - only Compact, Convert, and Expand.  Does the .vhd have to be formatted in a certain way to allow a Shrink option? 
Free Windows Admin Tool Kit Click here and download it now
September 30th, 2014 6:54pm

First off, the GUI you posted is for Windows Server 2008.  This server is 2012 and Disk Management is run through Server Manager on a different GUI.

The images posted are from a 2012 R2 VM.

In 2012 R2 Server Manager, click Tools\Computer Management to get to Computer Management GUI:

Second, there is no option to Shrink the drive in Disk Management.  Only to Extend.

In 2012 R2 there is - see screen shot in my first post. If that option is not available in Server 2012, you can either upgrade to 2012 R2, or use 3rd party tools to either shrink the disk in the VM, or do an offline disk clone with resize.

Furthermore, when I try to Compact the .vhd in Hyper-V, it spits out an error.  A rather nasty one which tends to crash all of Hyper-V.

Shrink and Compact are 2 different things. Compact is a process that applies to dynamically expanding disks only, and reclaims disk space occupied by the VHD(x) file that has been deleted inside the VHD(x). Compact must be done on offline disks, not ones that are being actively used by Hyper-V. Compact is not what you want here.

Shrink is a process that reduces the size of a VHD(x) file. In a fixed VHD(x) file you'll see the size reduction on the Hyper-V host. In a dynamic VHD(x) file the actual file size will remain the same, but the size seen by the VM will show the new reduced size. This is what you should be doing. If the guest OS (VM) has a partition on that VHDX that's taking all the space presented by the hyper-V host, the "Shrink" option won't be there. Hence, you must shrink in the guest OS first, then go out to the host and shrink it there as well.

Here's an example of a Gen2 2012 R2 VM that I've shrunk its boot/system disk in the VM and on the host - with no down time:

The Shrink Process has nothing to do with how the disk is formatted in the guest OS. All it needs is free space (in 1 GB increments) on the VHDX file.

 

September 30th, 2014 7:28pm

Oh okay thanks.  Well, I was able to shrink the drive within the OS, but when I go to Edit the .vhd file, the shrink option still doesn't exist.  Let me fiddle around with it a bit more and see what I can come up with.  I may need some advice with a decent third party tool to shrink the .vhd.

Also though I was able to shrink the drive within the OS, it would only let me shrink to 500GB even though the drive had less than 100GB of data on it.  I've had this problem before.

Free Windows Admin Tool Kit Click here and download it now
September 30th, 2014 10:49pm

Yeah I'm not seeing a "shrink" option in any of my Hyper-V instances.  I have one running on Windows Server 2012 and two running on Windows Server 2008 R2. 
October 7th, 2014 1:00am

For Hyper-V support, you should really be using the Hyper-V forums: http://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverhyperv

this forum is for Virtual Server 2005, which is in no way related to Hyper-V.

Free Windows Admin Tool Kit Click here and download it now
October 7th, 2014 2:55am

Great thanks!  I couldn't navigate to that topic from the root forum, so I just figured this was the next best place to ask.
October 7th, 2014 7:06pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics