Microsoft Virtual Server Disk Compactor INCREASED VHD File Size
Wednesday, October 10th, 2007I’ve long wondered about why Microsoft included a virtual hard drive (VHD) compacting option in its Virtual Server Disk Inspector since it never seems to compact anything when I tried it. So I read the highlighted section on pages 24 and 25 of the book…
Professional Microsoft Virtual Server 2005
…titled Compacting a Dynamically Expanding Virtual Hard Disk with great interest. Ben Armstrong (a Microsoft Virtual Machine Product Manager) has provided a lot of good information about Virtual PC and Virtual Server in his Virtual PC Guy blog. So, his writing is heavily weighted in the valid column when I read what he has to say. However, in this case, I’m still mystified by VHD compacting even after reading this section and especially the Linux related aspects of this section.
Ben recommends zeroing out the Linux VHD free space by creating a file using cat /dev/zero > zero.dat. This creates a file that fills out the unused portion of the VHD. This fills up the hard drive. The next part of the scripts syncs the buffer and then removes the zero.dat file. This means if you have your dynamic VHD set to, say 127GB, you need at least 127GB and maybe 127GB x 2 (double). My test VHD was set to max out at 16GB. So, I didn’t have this problem. I had a lot of free server host hard disk space. I then shutdown the Linux Guest OS before heading over to the web-based Virtual Server management window to start the disk compacting. Here’s the odd result I found.
Size Linux reports used inside the Guest OS: 4.6 GB
Size Virtual Server reports VHD occupies on the host: 9.7 GB
Size of VHD with zero.dat file completely filled: 12.3 GB
The Virtual Hard Disk was a bit over twice the size of the file space Linux reported using. This is normal since this particular virtual machine sees moderate use as a test box. Files get installed and deleted frequently. The size of the VHD completely filled also makes sense although I thought it would get closer to 16GB. Here’s the surprise though. After completing the VHD compacting, the VHD file was 10.8 GB. Yep, compacting the VHD actually INCREASED its file size by 1.1 GB compared to where it was before starting the process of creating the zero.dat file.