Page 1 of 2 12 LastLast
  1.    19 Mar 2017 #1
    Join Date : Dec 2015
    Posts : 5,936
    Windows10

    Compacting virtual hard disks


    Compressing a vhdx file in Hyper-V

    Well I have had fun today trying to compress some vhdx files used in Hyper-V.

    My VHDXs only had around 15GB of files (10 pro Insider 15061) including hidden files after disk cleanup when in Hyper-V but the vhdx files were around 40 GB/

    Tried following

    1) to compact it using Hyper-V compact - no change

    2) mounted vhdx as drive in host and used vdisk compact - no change

    3) backed up vhdx using Macrium Reflect, deleted partition and restored - no change.

    4) shrunk c drive to minimum size with partition wizard - no change

    5) shrunk c drive to minimum size and expanded to full size with partition wizard - no change

    6) backed up c partition from 5 above (deleting c partition in vhd in Macrium) and restored with Macrium - no change


    So I did this then

    7) deleted c drive partition in vhdx from disk management, and then restored c drive using Macrium (said full copying)- no change!

    8) So I then created a new vhdx and restored the image backup to new vhd (Hoooray - file now only 15 GB)

    9) renamed old vhdx with .bak and renamed new one to old name and ran hyper-v - would not boot.

    Back to trusty Macrium - booted from Rescue Drive and used "fix windows boot problems" - SUCCESS!

    So sequence is

    a) mount vhdx in hyper-v, use disk cleanup etc.

    b) mount vhdx in host disk management

    c) shrink c drive to minimum, the re-expand to full size using minitool partition wizard or similar

    d) image backup vhdx using Macrium Reflect

    e) create new vhdx

    f) restore image backup from Macrium Reflect to new one (renaming old to .bak and new name to old name).

    g) repair boot files using Macrium in hyper-v if needed.

    In hindsight, not sure if step c is needed. More testing needed.
      My ComputerSystem Spec
  2.    19 Mar 2017 #2
    Join Date : Nov 2014
    The Netherlands
    Posts : 628
    Win 10 Pro x64 1607 (Build 14393.953)

    Compacting virtual hard disks


    Sounds like a fun trip indeed! I'll give that a shot with VMware Fusion VM too. Keep you posted.

    Cheers
      My ComputerSystem Spec
  3.    19 Mar 2017 #3
    Join Date : Dec 2015
    Posts : 5,936
    Windows10
    Thread Starter

    Quote Originally Posted by M4v3r1ck View Post
    Sounds like a fun trip indeed! I'll give that a shot with VMware Fusion VM too. Keep you posted.

    Cheers

    Never had a problem compressing vhds when I used VMWARE. Issue seems to be with vhdx files.
      My ComputerSystem Spec
  4.    19 Mar 2017 #4
    Join Date : Jul 2015
    Posts : 3,722
    10 Pro

    I do this inside the VM before compacting - Defrag to consolidate free space then use sdelete to zero.

    It works much better than just compacting the vhdx.
    Code:
    		{	$Command = "C:\Windows\System32\defrag.exe"
    			$Parms = "C: /h /x"
    			$Prms = $Parms.Split(" ")
    			& "$Command" $Prms
    
    			$Command = "C:\Windows\System32\defrag.exe"
    			$Parms = "C: /h /o"
    			$Prms = $Parms.Split(" ")
    			& "$Command" $Prms
    
    			$Command = "C:\Users\Hali\OneDrive\Programs\SysinternalsSuite\sdelete.exe"
    			$Parms = "C: /z"
    			$Prms = $Parms.Split(" ")
    			& "$Command" $Prms
    		}
    Probably the save restore route with Macrium would be just as good (or better) but it is sometimes easier to run a script I think...
      My ComputerSystem Spec
  5.    19 Mar 2017 #5
    Join Date : Dec 2015
    Posts : 5,936
    Windows10
    Thread Starter

    Quote Originally Posted by lx07 View Post
    I do this inside the VM before compacting - Defrag to consolidate free space then use sdelete to zero.

    It works much better than just compacting the vhdx.
    Code:
            {    $Command = "C:\Windows\System32\defrag.exe"
                $Parms = "C: /h /x"
                $Prms = $Parms.Split(" ")
                & "$Command" $Prms
    
                $Command = "C:\Windows\System32\defrag.exe"
                $Parms = "C: /h /o"
                $Prms = $Parms.Split(" ")
                & "$Command" $Prms
    
                $Command = "C:\Users\Hali\OneDrive\Programs\SysinternalsSuite\sdelete.exe"
                $Parms = "C: /z"
                $Prms = $Parms.Split(" ")
                & "$Command" $Prms
            }
    Probably the save restore route with Macrium would be just as good (or better) but it is sometimes easier to run a script I think...
    I always avoid defrag as it usually takes so long. Minitool does the same in effect in a fraction of the time.

    What does sdelete do?

    Edit: I have just seen this

    Compacting Client Hyper-V VHDX Files • Helge Klein
      My ComputerSystem Spec
  6.    19 Mar 2017 #6
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,965
    Windows 10 Pro

    Quote Originally Posted by cereberus View Post
    In hindsight, not sure if step c is needed. More testing needed.
    Please do not take this wrong, I just have to say that your process involves awfully lot unnecessary work!

    To start with, a dynamically expanding VHD can only grow. It never shrinks, that's not what Compact Disk means. Each checkpoint, even when later removed makes VHD bigger, and so on.

    My workflow when I want to free unnecessary space used by my dynamical VHDs:

    • Disk clean-up
    • Create Macrium image of my VM
    • Shut down VM
    • Replace existing VHD with new dynamically expanding one in VM settings
    • Restore Macrium image to new VHD

    Can't understand why you mount VHD in host, can't understand why to save old VHD as .bak when Macrium Image exists.

    Of course I also export all new Hyper-V virtual machines as soon as I have finished installing Windows, when the VHD file size is smallest. If then later I want to start from scratch, from freshly installed Windows, I just delete the VM and import it back.

    Kari
      My ComputerSystem Spec
  7.    19 Mar 2017 #7
    Join Date : Jul 2015
    Posts : 3,722
    10 Pro

    Quote Originally Posted by cereberus View Post
    I always avoid defrag as it usually takes so long. Minitool does the same in effect in a fraction of the time.

    What does sdelete do?

    Edit: I have just seen this

    Compacting Client Hyper-V VHDX Files Helge Klein
    sdelete writes zeros to free space. If you do run it note it takes a long time (much longer than defrag) and sits on 100% complete for ages before it finishes. It is tempting to think it isn't working but it is - just need to let it finish.

    I have it as part of a script that compacts the OS, removes apps I don't want, runs disk cleanup and so on. I just let it run after upgrade/clean install. The whole script takes an hour to run I guess but it saves thinking.
      My ComputerSystem Spec
  8.    19 Mar 2017 #8
    Join Date : Dec 2015
    Posts : 5,936
    Windows10
    Thread Starter

    op
    Quote Originally Posted by Kari View Post
    Please do not take this wrong, I just have to say that your process involves awfully lot unnecessary work!

    To start with, a dynamically expanding VHD can only grow. It never shrinks, that's not what Compact Disk means. Each checkpoint, even when later removed makes VHD bigger, and so on.

    My workflow when I want to free unnecessary space used by my dynamical VHDs:

    • Disk clean-up
    • Create Macrium image of my VM
    • Shut down VM
    • Replace existing VHD with new dynamically expanding one in VM settings
    • Restore Macrium image to new VHD

    Can't understand why you mount VHD in host, can't understand why to save old VHD as .bak when Macrium Image exists.

    Of course I also export all new Hyper-V virtual machines as soon as I have finished installing Windows, when the VHD file size is smallest. If then later I want to start from scratch, from freshly installed Windows, I just delete the VM and import it back.

    Kari
    Re. .bak - just cautious - I delete after I verify new vhd works.

    What I found was that exporting vhdx using mrf alone and reimporting to new vhdx did not shrink the vhdx to minimum size possible. The minitool step does that (basically a defrag).

    Sure you can do this inside vm - just found it faster doing in host.
      My ComputerSystem Spec
  9.    19 Mar 2017 #9
    Join Date : Oct 2013
    A Finnish expat in Germany
    Posts : 12,965
    Windows 10 Pro

    Quote Originally Posted by cereberus View Post
    What I found was that exporting vhdx using mrf alone and reimporting to new vhdx did not shrink the vhdx to minimum size possible. The minitool step does that (basically a defrag).
    We must have totally different working methods

    Let's see what I told to be my workflow, and check how that works in reality. Example W10 x64 VM is one I have used for ESDtoISO and UUPtoISO testing, a clean installed build 15048 with no additional software installed, upgraded several times to builds 15055, 15058, 15060 and 15061, always restored back to clean 15048. This has of course caused the VHD size to grow to multiple times what really is needed.

    Quote Originally Posted by Kari View Post
    • Disk clean-up
    • Create Macrium image of my VM
    After the above, checking file sizes. Macrium image was made when the original 64 GB dynamically expanding VHD was 34.5 GB:

    Click image for larger version. 

Name:	image.png 
Views:	30 
Size:	373.0 KB 
ID:	125826

    Macrium image size just under 5 GB:

    Click image for larger version. 

Name:	image.png 
Views:	30 
Size:	147.1 KB 
ID:	125827

    Quote Originally Posted by Kari View Post
    • Shut down VM
    • Replace existing VHD with new dynamically expanding one in VM settings
    • Restore Macrium image to new VHD
    After restoring Macrium image to a new dynamically expanding VHD, file size is 9.3 GB. Over two thirds smaller than original one:

    Click image for larger version. 

Name:	image.png 
Views:	31 
Size:	355.3 KB 
ID:	125828

    The same as seen by File Explorer, yellow highlight is the original VHD, start situation, and green highlight the new VHD where Macrium image from old VHD was restored. Old VHD can now be deleted, net storage save savings over 25 GB in this example case:

    Click image for larger version. 

Name:	image.png 
Views:	30 
Size:	60.6 KB 
ID:	125829
    (Notice that VHD has already grown over 0.5 GB since the previous screenshot a few minutes earlier. This is because in previous screenshot VM was not started yet after restoring the image.)

    This of course is all logical, happens every time.

    Kari
      My ComputerSystem Spec
  10.    19 Mar 2017 #10
    Join Date : Jul 2015
    Posts : 3,722
    10 Pro

    Just did a similar test. I have a clean install of 10561 with about 300MB of programs installed.

    Before doing anything the VHDX was 10.54GB. I reduced the size of Windows to 6.50GB.
    Ran defrag free space and slab consolidation (took less than 1 minute) and sdelete (took 40 minutes)

    Compact option in Edit disk in Hyper-V reduced the VHDX to 7.38GB. Save and restore using Macrium reduced it to 6.65GB.

    So it seems Macrium is more efficient but IMO more of a faff.

    Code:
    Microsoft Drive Optimizer
    Copyright (c) 2013 Microsoft Corp.
    
    Invoking free space consolidation on (C:)...
    
    
    Pre-Optimization Report:
    
            Volume Information:
                    Volume size                 = 21.99 GB
                    Free space                  = 15.49 GB
                    Total fragmented space      = 35%
                    Largest free space size     = 10.97 GB
    
            Note: File fragments larger than 64MB are not included in the fragmentation statistics.
    
    The operation completed successfully.
    
    Post Defragmentation Report:
    
            Volume Information:
                    Volume size                 = 21.99 GB
                    Free space                  = 15.49 GB
                    Total fragmented space      = 34%
                    Largest free space size     = 10.98 GB
    
            Note: File fragments larger than 64MB are not included in the fragmentation statistics.
    Microsoft Drive Optimizer
    Copyright (c) 2013 Microsoft Corp.
    
    Invoking slab consolidation on (C:)...
    
    
    The operation completed successfully.
    
    Post Defragmentation Report:
    
            Volume Information:
                    Volume size                 = 21.99 GB
                    Free space                  = 15.49 GB
    
            Allocation Units:
                    Slab count                  = 702
                    In-use slabs                = 223
    
            Slab Consolidation:
                    Space efficiency            = 100%
                    Recovered space             = 1.71 GB
    
            Retrim:
                    Total space trimmed         = 4.15 GB
    
    SDelete v2.0 - Secure file delete
    Copyright (C) 1999-2016 Mark Russinovich
    Sysinternals - www.sysinternals.com
    
    SDelete is set for 1 pass.
    Free space cleaned on C:\
    1 drive cleaned.
    
    
    Press Enter to return to menu:
    Before

    Click image for larger version. 

Name:	Before.PNG 
Views:	21 
Size:	8.3 KB 
ID:	125834

    After running Compact in Edit Disk

    Click image for larger version. 

Name:	After.PNG 
Views:	21 
Size:	7.7 KB 
ID:	125833

    After save/restore using Macrium

    Click image for larger version. 

Name:	Macrium Copy.PNG 
Views:	21 
Size:	8.8 KB 
ID:	125835
      My ComputerSystem Spec

 
Page 1 of 2 12 LastLast


Similar Threads
Thread Forum
Solved Virtual hard disk can't be mounted ...
Hello everybody, recently I've installed Windows 8,1 Pro version on my laptop and today I'm trying to install Microsoft Office 2007 Enterprise. I've have it on CD but when I'm trying to run it there's a message that says : "Virtual hard disk...
Virtualization
Install Win 10 on two hard disks, same computer
Good day everyone The reason why I want to install Windows 10 on each of my two hard disks is because the Win 10 on my first disk is for my job, where I need to install software provided by my employer. The second Wind 10 on my second hard disk is...
Installation and Upgrade
Virtualization Change Hyper-V Virtual Hard Disks Folder in Windows 10
How to Change Default Folder to Store Hyper-V Virtual Hard Disks Hyper-V enables running virtualized computer systems on top of a physical host. These virtualized systems (aka: guests) can be used and managed just as if they were physical...
Tutorials
Solved Virtual Hard disk created in hyper-v
Hi There I am using windows 10 Pro, and had a virtual machine installed using Hyper-V with two virtual HDD in that VM. Recently I had some problem with my Windows 10 OS and had to reset my windows with keeping all the files and settings, and...
Virtualization
I lost 2 Hard Disks after updated from Build 9860 to 9879
Updated to build 9879 with no problems from build 9860. However, I powered down and restarted the next morning to find "Disk Boot Failure - Insert system disk". Whatever I tried to see inside the disk failed because it wasn't recognised in...
Drivers and Hardware
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 09:09.
Find Us
Twitter Facebook Google+ Ten Forums iOS App Ten Forums Android App



Windows 10 Forums