Shrinking a VHD image not working

Discussions related to using VirtualBox on Windows hosts.
Post Reply
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Shrinking a VHD image not working

Post by SergioTorresC »

I run VirtualBox 3.0.6 on a Windows Vista 64 host. I have a MS Virtual PC VHD file.
I want to shrink it and create a VirtualBox machine with it. I used virtual Media Manager and added the vhd file to it. I did not attached it to any of my existent virtual PCs. I tried to use vboxmanage clonehd to create an optimzed copy and I got an error message:
vboxmanage clonehd D:\MyVM\TheVirtualGrandMother.vhd D:\SunVirtualPCs\TVGM.vhd --format VHD
VirtualBox Command Line Management Interface Version 3.0.6
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
0%...FAILED
Error: failed to clone hard disk. Error message: Could not create the clone hard disk 'D:\SunVirtualPCs\TVGM.vhd'
(VERR_INVALID_PARAMETER)

I tried several versions of the command:
vboxmanage clonehd D:\MyVM\TheVirtualGrandMother.vhd TVGM.vhd --format VHD
vboxmanage clonehd D:\MyVM\TheVirtualGrandMother.vhd D:\SunVirtualPCs\TVGM.vhd
I tried using the VHD uuid instead of the source file name and using different target paths.
I tried from a normal windows command prompt and from a windows elevated command prompt (running as administrator).
Always got the same error message.
I tried vboxmanage modifyhd and I got an error message:
D:\VirtualBox>vboxmanage modifyhd D:\MyVM\TheVirtualGrandMother.vhd --compact
VirtualBox Command Line Management Interface Version 3.0.6
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
0%...FAILED
Error: Compact hard disk operation for this format is not implemented yet!

Can anybody tell me what am I doing wrong?

Thaks,
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Shrinking a VHD image not working

Post by Perryg »

Error: Compact hard disk operation for this format is not implemented yet!
Pretty much says it all my friend! Compacting VHD files are not supported yet.

Are you trying to add the VHD to VirtualBox?
If so you need to make sure that the settings are correct (match what you had in VPC) and that the VPC additions are uninstalled.
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Re: Shrinking a VHD image not working

Post by SergioTorresC »

Thank you for your answer. I included the modifyhd command just to illustrate I had tried several ways and was not sitting for somebody to solve my problem. What I need help with is the error I get when I run the command (in the conditions and variants I mentioned in my first post)

vboxmanage clonehd D:\MyVM\TheVirtualGrandMother.vhd D:\SunVirtualPCs\TVGM.vhd --format VHD
Error: failed to clone hard disk. Error message: Could not create the clone hard disk 'D:\SunVirtualPCs\TVGM.vhd'
(VERR_INVALID_PARAMETER)

Yes, I wan to add my vhd file to a virtualbox virtual machine (thank you for the tips), but before doing that I want to shrink it. It was created in my first attempt at virtualization and I made it 60 GB (altough I am only using about 25% of it). I'd love to shrink it and then create a virtualbox virtual pc with it (When I back it up to my USB hard drive it takes forever).

Any ideas?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Shrinking a VHD image not working

Post by Perryg »

Not really. Since the compact (nor the clone AFAIK) will not work on VHD files yet I don't see a way to shrink/clone it. You can add it and wait for the compact feature to be implemented but that might be a few months away. We have a volunteer (mpack) that has created a program that works great on VDI files but he has not taken on the VHD format as of yet. Look at the the sticky in Windows hosts called CloneVDI. You can request it and see what he says.

As a side not I was able to use the VBox program to clone the VHD file that converts it to VMDK and create an OVF control file but this means that it must be loaded in VirtualBox first.
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Re: Shrinking a VHD image not working

Post by SergioTorresC »

In chapter 13 of the VirtualBox Help file (Known limitations) it says:

"Shrinking virtual disk images is limited to VDI files. The VBoxManage modifyhd --compact command is currently only implemented for VDI files. At the moment the only way to optimize the size of a virtual disk images in other formats (VMDK, VHD) is to clone the image and then use the cloned image in the VM configuration." (bold face is mine).

It seems that the clonehd should work for vhd files, but I can get it to work for me...
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Shrinking a VHD image not working

Post by mpack »

Perryg wrote:We have a volunteer (mpack) that has created a program that works great on VDI files but he has not taken on the VHD format as of yet.
I'm actually working on VHD read support right now. It shouldn't take very long to code. A bigger problem will be adequate testing, as I don't have access to a good selection of VHD files. I may have to release a new version with this as an "experimental feature".
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Re: Shrinking a VHD image not working

Post by SergioTorresC »

Thank you mpack! Let me know when you are ready to experiment!
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Shrinking a VHD image not working

Post by mpack »

I released a new version a few moments ago, the new version has experimental VHD read support. See the first message in the CloneVDI support thread.
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Re: Shrinking a VHD image not working

Post by SergioTorresC »

Thank you mpack!
I'll give it a try right now and will let you know how did it go.
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Re: Shrinking a VHD image not working

Post by SergioTorresC »

Don,

I read your release notes and tried to use your tool on my VHD file (52+ GB).

Unfortunately it gives me an error message saying "Source VHD corrupt - block map contains errors"

I opened the virtual machine with Virtual PC and it seems to be ok. (Windows XP Pro 32 loaded and there was no error message).

I'll try to use Virtual PC to create a smaller disk and let you know how it goes with the new disk.

Thank you for your work.
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: Shrinking a VHD image not working

Post by BillG »

I have just used the new version to create a a vm from a Microsoft .vhd file and it worked fine. Did you remove the VMAdditions before you cloned the .vhd? This is recommended when going from one virtualization product to another.

I removed the Additions, shut down the vm under VPC and used Clonevdi to create a vdi file from the vhd. This was Windows XP guest running under VPC 2007 R1 on a Vista Business host.

I copied the cloned vdi to a machine running VirtualBox under Windows 7 Pro. Created a new vm using the vdi file and it booted up fine. It did need to be activated again because of the "hardware" changes.

Very impressed! Straight-forward and efficient.
Bill
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Shrinking a VHD image not working

Post by mpack »

SergioTorresC wrote:I read your release notes and tried to use your tool on my VHD file (52+ GB).
Unfortunately it gives me an error message saying "Source VHD corrupt - block map contains errors"
That error message means (a) it's a dynamic VDI, and (b) the block map refers to blocks that are beyond the end of file. I saw that same message when I briefly experimented with split VHD files... before deciding not to support split VHD files (the VHD spec implies that support for creating these hasn't existed since VPC 2004).

Is it in fact a split VHD? This would be indicated by the presence of a main file <file>.vhd, then a bunch of extension files, i.e. <file>.v01, <file>.v02 etc. As I mention in the release notes, these all need to be merged into one VDI before I can process it. On Windows you can allegedly use the copy command to do this, but you would need to be very careful to list the input files in the right order, ie. I think the right command is "copy file.vhd+file.v01+file.v02<etc> /b bigfile.vhd /b", but it's not a command I've ever used, so you should probably google for copy command tips before trying it. If I were you I would put the command into a .bat file, that way you can edit it in a text editor, get it right before you let it rip.

Incidentally, if we are going to carry on an extended CloneVDI support discussion we should really do it in the CloneVDI support thread. I only feel able to answer Sergio here at all because it was Sergio's thread to begin with.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Shrinking a VHD image not working

Post by mpack »

Oops! Never mind, I found the bug. It didn't like VHD files >4GB. I've posted a bugfix version (v1.21). Would you like to try it again Sergio?
SergioTorresC
Posts: 15
Joined: 19. Sep 2009, 02:35
Primary OS: MS Windows 7
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Server 2003 and 7
Contact:

Re: Shrinking a VHD image not working

Post by SergioTorresC »

Sorry Don,

I did not receive communication from the forum you (or anyone) had answered (until 10 pm, and then I was gone).

I'll try the new version and let you now in the clonedvi support thread.
Post Reply