Windows 10: I have discovered an easy way to compacting VHDs

Discus and support I have discovered an easy way to compacting VHDs in Windows 10 Virtualization to solve the problem; As we all know, vhds grow in physical storage size even if the vhds are much smaller in content inside the vhd. For example, I had a PRO 10 1709 VHD... Discussion in 'Windows 10 Virtualization' started by cereberus, Aug 29, 2018.

  1. cereberus Win User

    I have discovered an easy way to compacting VHDs


    As we all know, vhds grow in physical storage size even if the vhds are much smaller in content inside the vhd.

    For example, I had a PRO 10 1709 VHD of approx. 18GB and upgraded it to 1803. After I did disk cleanup, to remove windows.old etc, the contents of the vhd are back to 18GB but physically the vhd on hard drive was 38GB.

    I ran compact from diskpart (and from Hyper-V on a copy) and it had little effect, shrinking to around 36GB.

    I googled it and found a utility called SDELETE that zeros unused space (compact not work on unzeroed space apparently). I ran this on a 38GB copy, and it had some effect reducing to 27GB.

    However, I know with a bit of effort, shrinking C drive using minitool partition wizard, cloning vhd to another vhd, and re-expanding, the new vhd only occupies 18GB. I have done this many times.

    Then I had a light bulb moment - I thought why does the cloning method work, and I realised the key step is the shrinking step as that is essentially doing a defrag.

    So I thought "what if I defrag the 38GB vhd, and then compact?"

    I did this and, flabber my gast, it worked first time with the existing vhd being reduced to 18GB!

    The defrag of 38GB in a 50GB volume only took few minutes as the VHD was on an SSD (I am not defragging the SSD, only the virtual drive).

    So here is how to do it

    1) Mount vhd as a drive and note letter of OS drive e.g. R:

    2) Open admin command prompt and type

    Code: defrag R: /u[/quote]
    3) Eject mounted vhd from disk management

    4) Compact VHD (substitute correct drive letter, name and path as appropriate)

    Code: diskpart select vdisk file="D:\my path\my vhd.vhdx" compact vdisk exit[/quote] Compact from Hyper-V does not work after a defrag - it thinks file is compact.

    :)
     
    cereberus, Aug 29, 2018
    #1

  2. VHD to virtual PC

    does anyone know of an easy way to convert a VHD made using an old backup into a virtual PC
     
    theoneandonlymrk, Aug 29, 2018
    #2
  3. Kari Win User
    Compacting virtual hard disks


    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.
     
  4. Kari Win User

    I have discovered an easy way to compacting VHDs

    Compacting virtual hard disks


    We must have totally different working methods I have discovered an easy way to compacting VHDs :)

    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.

    After the above, checking file sizes. Macrium image was made when the original 64 GB dynamically expanding VHD was 34.5 GB:


    I have discovered an easy way to compacting VHDs [​IMG]

    Macrium image size just under 5 GB:


    I have discovered an easy way to compacting VHDs [​IMG]

    After restoring Macrium image to a new dynamically expanding VHD, file size is 9.3 GB. Over two thirds smaller than original one:


    I have discovered an easy way to compacting VHDs [​IMG]

    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:


    I have discovered an easy way to compacting VHDs [​IMG]

    (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.
     
Thema:

I have discovered an easy way to compacting VHDs

Loading...
  1. I have discovered an easy way to compacting VHDs - Similar Threads - discovered easy compacting

  2. What is the easy way to block websites???

    in AntiVirus, Firewalls and System Security
    What is the easy way to block websites???: I have a few websites, that haunt me... As soon I SEEM to block them, they reappear and are able to popup covering my abilities on the taskbar or status bars. I often don't notice and enable and activate them, allowing them to open up and further hurt my computer and my...
  3. Is there an easy way of toggling HDR on and off?

    in Windows 10 Ask Insider
    Is there an easy way of toggling HDR on and off?: I recently got a new monitor that supports HDR - and when I'm actually watching HDR content or gaming it looks fucking amazing, but when I'm not watching HDR (i.e. just on the desktop) it, instead of looking amazing, looks washed out and garbage... From googling around this...
  4. Is there an easy way to record part of a screen?

    in Windows 10 Ask Insider
    Is there an easy way to record part of a screen?: As per the title, I need to record one part of a screen (full screen won't do, just one window won't do either, so the Game Bar is out of the question). Is there an easy way to do this? When I googled it, all solutions seem to involve apps which will watermark the recording...
  5. easy way pin windows?

    in Windows 10 Software and Apps
    easy way pin windows?: pin windows show on all desktops pin windows should show on top of desktop, but below other windows by default 156295
  6. Is there an easy way to reset the Volume Mixer?

    in Windows 10 Ask Insider
    Is there an easy way to reset the Volume Mixer?: Everything appears to be a really low volume for some reason. submitted by /u/Ritalio [link] [comments] https://www.reddit.com/r/Windows10/comments/ghcryq/is_there_an_easy_way_to_reset_the_volume_mixer/
  7. Is there an easy way to share files??

    in Windows 10 Ask Insider
    Is there an easy way to share files??: Hello, I have 2 Win 10 Home machines sitting next to each other on a desk, both connected to the same wifi network. Is there an easy way to transfer files from one machine to the other?? I've been using a flash drive because I have googled my brains out and cannot figure...
  8. Easy Way to Transfer Account Settings

    in Windows 10 Customization
    Easy Way to Transfer Account Settings: I think I have a corrupted Windows Account. I could not find an easy way to transfer my existing one to a new one I made. Also the new account has a different name under users since I cannot use my original name. Any suggestions on how to solve these two problems?...
  9. Firefox -- is there an easy way to access Favourites

    in Browsers and Email
    Firefox -- is there an easy way to access Favourites: Hi there On the Tor Browser ( a variant of firefox it's really easy to access BOOKMARKS (favourites) [img] On Firefox it's another step to get the bookmarks or is there something in configuration that I can use -- the bookmarks icon doesn't appear in the standard...
  10. Easy way to open EPUB files

    in Windows 10 Support
    Easy way to open EPUB files: Greetings from Holly Jerusalem Easy way to open EPUB files 1. Open Google chrome 2. Get Simple EPUB Reader extension 3. Open Simple EPUB Reader extension 4. Drop your EPUB file 5. Setup settings as you prefer That is all 92677

Users found this page by searching for:

  1. compact all vhds in a folder