How To Shrink VMware Virtual Disk Files with Windows Guest
While at home for reading week, I set up my development environment on Windows XP Professional, 64-bit. XP x64 was never meant to be run on real hardware, as it lacks driver support from hardware vendors. However, it was free for students and quick to set up with VMWare as I only had to enter the license key for an unattended install. I originally indended to carry around the virtual machine on a 8GB USB, but the hard disk file exceeded by a few GB. I managed to shrink all the files required to run the virtual machine combined down to less than 3GB. Here’s a quick run down of the process that requires about 1 hour for a computer to complete:
- Uninstall unused applications
- Delete downloads manually
- Clean out temporary files with CCleaner
- Shutdown virtual disk and make a copy
- Hook the virtual disk into slot2 and start the virtual machine Settings -> Hard Disk -> Add…
- Zero out unused parts of partitions on the copied disk with KillDisk wipe
- Shutdown virtual machine to work with the virtual disk file
- Defragment copied hard drive under Settings -> Hard Disk -> Utilities
- Compress copied hard drive
- Find the virtual machine working folder under Settings -> Options tab
- Replace the larger virtual disk file with the smaller one
- Create a zip folder of the virtual machine files, 7-zip is suggested
It’s easy to see why this process works, if you understand how file systems work. Because deleted files are still on the hard drive, they cannot be compressed in the virtual disk file. So the idea is to overwrite those unused sectors of the hard drive with zero’s. VMWare’s defragment collects zeros together at the end of the disk, and compress completely removes them from the virtual disk file, shrinking the file. If you’re making a clone of the virtual machine for later use, it is suggested to start the operating system again as it will detect hardware changes and reconfigure. Many of these steps take a few minutes to complete, so it is wise to have something else to do while waiting.
Update: Instead of using KillDisk, CCleaner has a wipe utility under Tools -> Drive Wiper. The default settings writes zeros over the free space. Compared to my method, it’s slower. One way to speed it up is to give the process realtime priority in the Task Manager.