Compacting a Linux Hyper-V, Virtual PC 2004 or 2007 Dynamic VHD/VHDX file

System Requirements:

  • Virtual PC 2004, SP1
  • Virtual PC 2007, SP1
  • Hyper-V

The Problem:

The Windows Integration components ISO contains a tool for performing a VHD pre-compact. Once completed, this tool allows you to shut down a VHD and compact it to reclaim disk space previously used by the VM which has actually marked as being free space by the VHD FAT/MFT.

More Info

As Linux operating systems do not formally include integration components for Virtual PC, there is no standard Microsoft way to pre-compact the VHD. The fundamental process behind pre-compaction is however simple: write 0’s all sectors of the hard drive that the FAT/MFT claim to be free (available) space.

Once you have done this, the Virtual PC/Hyper-V management UI will flush the contents of the VHD into a new VHD, skipping any 0’d sectors from the migration process, thus reducing the size of the VHD as seen by the hypervisors host partition.

The Fix

I’ve used two different methods to achieve Linux pre-compaction.

Note: This was written against the steps that need to be performed on Debian. Other distributions may require additional steps to install software.

Open Terminal and execute the following:

cd /
cat /dev/zero > zero.dat ; sync ; sleep 1 ; sync ; rm -f zero.dat

Although simpler and not requring any software installation, the compaction rate achieved using the method was a little hit and miss, often resulting in a large VHD file after the compaction process.

A higher success rate was achieved by installing a small app package called secure-delete. To install and use this issue the following commands from a shell.

apt-get install secure-delete
sfill -f -z /

While I have realised better results from this, the process takes far longer as the secure-delete packages sfill is in fact performing an “insecure” erase on the hard drive, not simple zeroing sectors. This means that it actually passes over the disk more than once, with the concluding pass being the zero pass. The cumulative effect of the multiple passes means that it takes far longer to complete. The last time that I ran with this method, a 16 GB Debian 6 VHD was reduced by 1.2 GB. Small change given the size of today’s hard drive, but a significant percentage of the 16GB disk none the less.

Please also note that there are other elements to the secure-delete package, including tools to wipe the SWAP partition (which may further reduce the size of the VHD if used) as well as tools to perform a full, secure disk erase (not just empty sector erasing). So do ensure that you use this package carefully.

Windows Vista under Microsoft Virtual PC 2004 SP1 – Installing using the ISO as the installation media

System Requirements:

  • Virtual PC 2004, SP1
  • Windows Vista DVD-ROM ISO

The Problem:

It’s very nice of Microsoft to make the ISO available to so many people for testing, and I hate to think how many downloads and DVD burns that will equate to – though I shant dwell on the fact it took 3 download attempts to actually get the thing, the first keeling over at a robust 89% before the Akamai server decided it didn’t want to resume and reset the file stream to 0%, and the second a hearty 71% before I was graced with the same announcement.

What if you either don’t have access to a DVD Burner, the test PC you plan to install on has a DVD drive that doesn’t accept the burn media from the DVD-Writer (like me) or you just don’t like wasting Disc’s on one hit wonders (like me).

In amazing thoughtful form, the Virtual PC ISO mount driver cannot seem to address ISO’s over a couple of GB, handy when a Vista ISO weighs in at 3.12GB. So here’s a nice 100% Microsoft way to get aroung the problem.

The Fix:

When I was working on Windows 2000 SP4, SP4 URP and on the short lived Windows Security CD beta’s, Microsoft introduced a nice MFC utility to the beta core to instill a sense of environmetntal responsibility in us – after all we were getting weekly builds.
The Virtual CD Control Panel Driver application is a ISO mounter in a stand-alone form running at the driver layer (VCdRom.sys), with no resident applicaiton layer (aside from the service start/stop/mount MFC application). Unlike its counterpart in Virtual PC, it isn’t restricted to the size of the volume it can mount – at least any ISO I have ever tried.

The driver identifies itself to Windows as a de facto Optical drive, complete with drive letter. The short answer to the problem is that the Virtual PC Physical drive mounter doesn’t actually care what it is mounting so long as it is identified as an optical drive. By piggy-backing the ISO through the VCdRom driver, you can get around the limitation’s of Virtual PC.

The Virtal CD Control Panel runs under any NT 5 based OS, is completely free and is a Microsoft application – be it an unpolished one.

Download: Virtual CD Control Panel 1.21

The VCdRom driver is naturally a software based solution, as a result there is bound to be a nominal impact on performance, however in the greater scheme of VPC2004 performance hits, it is indistinguishable from a pre-Additions installation of any OS.

When mounting one of the formal beta ISO images, you will encounter an error message stating that the mount failed with the driver. Under these conditions, the most likely culprit is the literal name of the ISO. As an Exmaple the Public Beta 2 release ISO is catchily named:

A 67 character file name, or a nice round 536-bit ASCII string with a couple of periods thrown in for good measure. The simple fix: Shorten it and drop all but the suffix identifier period. Vista.iso will do nicely in the event you cannot think of anything creative.

Preventing Virtual PC’s obsession with “My Virtual Machines”

System Requirements:

  • Virtual PC 2004, SP1

The Problem:

Virtual PC 2004 ritually insists upon creating the a “My Virtual Machines” directory beneath your user profiles My Documents root, even if you have previously deleted this folder and frequently set the ‘working’ path to another location while in the file browser.

If you wish to store your VMC and VHD data elsewhere on your system or network, you must manually specify the full path to the Virtual PC Console each time you make configuration changes, as well as delete a new instance of My Virtual Machines.

The Fix:

This seems like a simple, yet typically Microsoft omission from the program – utterly defeating the idea of it being “My” Documents in favour of whatever Microsoft, Adobe, BVRP etc want to make it.
Most applications store working path information in the registry’s Current User settings, Virtual PC has, however been hard coded with its user profile paths, making non of the traditional registry keys beneath the Current User Software hive.

There is, however a way around this limitation, as presented cryptically in the readme.htm; which states:

MYVIRTUALMACHINES environment variable controls the default location where new Virtual Machine Configuration (.vmc) files are created
By default, Virtual PC creates the virtual machine configuration files (.vmc) in My Documents\My Virtual Machines. Virtual PC then stores other files that are used by the virtual machine in the same folder as the .vmc file. This is controlled on the host operating system by the MYVIRTUALMACINES environment variable. You can change the MYVIRTUALMACHINES environment variable to a different location. For more information on how to change environment variables, consult the documentation included with the version of Windows on which you have installed Virtual PC 2004.

What this is saying, in case you’re don’t happen to have a MCSE, is that as a counter measure, Virtual PC will screen for the presence of a Shell Wide configuration pointer (Environment Variable) defined as MYVIRTUALMACHINES.
Ever seen, for example, “%SYSTEMROOT%” or “%TEMP%” pop up before in Windows? They are environment variables specifying where the Windows folder (Q:\Windows\) and global Temp folder (N:\Eccentric\Folder\Naming\Temp\) are.

The Environment Variables are considered constants, and not likely to change – if indeed they will ever change. Administrative privileges are required to set or unset an environment variable, lacking the susceptibility of the registry. As they are global, they will already be considered active no matter who is logged into the system (unlike with Current User Registry settings) and unlike with Local Machine Registry settings, are globally available to anything looking for %MYVIRTUALMACHINES%. Saving the system or VPC drivers from specifying access to reams of registry hive to get to the desired few bytes of information.

There are two ways to set an environment variable.

Using the GUI:

  1. Pull up the Control Panel
  2. Run the System Applet
  3. Open the Advanced Tab
  4. Choose Environment Variables…
  5. Under System Variables click New…
  6. In the Variable Name enter:
  7. Under Variable Value enter the Full System Path to your new MVM root e.g.
    D:\Virtual PC\Images\

Exit and restart Virtual PC for the change to become active under Virtual PC.

Using the Registry:

  1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
  2. Create a new String value named:
  3. Set the value to equal the Full System Path to your new MVM root e.g.
    D:\Virtual PC\Images\

If you set the variable by hand in this fashion, you may need to log off before the change is recognised by the system.

Once you have added the system environment variable, Virtual PC will stop creating the My Virtual Machines folder beneath My Documents, and will default file system browser windows to the new MYVIRTUALMACHINES path.

Running Mozilla Firefox under Windows NT 3.51

Windows NT 3.51 users have had access to Microsoft browser technology on the same release schedule as Microsoft browsers for Windows 3.11. Unfortunately Microsoft’s logic with NT 3.51 (a 32-bit operating system) was to restrict web browser installations to 16-bit client releases.

The result of losing these 16 extra bits of power? The browser runs at half pace, is exceptionally slow and is limited in its execution space. One must conclude that this artificial restriction was the results of a drive towards forcing people over to Windows NT 4.0, rather than for any pragmatic reason.

One thing that it is very easy to forget when absorbing yourself in the Program Manager driven interface of 3.51 is that 3.51 is a 32-bit operating system, and that crucially it has more in common with Windows 95 and NT 4.0 than Microsoft ever allowed it to take credit for. Subsequently it is often possible for it to run code designed for higher windows versions; particularly code not bolted together using Microsoft’s latest IDE runtime mishmash. Open Source Mozilla Firefox is one such example.

Firefox 1.5

Firefox on 3.51

At the time of writing, the latest build of Firefox is (pictured above). Interestingly, looking at the user agent string, Firefox is even able to identify itself as running under Windows NT 3.51 – though this is likely from the registry rather than a hard coded variable.


Even Firefox themes work as expected under the release, here showing a Luna theme and a minor level of distortion.

Firefox Themes


Finally, for those who get a little crazy about such things. Even tabs work under 3.51.

Firefox Tabs

What doesn’t work

Unfortunately, the sweet delights of a 32-bit browser are overshadowed by a few minor (I say minor…) issues.

  1. Firstly, the installer does not work under 3.51. It will inflate the data store, begin running setup.exe and then drop the process without the slightest hint of an error. Even if you perform the inflation for it, it still drops out unannounced.
    I have found that you can get around this by installing Firefox onto another Win32 NT based system and copying the entire Firefox installation path over to the machine, or run firefox over a network share
  2. Windows NT 3.51 lacks common runtime controls and dialogue menus. As I said above, it’s Microsoft’s IDE and API set which causes programs not to run under 3.51, and control dialogues are an exception in the Firefox build. In the absence of commdlg controls, firefox cannot render any of the shell menu’s which we all know and love from Windows 95 and above. Consequently, displays such as the file system navigators wont display
  3. As a side effect of the above, the downloads control doesn’t work as you cannot browse for a download location and under 3.51 the default “desktop” does not exist. You can change the default download locations by adding the following into perfs.js found somewhere under C:\WinNT35\Mozilla:
    user_pref(“”, “C:\\builds\\04182006\\INS\\unix\\EN”);
    user_pref(“”, “C:\\builds\\04182006\\INS\\unix\\EN”);

    Unfortunately, I have not been able to get the downloads system working at all.
  4. The above makes getting hold of extensions such as Macromedia Flash somewhat harder
  5. You need to click on hyperlinks twice