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.

Installing Windows NT 3.51 under Virtual PC 2004 SP1

This document outlines the steps required to install Windows NT 3.51 Server or Workstation under Microsoft Virtual PC 2004 SP1.



  • Windows NT 3.51 Server / Workstation
    This guide assumes that the installation source is an original NT 3.51 Gold (RTM) source and does not include any Service Pack revisions. If the source is slipstreamed with a Service Pack some steps outlined in this document may not be required.
  • The guide assumes that you are installing 3.51 into a new Virtual Machine, and not as a dual boot.
  • Windows NT 3.51 SP5 – Available from the Microsoft FTP Server (12.7MB).


Windows NT 3.51 can be installed from either a CD, or from the local filing system using the WinNT Setup sub system. For the benefit of readers in this article, the primary focus will be on performing the installation using WinNT Setup rather than a CD.


Prepare the Virtual Machine using the New Virtual Machine Wizard

  1. Create a new Virtual Machine
  2. Set the Operating System as Windows NT Server
  3. Select a custom RAM level and set it no higher than 64MB of RAM. It is important that the RAM allocation does not exceed 64MB during the Install process, however it can be increased after installation.
  4. Create a new Virtual Hard disk, with a minimum size of 400MB. Leaving the setup defaults as a dynamically expanding volume is recommended.


Installing from the CD/Floppy Disk Set

If you intend to install from a CD ROM you will require the NT 3.51 Setup boot floppies. I have created Virtual Floppy Images of the disks for use with Microsoft Virtual PC which you can download below.

Download: NT 3.51 Virtual PC Boot Disks (1.5MB)

  1. Boot onto the first two floppy images
  2. Press Enter to install Windows NT 3.51
  3. Select C to perform a custom installation
  4. Boot from the third floppy image
  5. Ensure that setup has detected the CD Drive as:
    IDE CD-ROM (ATAPI 1.2) / Dual-channel PCI IDE
  6. Press Enter to continue
  7. When prompted either select “To install Windows NT from CD-ROM, press ENTER” if you are installing from the CD or “To install Windows NT from 3.5″ disks (drive A:), press A.” if you are using a floppy disk installation set.
  8. Setup your Installation options, ensuring that 3.51 is setup as a “Standard PC“. Perform the setup using the VGA or Compatible display adapter
  9. At the partition manager setup the physical volume onto which you wish to install Windows NT. You cannot create a drive volume using the default NTFS driver up to the 8GB limit. It is recommended that you create a volume of 4096MB (4GB) to install the operating system onto.
  10. It is recommended that you format the partition as NTFS
  11. Select the Windows Folder for the Install and press enter
  12. Insert your Windows NT 3.51 CD and begin the file copy process. Once complete setup will reboot into GUI mode setup


Installing using WinNT.exe

If you are having problems with the CD based setup, or you wish to perform the installation using a local system file copy, you must use the 16-bit WinNT setup command line routine.

You will need a MS-DOS startup disk containing FDisk, Format and SmartDrive (recommended) and a mathod of transfering the i386 folder of the Windows NT 3.51 Setup CD onto a Virtual Hard drive

  1. Boot onto the MS-DOS boot disk
  2. Run FDisk
  3. Create a new Primary Partition up to the maximum allocation ont he virtual hard disk
  4. Create a new Extended partition on the same drive of a minimum of 300MB
  5. Create a new Logical volume within the extended partition of the maximum size
  6. Exit FDisk and reboot back on to the MS-DOS boot disk
  7. Format C: as a FAT16 disk partition (The size can only be up to 2GB)
  8. Format D: as FAT16
  9. You must now copy the i386 folder of the Windows NT 3.51 Setup CD onto the D: partition. You can do this by mounting the VHD as a secondary drive in another Virtual Machine (e.g. Windows 95, Windows XP) and copying the files over -or- by using a Boot disk with CD ROM support and manually copying the files into a sub folder on d: (as the number of files in the NT 3.51 setup folder is upwards of 1,800 files you must copy them into a sub folder. FAT16 has a file limit of 512 unique file objects on the root folder)
  10. Boot back onto the MS-DOS boot disk
  11. Load SmartDrive (Recommended)
  12. Open (‘CD’) the folder on D: where you copied your setup files. For the purpose of the remaineder of this guide D:\i386\
  13. Type:
    winnt.exe /s:D:\i386 /x /b
  14. The setup file copy process will begin
  15. Once the file copy has completed your will be prmoted to reboot your computer. Dismount any VFD images you are running and remove all floppy disk from your drive.
  16. NT 3.51 will begin booting. This first bootup will take longer than normal boot processes
    Blue screen of... life!
  17. If at this point the system runs into the STOP error:
    KMODE_EXCEPTION_NOT_HANDLED Address 801adcac has base at 80100000 – ntoskrnl.exe
    Blue screen of death
  18. The error message is caused because of two reasons
    1. Firstly because setup has incorrectly determined that the Virtual PC system is not a general IBM compatible x86 PC. In order to continue with the installation you must force the WinNT Setup application to run as a IBM Compatible PC.
    2. Additionally, setup may halt at this point if you are using more than one VHD (Virtual Hard Disk) file to access your NT 3.51 setup/installation drives. In order to proceed you must close the Virtual PC and disable the second Hard Disk.
  19. Reboot the system
  20. Immediately after this screen:
    Inspecting hardware configuration
  21. Begin pressing F5 twice a second
    NB: No dialogue prompt will be displayed to the user offering F5 as an option, so do not wait until you see the blue screen
  22. If you were fast enough you will be presented with this screen;
    Computer type
  23. Select Standard PC
  24. Press Enter to install Windows NT 3.51
  25. Select C to perform a custom installation
  26. Ensure that setup has detected the CD Drive as:
    IDE CD-ROM (ATAPI 1.2) / Dual-channel PCI IDE
  27. Press Enter to continue
  28. Setup your Installation options, ensuring that 3.51 is setup as a “Standard PC“. Perform the setup using the VGA or Compatible display adapter
  29. At the partition manager setup the physical volume onto which you wish to install Windows NT.
    You must not attempt to delete the C:\ volume of the hard disk, otherwise setup will fail completely. If you wish to add additional drives at this point you can do so.
    If you wish to resize the partition in the future, use disk utilities such as PowerQuest Partition Magic after you have applied SP5.
  30. It is recommended that you specify to convert the partition to NTFS
  31. Select the Windows Folder for the Install and press enter
  32. Windows NT 3.51 will reboot the setup program and boot onto the Windows NT subsystem GUI mode setup at this point in the installation

Installation complete

Before attempting to make use of NT 3.51 it is strongly recommedned that you install Service Pack 5 so as to benefit from update which will considerably stabalise the Kernel under Virtual PC.

Additional Installation Tasks

Windows NT 3.51 Driver Installation

Windows NT 3.51 Workstation Patching & Installation Guide (maintained by me)