Use “sdelete -z” when Shrinking a Windows Guest’s Virtual Hard Drive

I was installing Windows 7 in a VirtualBox Virtual Machine, and tried to shrink the dynamic virtual hard drive (vdi format). There are several guides out there explaining how to do this. SDelete is commonly used to zero out the virtual hard drive’s free space before compacting the hard drive file.  As the SDelete manual page states, “-z” is the correct option to use for this purpose.  However, many of the guides I read use the “-c” option.  This is counterproductive since it results in random data being written to the free space, thus causing the virtual hard drive file to expand to its maximum size (in my case, this filled my host PC’s hard drive).  This issue has been discussed quite a bit in forums and blog comments; “-c” at one time was the correct option to use, but the semantics of the “-c” and “-z” options changed with one of the recent SDelete releases (I understand it was with version 1.6).

Conclusion: With the latest version of SDelete, use the “-z” option when you are shrinking a virtual hard drive.

As a side note, it took a long time for SDelete to finish on my machine – I think it was because I made my virtual hard drive very large.  I chose a size much larger than I actually needed, since I thought there would be no disadvantage to having too much space (since it is a dynamic drive, the extra virtual space takes no physical space).  In hindsight, maybe I should have chosen a smaller size.

 

Update: I found this blog entry, which has a similar post.

Advertisements

VirtualBox – PowerShell Script to Start a Virtual Machine with the Maximum Number of Monitors

With the help of a Plugable UGA-2K-A, I sometimes attach an extra monitor to my PC.  I have a VirtualBox virtual machine that I like to run across all of my physical monitors, and I used to manually change the virtual machine’s Monitor Count when connecting or disconnecting the extra monitor.  I now have a PowerShell script which automatically detects the number of monitors connected to my PC, sets the Monitor Count of the virtual machine, and then starts the machine.  I am using the script on a Windows 8 host. I posted the script in this GitHub Gist.

Update: I found this blog entry, which has a similar script (although some of the mechanics are different).