none
resize fixed VHD

    Question

  •  
    Hi,
     
    I do use fixed vhd files but like to resize them. What is the best way to do this ?
    Friday, March 14, 2008 11:51 AM

Answers

All replies

  •  
    Hi,
     
    Compacting is not usefull with fixed disks
     
    I like to resize the fixed vhd and make it smaller. The only way I can think of doing it now is to make a ghost image an restore that on a new smaller disk but it must be possible to do it easier....
    Friday, March 14, 2008 1:38 PM
  • Okay...not sure why you think compacting is not useful. Anyway, here is another wild way to do it. Again, I dont know if MSFT supports it or not.

    1. Boot the target VM with WinPE 2.0 DVD or CD
    2. At the command prompt,
    • Diskpart.exe
    • diskpart> Sel disk 0
    • Diskpart> Sel vol 1 (Assuming your VHD is detected as vol 1)
    • Diskpart> shrink desired=4000 minimum=2500
    I just did this on my dynamic VHD and I got a message that the volume was shrunk by 4000MB and it even reflects in the VM when I started it from the VHD. I had a 20GB dynamic VHD and the size after shrink was 16GB. I could verify this in disk management as well. I am not sure about the side effects of this experiment. As far as I see, my guest is really happy.

    I am currently converting this VHD to fixed type and will try the same steps on the fixed VHD to see if it actually reflects in the parent partition filesystem.

    Your comments are welcome. Waiting to see what MSFT will say

    Cheers
    Friday, March 14, 2008 2:54 PM
  • I am getting a feeling that using diskpart shrink is not the right way. Shrink operation was successful but the Msvm_VirtualDiskInfo values still reflecting 20GB max internal file size. This is understood because diskpart shrink operation will not change any VHD header information to reflect the shrunk size of the VHD. Now, it will be interesting to see what will happen to the VHD if I try and grow it to the max. Would it be 20GB or 16GB (shurnk size)?

    I am also thinking if the Edit Disk -> Compact feature is similar to what diskpart shrink does except that the edit disk will be capable of updating VHD header information also.

    Weird thoughts..!!
    Friday, March 14, 2008 3:32 PM
  • We do not provide a way to do this - but you may want to checkout the VHDResizer tool from here: http://vmtoolkit.com/files/folders/converters/entry87.aspx

     

    Cheers,

    Ben

    Monday, March 17, 2008 8:25 PM
  •  

    I already contacted people from this website because I did know this tool but it doesnot run on Windows 2008 RTM x64
    Tuesday, March 18, 2008 3:41 PM
  • This is one year old post. Is there any easy way to resize fixed size VHD in hyper-v now? Or do we still need to use third party tool? 


    Darwaish
    Thursday, June 18, 2009 9:12 PM
  • Ditto, can someone tell us whether you can shrink a fixed vhd disk in either Hyper-V R2 or VMM 2008 R2
    Monday, July 27, 2009 7:09 PM
  • And nearly another year after this post without any change?  I'll try the third party utility again, but last run it didn't do anything to remove the unused space on the VHD file.  If there's anything new available I sure would love to hear about it.
    Wednesday, May 12, 2010 1:14 PM
  • Lawdy lawdy.

    If you accept defaults for VPC (Win 7) for a dynamic drive, max size is that of the parent PHYSICAL drive where you save the vhd.  I spent a solid week getting my vm all SysPrep'd, and prettied up with apps, before I learned the hard way that this header info is hard to change.

     

    IMPORTANT DIFFERENCE: 

    1. On the one hand, you got folks talking about the size of the vhd FILE (highly mobile and easy to copy/replace), and then

    2. Altogether on another planet, ya got the size of the virtual drive that the vm THINKS it is living on, which is set at max size.

     

    Those who know the difference, for fear(?) of insulting those who don't, usually neglect to point out this CRITICAL difference, and instead assume you know it.  So, as a novice vm guy, you spend a hundred or more hours learning to SysPrep your perfect VM's, clone them, and then install apps and more.  You are excited because you imagine that NEVER AGAIN, will you DIE THE SLOW DEATH of formatting and reinstalling tons and tons of junk (often at the end of enormous troubleshooting efforts, windb and whatnot). 

    But low and behold, you find that this horrific little number, a simple parameter that a kind-hearted programmer might write a tool to change in the vhd header, will WREAK HAVOC, and put a straight jacket on where and how you use the vhd.


    humpty dumpty is sleepy
    Monday, June 28, 2010 8:40 PM
  •  

     

    Ravikanth,

     

    I had a bloated 40 Gb VHD with about 14 Gb of used space.  The guest is XP Pro x86, host is Win 7 Enterp X64 running Virtual PC.  Teracopy and other programs could not (or would not) copy the 40 Gb VHD anywhere else for me.  And even VHDResize wouldn't copy it after I shrank the used partition down to 14 Gb, with 26 Gb unallocated inside the VM.  So here's what I did:

     

    -------------------------------------------------------------------------

    HOW TO SHRINK A 40 GB FIXED VHD (with 14 Gb used), to a 15 GB DYNAMIC VHD

    -------------------------------------------------------------------------

     

    1. Compress/defrag/etc, your current vhd while booted up as the system drive in a vm, and install software such as EASEUS Partition Master Pro/Server
    2. If you use the free version of EASEUS Partition Master, this procedure won't work, but I think that Ghost might work as well as Easeus, and Acronis too.
    3. In a nutshell, we're going to mount a 2nd VDH with maybe a Gb more space than you really need, and "clone" the sys drive to the attached 2nd vhd
    4. To easily create the additional (2nd) vhd, just use the explorer shell to create a new VM: I used the same VM/VHD names, but stored in a diff. folder
    5. The new VHD should be slightly larger than the 'used' space on the VHD in the original VM, and it will need to be 'fixed' to show up that size inside the VM.
    6. Try not to create a situation where you've got like 15 steps that need to be done in a single reboot, to avoid possible bad problems.
    7. Shrink the partition on the original VHD while booted into it's VM, just slightly larger than the 'used' space, so most of it becomes unallocated.
    8. Attach the VHD you created before (it should be 'fixed'), and then clone the source (original) 'drive' to the new smaller drive, then tell it to 'apply' (reboot)
    9. Create a new VM for the new VHD, and boot up.  

    DON'T FORGET:  Don't forget that in some programs, a 'partition clone' operation doesn't make the new (target) partition a bootable system drive (that's the problem with Easeus Partition Master Free Edition).  To avoid fiddling with the MFT or worse, just use a program like Easeus Pro or Ghost, which can clone the drive, and can be told to only move over the 'used' space (Easeus refers to this as a clone with resize on the fly).

    Also, just for peace of mind:   You need not wonder if this is just pure conjecture.  I know that this works, because I've done it.   

    ~p

     


    humpty dumpty is sleepy
    Sunday, August 15, 2010 9:11 PM
  • Even though VHD resizer [ is not supported | does not run | you do not want to install it ] on Windows 2008, you can still use it.

    You can copy your VHDs to a Windows 7 computer, with VHD Resizer installed in it, and follow the steps in http://jagbarcelo.blogspot.com/2011/11/how-to-shrink-vhd-virtual-hard-disk.html . I have already managed to reduce the size of some dynamically expanding VHDs and wrote a post about it. I hope it helps someone.

    Regards.


    Thursday, November 10, 2011 5:31 PM
  • If your storage vendor is NetApp, you can download the Data ONTAP PowerShell Toolkit v1.6.  This includes the Set-NaVirtualDiskSize cmdlet that you can use to grow or shrink a fixed VHD to include the partition inside the VHD.  When you shrink a VHD, not only does the VHD  shrink in the NTFS file system, the now unused blocks are dealloced on the storage back end using SCSI UNMAP.  Likewise, when you grow the added blocks are unmapped on the storage.  That way, blocks within the VHD don't consume additional space until you actually write to them.  You'll also find the New-NaVirtualDisk cmdlet which creates fixed VHDs will all the blocks in the data area unmapped (it's thin on the storage although it appears thick to NTFS), Copy-NaHostFile which leverages sub-LUN cloning technology to clone VHDs without using additional space on the back end, and Remove-NaHostFile which unmaps all the blocks then delets a file (single file space reclaim).

     

    J

     

     

    Thursday, November 10, 2011 5:47 PM
  • Quite frankly messing around with production based VHDs is risky indeed.

    On other than OS partition/VHDs we would complete a backup of the data on the VHD/Partition and then restore that data to the newly created VHD/Partition/LUN.

    For an OS partition we would run the shrink process from within Disk Management prior to restoring to a smaller partition/VHD if possible. Otherwise we would restore the OS to a larger VHD/Partition/LUN.

    While using a backup/restore process may be somewhat costly in time, it greatly reduces any risks to the VM and its VHDs.

    As a rule of thumb we prefer to treat VHDs in the same manner as a physical hard disk/SSD.

     


    Philip Elder SBS MVP Blog: http://blog.mpecsinc.ca
    Thursday, November 10, 2011 8:03 PM
  • VHDResizer works fine when run on a Windows 2008 R2 physical server or virtual machine.    The source VHD needs to be shrunk first using Disk Management from within the guest virtual machine.

    Microsoft, why is this very useful feature not available natively in Hyper-V/SCVMM    Will it be introduced in Hyper-V 3.0?    The ability to expand VHDs whilst the VM is running would also be extremely useful.

    Mark

    Saturday, May 05, 2012 2:03 AM
  • VHDResizer works fine when run on a Windows 2008 R2 physical server or virtual machine.    The source VHD needs to be shrunk first using Disk Management from within the guest virtual machine.

    Microsoft, why is this very useful feature not available natively in Hyper-V/SCVMM    Will it be introduced in Hyper-V 3.0?    The ability to expand VHDs whilst the VM is running would also be extremely useful.

    Mark

     Confirmed, I was also able to use VHDResizer on 2008 R2 SP1 Ent x64. It took a few minutes for it to start, but once it did, it didn't take that long to resize a 100GB FD down to 60GB.
    • Edited by hazmat2012 Friday, May 25, 2012 9:08 PM
    Friday, May 25, 2012 9:07 PM
  • can an update to this thread be made to accomodate Windows 2012 HyperV with fixed disk shrink/compact processes? - GUI and/or PS

    ...tia Dale


    Dale Unroe

    Wednesday, November 07, 2012 4:24 PM
  • 2012 has it's own capability to shrink fixed VHDs, the powershell cmdlet is resize-vhd.

    Heh, I kept running into that when I'm looking to shrink a 2TB VHD down to 120GB.. the VHD being fixed and having mostly unallocated space after shrinking the OS volume down.  Went around a loop with disk2VHD.. which created the small (15GB) dynamic VHD.. which is what I started with...  *sigh*.  gParted was happy to copy/paste the partitions.. but Windows Boot Manager got mad at me.

    All because the Dell OEM VHD for 2008 R2 Enterprise comes this way.. and I intend to have an Exchange 2010 VM with a fixed-size C: drive and a SAN passthrough for the data.  Go figure.  Knew I should have snapped an ISO of the OEM CD and put it on the host..  wasted more time than shuttling it out to the client site..

    Tempted to just fire up a 2012 VM and do the deed using it!

    Wednesday, November 28, 2012 7:48 PM
  • I am looking for a way to shrink a fixed VHD on server 2008 R2.

    In these posts, people recommend the VHDResizer tool, but from what I can tell, that tool is no longer available.  The website fails and I can't find any other reputable sites that claim to have the tool.

    Does anyone know where I can get that tool or if there is now a better way to shrink a fixed VHD?

    Tuesday, March 05, 2013 3:39 PM
  • http://blogs.msdn.com/b/virtual_pc_guy/archive/2008/03/12/expanding-virtual-hard-disks-with-hyper-v.aspx

    should fix all your problems :)

    Monday, June 10, 2013 4:36 PM
  • unfortunately isn't vmtoolkit.com online (any more)
    Friday, August 30, 2013 12:55 PM
  • unfortunately isn't vmtoolkit.com online (any more)
    Here is the working link http://www.dariusblog.net/wp-content/uploads/2012/11/VhdResizerSetup.zip from the link somewhere above (http://www.dariusblog.net/2012/11/02/vhd-resizer-from-vmtoolkit-com/).
    Tuesday, October 15, 2013 4:43 PM
  • Yeah.. that link doesn't work either.

    Ugh.. just want to shrink my fixed VHDs.. now with unallocated space.. before migrating the hypervisor to 2012 R2.

    Wednesday, June 25, 2014 10:42 PM