Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i am running Hyper-V on Windows 8, with few Virtual machines like XP,Ubuntu, etc.. i have set hard drive to be on demand, so it's starting small.

Now i have downloaded few files on my Virtual XP, i noticed that hard disk used space is about 12 GB, so i decided to delete some files, after deleting even from recycle bin, the hard drive is now around 6GB, but the problem is when i checked the read size of the VHDX it's still around 12GB !!

i tried to power off and edit/compact the hard drive, but it's still the same size!!

any help is appreciated.


share|improve this question

migrated from Mar 4 '13 at 13:09

This question came from our site for system and network administrators.

You can use SystemRescueCD Here is the answer:… – AmShegar Nov 20 '13 at 14:36

Deleting big files changes only tiny parts of the (virtual) hard disk: the block allocation. The content data of the file remains on the disk until overwritten. The hypervisor / disk image does not work on the file system level. You have to overwrite the data with zeroes for the compacting to be successful. With Linux (and a file system that still allows you remove files when it is completely full (btrfs has problems in that situation)) you can do this:

dd if=/dev/zero of=/ bs=100M ; rm /

In the future you can delete files in a VM with wipe -z instead. There is probably a Windows tool to do the same.

share|improve this answer

Hyper-V will compact the VHD (or VHDX) whenever either of two conditions are true:

1) It can mount the VHD and the underlying file system and use the data from within the file system to figure out which blocks in the VHD are no longer used by the file system.

2) The OS in the guest uses the ATA "trim" command or the SCSI "unmap" command to indicate to the underlying disk that blocks are being freed and the data within them is no longer of interest.

(1) isn't going to work unless the file system is one that Windows knows intimately, and I suspect that though you don't mention it, you weren't using NTFS in your Ubuntu installation. For the Windows XP VM, it might have helped to defragment it under XP first (which would have made the VHD even bigger during the process) and then compacted it with the VM turned off.

(2) only works with very recent Windows versions. You might be able to find Ubuntu versions or patches which support trim and/or unmap.

share|improve this answer

You can compact VHD with SystemRescueCD - it is the answer on this question

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.