0

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.

Thanks.

1

3 Answers 3

1

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=/filldisk.zero bs=100M ; rm /filldisk.zero

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

0

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.

0

You can compact VHD with SystemRescueCD

https://serverfault.com/questions/551053/how-can-i-compact-the-vhd-file-with-ubuntu - it is the answer on this question

You must log in to answer this question.