none
Hyper-V Disk Size Reduction

    Question

  • I orginally created my virutal disks much to large for what I am using each virutal machine for.

    I would like to reduce the size of the disks and at the same time make them fixed instead of dynamic. I see the utility to convert them from dynamic to fixed..... but I dont see how to reduce the size.

    Is this possible without blowing off the entire partition and starting over?

    Thank you,

    JITS

    JITS
    Wednesday, June 25, 2008 12:25 AM

Answers

All replies

  • Download VHD resizer and you can resize your disks: http://vmtoolkit.com/blogs/announcements/archive/2007/02/28/vhd-expander-is-now-vhd-resizer.aspx
    Technet Forums Moderator | Solution Specialist | Ask The Experts IT-forum
    • Marked as answer by Chang Yin Friday, June 27, 2008 2:13 AM
    Wednesday, June 25, 2008 7:55 AM
  • Some people posted that they had trouble shrinking a vhd with the VHD Resizer.

    There is another way to resize a vhd. Disk imaging utilities such as Acronis and Ghost can accomplish the task. See my article at http://www.vmcentral.com/home/case-studies/solving-virtual-machine-maintenance-problems-with-disk-imaging-by-john-paul-cook
    Wednesday, June 25, 2008 12:49 PM
  • Thank you for the responses all....

    I tried the VhdResizer because it seemed quick and easy. Only problem is the minimum size is 100GB. I am trying to go from 100GB to 75GB and 50GB on certain VMs.

    I wonder why 100GB is the minimum?

    Thanks again,

    JITS

    JITS
    Wednesday, June 25, 2008 2:28 PM
  • Did you shrink the partition first?  VHDResizer will only shrink the VHD to the extent that there is unallocated (unpartitioned) space on the "disk".

    Martin
    Wednesday, June 25, 2008 7:05 PM
  • Can you specify exactly how you achieve this (resizing the partition) with standard MS tools?

    I have a problem where the P2V process wont allow me to make the target VHD files smaller than the size of the source disk even though it is mostly free space.  My thoughts were to use VHDResizer to shrink the resulting VHDs but I can't find an adequate how-to that includes all the steps.

    Cheers,
    Jeremy.
    Thursday, October 02, 2008 12:55 AM
  • I have the same problem too.  I P2V some servers and have a huge VHD size due to the initial size of the C: partition on the source server.  The actual data is usually 1/4 the size so it would be nice to easily shrink the vhd
    Thursday, October 02, 2008 12:59 PM
  • hi

    i just hit the same issue over here.
    i did P2V using SCVMM 2007 trial version, from IBM X336 server with physical disk size 33GB, single partition, to Hyper-V, dynamic disk. The disk usage is about 18GB includes the paging file.

    i've tried several possibilities to shrink the partition size into about 20 GB, without success.
    In summary :

    1. run defrag, then compact the disk, then run vhdresizer, but it only offers 0 KB to be shrink

    2.convert the disk into fixed disk, which expand the physical size into 33 GB, then run VHDresizer, it's till offers only 0 KB to be shrink

    3. attached the mentioned fixed disk above into win2k08 guest, under storage-> disk management, i tried to shrink the disk, also failed

    there is a thought to convert this Hyper-V guest to VMware with destination disk 20GB, then convert it back to hyper-V using SCVMM

    any advice pls?
    thank you, Rommel

    Monday, May 04, 2009 2:23 PM
  • You are asking how to change a vhd from say, 40 GB down to 20 GB. VHDResizer is only part of the answer.

    Try this, keeping in mind I've only done this on Windows Server 2008 R2 Beta so I don't know if this is a new feature in this version of Windows Server?

    1. Open the VM you want to change then go to Disk Managment
    2. Right click the volume to shrink and select "Shrink Volume"
    3. Choose how small you want to make the volume and click OK
    4. Shutdown the VM
    5. Run VHDResizer from the host/parent
    6. Now you should be able to reduce the size of the VHD (Note: a little bug in VHDResizer seems to be you cannot choose the smallest size possible, say 20 GB but instead must add to it - 21 GB works)

    Hope this helps!
    Boris

    • Proposed as answer by cravier Monday, July 05, 2010 9:33 AM
    Friday, May 08, 2009 8:42 PM
  • I have still not figured out how to make a VHD smaller. For instance I have a 100GB max size VHD sitting on a 20GB volume on our SAN. The VHD is currently about 1.7GB. When I use VHDresizer the minimum I can make the VHD is 100GB. Useless tool from my testing.
    Friday, September 04, 2009 6:03 PM
  • Here was my step-by-step - it still won't always shrink as much as you might like but you should get some savings:

    <!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman";} a:link, span.MsoHyperlink {mso-style-unhide:no; color:blue; text-decoration:underline; text-underline:single;} a:visited, span.MsoHyperlinkFollowed {mso-style-noshow:yes; mso-style-priority:99; color:purple; mso-themecolor:followedhyperlink; text-decoration:underline; text-underline:single;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; font-size:10.0pt; mso-ansi-font-size:10.0pt; mso-bidi-font-size:10.0pt;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1737438276; mso-list-type:hybrid; mso-list-template-ids:-1485914132 67698705 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-text:"%1\)"; mso-level-tab-stop:.5in; mso-level-number-position:left; text-indent:-.25in;} ol {margin-bottom:0in;} ul {margin-bottom:0in;} -->

    1)      Defrag and (if dynamic disk) compact (using Hyper-V MMC) the Disk/VHD

    2)      Copy VHD file to Server 2008 Hyper-V host system

    3)      Mount VHD file to host OS - one option is script here: http://blogs.msdn.com/virtual_pc_guy/archive/2008/02/01/mounting-a-virtual-hard-disk-with-hyper-v.aspx

    4)      Start Diskpart (command-line tool)

    5)      Execute list disk and note disk number (should be offline)

    6)      Execute select disk disknumber    (from previous step)

    7)      Execute online disk

    8)      Execute attributes disk clear readonly

    9)      Execute detail disk and note volume number (should only be one)

    10)  Execute select volume volumenumber (from previous step)

    11)  Execute shrink desired=amount_to_shrink_by (in MB; if will not shrink as much as desired, can use shrink querymax to determine how much can shrink)

    12)  Exit from diskpart

    13)    Unmount VHD from host OS (one option: http://blogs.msdn.com/virtual_pc_guy/archive/2008/02/01/mounting-a-virtual-hard-disk-with-hyper-v.aspx)

    14)  Copy file to Server 2003 or XP system

    15)  Decrease size of VHD file using VMToolkit VHD Resize (http://vmtoolkit.com/files/folders/converters/entry87.aspx ); can also convert to Fixed-size at the same time.

    16)  Copy VHD to desired/appropriate location

    • Proposed as answer by fruvio Saturday, April 07, 2012 1:57 PM
    Tuesday, September 08, 2009 1:43 PM
  • You are asking how to change a vhd from say, 40 GB down to 20 GB. VHDResizer is only part of the answer.

    Try this, keeping in mind I've only done this on Windows Server 2008 R2 Beta so I don't know if this is a new feature in this version of Windows Server?

    1. Open the VM you want to change then go to Disk Managment
    2. Right click the volume to shrink and select "Shrink Volume"
    3. Choose how small you want to make the volume and click OK
    4. Shutdown the VM
    5. Run VHDResizer from the host/parent
    6. Now you should be able to reduce the size of the VHD (Note: a little bug in VHDResizer seems to be you cannot choose the smallest size possible, say 20 GB but instead must add to it - 21 GB works)

    Hope this helps!
    Boris

    Problem

    Here is my inital problem on why I need to shrink my .VHD files. A 60GB volume was created and attached to my host server. We assign one volume per VM so every VM has it's on volume. The template used to create the VM has the C:\ drive as being 40GB and the D:\ drive as being 60 GB for 100 GB total. The disks are set to dynamic. If these disks were to grow to there max that would create a problem. What I want to do is shrink the VHD's to 30GB a piece for a max of 60Gb so it matches the volume it is on.

    Attempting a solution


    I'm using Server 2008 with Hyper-V enabled. I tried the method above to shrink my c:\ Drive .vhd file from 40GB to 30GB. I did the first 4 steps with no problems. I downloaded the VHD resizer program to my PC. I then mapped my PC to the server that my .VHD file was stored to. I browsed to the file which is a dynamic disk. Next you need to enter the name of the destination VHD. I wanted to keep the name the same as the old one. I have not read where you can't do this. I left the type as dynamic. I wanted a 30GB VHD so that is what I entered. I resized the disk and everything seemed fine. I started my VM from my SCVMM console and once I went to disk management I seen that the total size of the VHD was still 40GB. I still had 10GB as unallocated space. How do I erased the 10GB of unallocated space so that I have a 30GB VHD? Did I go wrong somewhere in the process? Thanks for any and all help!

    Pat

    • Edited by Pgrantland Thursday, April 29, 2010 1:10 PM Added detailed info
    Thursday, April 29, 2010 12:21 PM
  • Hi,

    try setting another vhd file name for the resize process (you could rename it after all is done).

    Make sure you select the new VHD in Hyper-V manager (find the old one and select "browse..." to point at the resized VHD).

     

    It works for me (reducing a 130 GB dynamic VHD with 30 GB used to a 40 GB one)

     

    Chris


    Christophe Ravier - .Net Architect
    Monday, July 05, 2010 9:47 AM
  • After changing my entire production environment I'm now able to fill in more complete details on my original post...

    How to shrink a VHD in Microsoft Hyper-V

    (VHDResizer, a free third party software, is only part of the answer)

     

    This will only work on Windows Server 2008 or newer operating systems. Windows Server 2003 R2 and older systems don't have the "Shrink" option under disk management and third party partition software will likely be necessary - such as Acronis or Partition Magic.

     

    1.       Defragment the hard drive. This step is needed if you want to "shrink" the size of the hard drive by more than 50%. Windows won't shrink more than 50% because of unmovable system files placed halfway on Windows volumes. Use a defragmenter that moves system files - the built in Windows defragmenter won't do this. Not all free/cheap defragmenters will work. Perfect Disk Defragmenter is a known solution because it will move Windows system files with its Boot Time defrag option. A free trial version is offered or ~$100 purchase.

    2.       Open the VM you want to change then go to Disk Management

    3.       Right click the volume to shrink and select "Shrink Volume"

    4.       Choose how small you want to make the volume and click OK

    5.       Shutdown the VM

    6.       Delete/Merge any Hyper-V snapshots prior to starting (you must shut down the virtual server for Hyper-V to complete the merging process)

    7.       Run VHDResizer (free third party software download) from the host/parent (Note: a little bug in VHDResizer seems to be you cannot choose the smallest size possible, say 20 GB but instead must add to it - 21 GB works) VHDResizer will make a copy of your current VHD so you can always go back to the original in case of disaster.

    8.       VHDResizer cannot use the same file name. You must choose a different file name.

    9.       Use the Hyper-V Manager to change the VM hard drive settings to point to the new VHD file created. If you want to use the same file name for the VHD as before the resize you must rename the newly created and the old VHDs. I’ll typically rename the old VHD something like “Server8DELETE.vhd” and the new VHD “Server8”. Then (and this is an important step) you have to force a change in the Hyper-V Manager VM hard drive settings to properly change the registry setting pointers. You cannot simply rename the VHD in Windows Explorer and expect Hyper-V Manager to use the newly created VHD. I simply click “browse” then select the old VHD and click “Apply” when changing the Hyper-V hard drive settings then “browse” and select the new VHD and click “Apply” / “OK”.

    10.   I’ll finally verify the newly created VHD works and then delete the old VHD.

     

    Hope this helps!

    Boris

    • Proposed as answer by Bor1s Monday, August 09, 2010 1:40 PM
    Monday, August 09, 2010 1:39 PM
  • In a couple desktop P2V migrations I have performed I booted with a GParted / Clonezilla Live CD and used ntfsresize to reduce the partition size. Make sure you have a backup before you do this, or do it on a copy in case you need to go back to the original.

    I'll have to look into the "Shrink Volume" command folks here mentioned -- that's sound a bit easier ;-)

    Friday, November 12, 2010 12:06 AM
  • Good step by step - the part with diskpart is usefull to ensure that VHD is not read only to use VMToolkit - otherwise the resize button will be grayed out...

    Performed the converting and resizing of SBS2011 VHD from 300GB max dinamic to 80 fixed - very happy!

    Saturday, April 07, 2012 2:03 PM
  • If your storage provider is NetApp, then you can just use the Data ONTAP PowerShell Toolkit v1.7.  A couple of cmdlets there make this really easy:

    ConvertTo-NaVhd -SourceVhd <path> -DestinationVhd <path> 

    Will convert a dynamic VHD to a "Fixed Thin" VHD.  A "Fixed Thin" VHD is a fixed VHD with all the unused blocks unmapped with SCSI UNMAP.  To NTFS it appears as a fixed VHD.  To the NetApp storage, it only consumes as much space as you have written to it.  This is very fast.  Converting a 100g dynamic VHD to Fixed takes about 2 minutes.

    Set-NaVirtualDiskSize <path> +/- <size>

    Will grow or shrink a fixed VHD along with the partition inside it.  Once again, it is very fast.  Less than a minute for most changes.

    The toolkit is free to NetApp customers/partners.  You can download it on the NetApp Communities.  You can find more information on usage scenarios for the toolkit at http://blogs.netapp.com/msenviro

    J


    Saturday, April 07, 2012 8:11 PM
  • This is an old post, but this may still help people who are attempting to use VHD Resizer to shrink their VHDs.

    There are two prerequisites for shrinking disks 

    - there must be unallocated space within the VHD file itself (ie no partition created for the space). This is easily done by starting the virtual machine, opening Disk Management and selecting "Shrink" on the partition(s) within the VHD.

    - there can be no snapshots. You must delete the snapshots, shut the virtual machine down and wait for the merge to complete (view the progress in Hyper-V manager).

    After these two are satisfied, you should be able to shrink the VHD using VHD Resizer.

    Saturday, June 09, 2012 4:02 AM
  • Download VHD resizer and you can resize your disks: http://vmtoolkit.com/blogs/announcements/archive/2007/02/28/vhd-expander-is-now-vhd-resizer.aspx
    Technet Forums Moderator | Solution Specialist | Ask The Experts IT-forum
    That link is now dead, anyone got an alternate link or download of the s/ware?
    Wednesday, January 09, 2013 8:00 AM
  • I have been able to download the VHD resizer from the following location: http://www.dariusblog.net/2012/11/02/vhd-resizer-from-vmtoolkit-com/

    Select Download (copy) as the first link is broken.

    Before running the VHD resizer make sure to detach the VHD using the Disk Management console. Otherwise the resizer reports "invalid VHD format", which means "file in use".

    • Edited by Boris2000 Saturday, February 09, 2013 10:30 PM
    Saturday, February 09, 2013 10:12 PM