How to compact the VHD file with Ubuntu

ext4hyper-vhyper-v-server-2008-r2ntfszero-fill

I use windows server 2008r2 with role Hyper-V. The guest system is Ubuntu 12.04 LTC. It is situated on the dynamic virtual hard disk.

I want to compact this VHD (The real size is 50 GB, 360 GB on the disk). But I can not do this, because the Ubuntu file system is not NTFS.
What do I need (gparted, sdelete, …) for solving this problem?

The main problem is that the filesystem is not NTFS, but ext4.

The answer:

1) Download systemrescuecd

http://sourceforge.net/projects/systemrescuecd/files/sysresccd-x86/3.8.1/systemrescuecd-x86-3.8.1.iso/download

2) Add this .iso to the quest OS Ubuntu

3) Start this virtual machine

4) Use zerofree

zerofree /dev/sda1

5) Poweroff this virtual machine

6) Use Hyper-V manager (Edit -> defragmentation)

This vhd was 360 Gb. Now 70 GB.

Best Answer

Poweroff your VM, backup the VHD, and run another virtual machine (I use SystemRescueCD since it's small and fast) that has the ext4 partition available to it, i.e., a HD for SysRescue (but don't mount it!). From the SysRescue VM, run 'zerofree' on the ext4 partition, poweroff that VM, and then use your Administration Website to compact the VHD.