9

I have a virtual machine with about 30 snapshots in branches. The current development path is 22 snapshots plus the base disk. The amount of files is seemingly having an impact now on IO and the dev laptop I'm using (don't know if it is host disk performance issues with the 140GB total size over a lot of fragments, or just the fact that it is hitting sectors distributed across a lot of files).

I would like to merge the current development branch of snapshots together with the base disk, but I am unsure if the following command would produce the correct outcome. I am not able to boot this disk after the procedure completes (5-6 hours).

vboxmanage clonehd "C:\VPC-Storage\.VirtualBox\Machines\CRM\Snapshots\{245b27ac-e658-470a-b978-8e62137c33b1}.vhd" "E:\crm-20100624.vhd" --format VHD --type normal

Could anyone confirm if this is the correct approach or not?

  • To add some information, the error I am getting is not a VirtualBox error, but a boot error from Windows. It wants to launch startup repair, but as I don't know the error, I don't know the fix. Starting windows normally results in a long wait and a blue screen. Is this expected or have I used the wrong method when cloning the disk? – Henrik Jun 24 '10 at 11:15
  • I've used VBoxManage (on Windows host, Ubuntu guest) as you've suggested in your question and it did properly merge the snapshots into the single output disk image – Chaulky Dec 6 '12 at 4:13
  • 1
    Yes this is a correct approach. It's better to specify just the source UUID instead of its file name, then you're sure VBox will be able to resolve the attachments. – rustyx Mar 30 '13 at 14:55
7

What you want to do is from the snapshots dialog, select your parent snapshot that you want to merge all snapshots afterwards to a single VDI.

From your description it sounds like this is the root of the tree.

Right click and select 'Delete Snapshot'.

This will do what you want --- it will merge all the changes from all child snapshots into a single VDI.

Additionally - cloning the disk image that is in the latest snapshot - will also merge the differencing disk with its parent (and its parent, so on, until you get to a 'normal' hard disk type).

I suspect that 'deleting a snapshot' runs the clonehd command.

Check your VM settings (specifically IO APIC enabled/disabled) and make sure they match.

  • I guess this is currently the only way to do this, however it is a manual, time consuming, multi click in GUI way to do it. – Henrik Aug 27 '10 at 13:50
3

If you only want to keep a single snaphot, make it your current state & then export the VM & re-import it. Exported appliances don't retain their snapshot history.

Or you could use this vboxmerge.py script to handle the merging for you. Given the number of snapshots you have, I would expect the export/import cycle to be quicker.

2

Here's a technique (tested on VirtualBox 4.3.4) that uses the 'Clone' command to merge and compact all the snapshots to a new VM containing a single VDI file:

  1. Rename the VM so you can reuse its current name for cloned VM (you can change the VM name from the 'Basic' tab of the 'General' settings).

  2. Right-click on the VM and run the 'Clone...' command:

    • Set the name to the VM's original name.
    • Accept the remaining defaults i.e. Clone type: 'Full clone'; Snapshots: 'Current machine state'.
  3. Delete the old VM (right-click on the VM and run the 'Remove...' command).

0

If your host is a Windows or you can access VHD files from a windows there is a trick to MERGE all changes into parent, grand-parent, etc.

It is using DiskPart tool and the two commands:

select vdisk file="whatever your file is, with full path"

merge vdisk depth=#

Where # is the number of hierarchy levels you want to move, 1 for dirent parent, 2 for grand parent, etc.

It does it in-place, much less time consuming than cloning, etc.

Remember, after merging all intermediate VHDs can be deleted (it does not delete them for you) and do not forget to attach into VirtualBox that parent where you merged.

Example:

Disk3.vhd is child of Disk2.vhd, Disk2.vhd is child of Disk1.vhd

If you want on Disk1.vhd all changes of Disk3.vhd just use depth=2 and select Disk3.vhd. If you want on Disk1.vhd all changes of Disk2.vhd just use depth=1 select Disk3.vhd.

Also remember there is no need for ugly VirtualBox Snapshots, you can use DiskPart create vdisk command to create a differencing disk from an existing one (that can also be a differencing disk, etc), also can create a huge tree.

For all the rest: The poster is using VHD (not VDI) so can use native tools like DiskPart and Disk Managment to access that disks out of the Guest (on the Host, if Host is Windows).

For you, the poster: Remember to allways have a full BackUp prior to Merge, VirtualBox clone does not work in place, it creates a new file (copy on write), but DiskPart merge works in place (modify the file, do not create a new one).

Hope that can give another different aproach since VHD/VHDX is in use (not valid for VMDK, VDI, etc, only for Windows Host).

Note: Windows 7 and Up, XP and Vista can mount VHD with an external M$ tool but DiskPart has no VHD support on XP & Vista... all this also works on Windows HOME editions (7 and Up), no need for a SERVER edition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.