How to fix the “Cannot attach the virtual hard disk …”

… to the virtual machine.  Check the values provided and try again.” error
Windows Virtual PC: Cannot attach the virtual hard disk to the virtual machine.  Check the values provided and try again.

It sucks as an error message.  Would it take too much programming effort to make it more meaningful Virtual PC team?

What does it mean?

It means you have a Virtual Hard Disk file larger than 127.5GB.  Which Virtual PC does not support.
You might have created this with the Microsoft Disk2VHD tool.
To confirm the “disk is too big” problem, open the Settings on an existing Virtual PC, and try to attach the drive:
The virtual hard disk image ... is too large for the IDE bus.  Make sure that all virtual had disk images connected to the IDE bus are not greater than 127.5GB

In other words, we’ve captured a 160GB hard disk, and Virtual PC won’t let us use it.

But we can fix it, it’s a two step process

First we use DiskPart, and then we use VHD Resizer.

1.DiskPart

DISKPART> select vdisk file=c:\users\dale\desktop\worktest.vhd

DiskPart successfully selected the virtual disk file.

DISKPART> attach vdisk

100 percent completed

DiskPart successfully attached the virtual disk file.

DISKPART> list volume

Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
----------  ---  -----------  -----  ----------  -------  ---------  --------
Volume 0     E                       DVD-ROM         0 B  No Media
Volume 1                      NTFS   Partition    100 MB  Healthy    System
Volume 2     D                NTFS   Partition    199 GB  Healthy
Volume 3     C                NTFS   Partition    265 GB  Healthy    Boot
Volume 4     F                NTFS   Partition    149 GB  Healthy

DISKPART> select volume 4

Volume 4 is the selected volume.

DISKPART> list volume

Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
----------  ---  -----------  -----  ----------  -------  ---------  --------
Volume 0     E                       DVD-ROM         0 B  No Media
...
* Volume 4     F                NTFS   Partition    149 GB  Healthy

DISKPART> shrink querymax

The maximum number of reclaimable bytes is:  106 GB (108636 MB)

DISKPART> shrink desired=40960 (Note: desired is the amount we want to prune of the image)

DiskPart successfully shrunk the volume by:   40 GB

DISKPART> list volume

Volume ###  Ltr  Label        Fs     Type        Size     Status     Info
----------  ---  -----------  -----  ----------  -------  ---------  --------
Volume 0     E                       DVD-ROM         0 B  No Media
...
* Volume 4     F                NTFS   Partition    109 GB  Healthy

DISKPART> detach vdisk

DiskPart successfully detached the virtual disk file.

DISKPART> exit

What we now have is a VHD file still sized at 149GB, but with a 109GB partition in it.  What we need to do next is resize the VHD to 109GB.

2. VHDResizer.

Use VHDResizer to resize your newly shrunk VHD file, in this example WorkTest.VHD

VhdResizer -enter the size of the disk you want to resize to.  Not greater than 127.5GB though. VhdResizer - resizing the VHD file VhdReziser - Processing complete

(yes, I picked a New Size larger than 109GB, I went for 120GB instead).

And finally…

Success!  It boots!
Windows XP Boots

This article might be useful as well:
Mount base and differencing VHD disks using Windows Virtual PC on Windows 7 x64.

To recap, the tools used were:
DiskPart (included in Windows)
Disk2VHD
VHDResizer

Bookmark and Share