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

On this day..

View CommentsHow to fix the “Cannot attach the virtual hard disk …”

  • Bruce

    Great job on the post.  Very helpful.  The only thing that I thougt was missing was a link to download the utilities.  I found someone else’s article that told me to shrink the volume by mounting it in Computer Management but then they left off the part about vhdresizer.  Needless to stay it still wouldn’t boot after completing their steps so I am running vhdresizer now and expect it to work when done.  Thanks again.

  • Dale

    Well Bruce, hopefully it’ll work for you.  And thanks for the suggestions.  I’ve updated the post to highlight the tools used.

  • Andrew Aitken

    Hi, good post it helped me alot but I had a slight problem when doing

    > LIST VOLUME

    It wouldn’t show the VHD.

    If you do

    > LIST DISK

    and then

    > SELECT DISK {VHD Disk Number}
    > ONLINE DISK

    It should then appear in the LIST VOLUME list.

    Hope this helps anyone with the same problem as me.

    Cheers

  • Jason R

    Dale, thank you so much for posting this. I have a vhd with 2 partitions, one of 100GB that is the drive i’m trying to create a VM from, and the 2nd partition is 49GB of empty space. When I try to use VHDresizer, it shows the min size is 149GB, which does not help me. I used the DISKPART to shirnk the 100GB partition down to 75GB. But when I use VHDresizer again, it still shows the min size is 149GB. Any insights? Thank you!

  • Dale

    VHDresizer would be looking at the disk, and not the partitions in it. You may be able to use the DISKPART COMPACT command to reduce the physical size of the file.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

blog comments powered by Disqus