Home > It's A Bug, Windows, Windows 7, WinXP > How to fix the “Cannot attach the virtual hard disk …”

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

December 31st, 2009 Leave a comment Go to comments

… 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..

  • 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.

  • 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.

  • 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

  • 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.

  • Davide

    Thank you so much!

  • Douglas Hiser

    I ran the diskpart and shrunk the vhd size down to 120GB (confirmed by list volume) but when I mount it in vhdresizer, the min size is 149 GB which is larger than the original partition size. Any ideas?

  • http://blog.wisefaq.com Wisefaq

    Did the VHDResizer resize operation increase the volume size???

  • Oszy

    same problem here, Jason.
    Did you ever solve it ?
    thank you

  • Nick

    After I mounted it with Diskpart, I used the Disk Management in windows just so i could see things grapically. Helped me keep things straight since my local disk was the same size(with same partition sizes) as the VHD i was working with.

  • jon simpson

    Like a few others, when i loaded the vhd in vhdresizer the minimum size possible was larger than the vhd file itself (almost 1TB).

    so i mounted the vhd with diskpart then i ran disk management. and the hard drive had a 700gb raw partition on the end of it.

    once i deleted that partition i was easily able to shrink the vhd down to the minimum which was about 93gb.

  • Anonymous

    Thanks for this Dale! You saved my bacon today.

  • Guest

    I got the same error message, but for a different reason.  When I tried to access it through DISKPART, I got the following message:

    DISKPART> select vdisk file=”d:virtual Hard DisksKamikaze Hard Disk.vhd”DiskPart has encountered an error: The sector size of the physical disk on which the virtual disk resides is not supported.See the System Event Log for more information.There is no virtual disk selected.My virtual disk is only 6GB, but because it was located on a 8TB physical disk, it was unable to connect to it.  I copied it to my 120GB boot drive, and then both DISKPART and Virtual PC were happy.

  • Martin Bishop

    Hi everyone,

    Thanks for this guide, it did help me get an older Windows XP drive image resized to work with a Windows 7 virtual machine.

    I had the problem with the VHDResizer giving me a minimum size of 149 (the total disk size) even after performing the operations with diskpart.  What appeared to happen is that even though I shrank the main partition on the drive image, there was still an extra partition (probably system restore information) in the volume at the end of the disk.  So I went from the disk having:

    Data partition
    Data partition

    To:

    Data Partition
    Empty Space (created by the diskpart shrink)
    Data Partition

    I assume that VHDResizer saw the end partition and couldn’t handle resizing the disk.

    The solution is to mount the virtual disk using diskpart, go into the Disk Manager , find the virtual disk, and delete the final partition.  (Make sure this isn’t the main partition you resized, or some other partition that you actually need!)  Then the disk should look like:

    Data Partition
    Empty Space

    Unmount the disk in diskpart, load up VHDResizer on the image, and it should have the correct minimum value.

    Side note: My VHDResizer said that the minimum was 109, but I had to put in 110 in order to get the “resize” button to enable.

    Hope that helps.