Shrink Sparse Disk Files of Windows VM Images

From JoBaPedia
Jump to navigation Jump to search

Shrink Sparse Disk Files of Windows VM Images

Sparse files only claim space for data that is actually used. Contiguous blocks of zeroes are skipped. This is useful for files that represent disks of VMs. Unfortunately, deleted files are not zeroed out. This prevents the mechanism to work on older VM's where data was often created and deleted again. But on Windows (since XP Pro) there is a utility to zero out unused space.

Start a cmd.exe as administrator and enter this command for disk C:

cipher /w:c

It will wipe data in three waves. First wave writes zeroes, second wave writes 0xFF's and the last wave writes random data. Wave 2 and 3 are good for privacy, but obviously bad for our sparse files. So cancel the tool when it starts wave 2. You'll see that wave 2 has started on the screen.

I tried this on a new windows 8.1 image (Fresh windows 8 install, all updates, quicken install + some tools, then 8.1 update)

  • Size of sparse file: 40 GB
  • Image before shrink: 39 GB
  • Image after shrink: 18 GB