59

I have vdi with quite a number of snapshots taken from it - say, 50 or 70 snapshots. I want to have one plain vdi with a current state. These snapshots take way too much disk space and are not needed as snapshots.

I know that if I call

VBoxManage clonehd thedisk.vdi thedisk-full.vdi
(50-70 times) VBoxManage clonehd {uuid-of-snapshot}.vdi thedisk-full.vdi --existing

I will get what I want. But it takes very very long time (more than 5 hours given my hardware and 16G initial disk size).

And, of course, I tried VBoxManage snapshot delete and it is strange: doesn't work on stopped machine, can fail on running machine and when it fails once, it will fail all subsequent calls.

Is there a way to make plain vdi from a number of snapshots - quicker?

$ VBoxManage --version
3.2.14r75509

(asked it on ServerFault but decided this place is more appropriate for this question)

3
  • The command your using is the command you want to use there isn't a faster way.
    – Ramhound
    May 3, 2013 at 10:51
  • What about exporting the whole VM? Will its vdi contain what i want? May 3, 2013 at 11:16
  • You should try it. In the end any other method is still going to take awhile because of the size of the Virtual Machine.
    – Ramhound
    May 3, 2013 at 11:25

5 Answers 5

62

Found the solution. It is as simple as the last step from the commands I wrote here. I.e.

VBoxManage clonehd fullpath/{uuid-of-last-snapshot}.vdi thedisk-full.vdi

So I should clonehd only the last snapshot, not every snapshot from the chain. And it is thousands percent faster.

The uuid can be found from VBoxManage list hdds | grep VmName | tail

In the GUI (on Windows), select the VM, select Snapshots from the top right, right click on the snapshot you want, select Clone..., and select Full Clone in the dialog.

5
  • thx but it doesn't work on my setup, it says the image would already exist. Did you forget the --existing?
    – Andy
    Apr 15, 2014 at 15:07
  • 3
    if you already have thedisk-full.vdi file on disk then please first change the name in command to something like thedisk-full-new.vdi. Apr 16, 2014 at 2:36
  • The fullpath needs to be the one that is registered in VirtualBox, of course. Symbolic links wont work, since VBox needs to look up all Snapshots
    – Andy
    Oct 26, 2014 at 20:47
  • not sure what does the tail do, do you mean "tail -1"?
    – eckes
    Oct 22, 2015 at 15:12
  • 3
    In VirtualBox 5, clonehd is deprecated and left for backward compatibility, use clonemedium instead. Dec 27, 2018 at 13:57
27

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

1
  • As of VirtualBox 6.0.8, this still works.
    – Paul Sturm
    Aug 29, 2019 at 15:11
3

You can try to export to OVF and then import back the generated file.

As explained here:

OVF cannot describe snapshots that were taken for a virtual machine. As a result, when you export a virtual machine that has snapshots, only the current state of the machine will be exported, and the disk images in the export will have a "flattened" state identical to the current state of the virtual machine.

As result you will have a cloned VM with the current state without other snapshots.

1
  • I ask about vdis because cannot export machine - it was broken (inaccessible state after host reboot), and all that I had was the bunch of VDIs - disk and about fifty snapshots. May 10, 2013 at 5:03
0

That operation means reading and writing very large files in the same physical disk. The only way you can speed that up is to put those files in different disks changing the paths in your VBoxManage command. If the machine has only one disk, you could use an external USB drive or even a disk in another machine via a network share (depending on the speed of your network)

1
  • 1
    Typically network is orders of magnitude slower than internal HDD interface, so this probably wouldn't make the process faster. May 8, 2013 at 10:55
-3

Some have 10Gib/s LAN, so it can transfer more than one gigabyte per second, so it will not be a bottleneck.

Some have 1Gib/s LAN, so it can transfer more than more than 100 megabytes per second, so it will not be a bottleneck (unless you have a really fast SSD).

Mechanical disks, when read & write on same disk at same time (or much fragmented), go down for near 20 megabytes per second, while on non fragmented only read or only write can go to more than 100 megabytes per second.

You tell about LAN be slower, but not about USB (2.0, not to mention 1.1 or 1.0) is much times slower.

What i would suggest would be: Use USB 3.1 Gen2 Type C or a eSATA / SATA / SAS

But allways: Use a second fast enough disk.

And allways: Cloning to another disk and the copy back the file is much faster that using only one of the disk unless it is a SSD or a hard disk with independent multi-head arms (they can read and write at the same time on two surface places, each head has its own arm, very expensive, about >9876€).

The best is to clone only the virtual hard disk of the state you want, then check it works, then RESTORE top level (will delete all the snapshots), then remove the HDD on storage and connect that new one.

So steps, to loose all old states on a no tree snapshots scheme:

  1. Clone from one hardisk to another one, avoid bottlenecks
  2. Create a new machine, connect that disk, disconnect it, configure it as inmutable
  3. Test it works (since it is inmutable) you will have the same state
  4. If you need it not be inmutable, disconnect it, change back to normal, etc
  5. Delete the old machine snapshots (RESTORE first)
  6. Delete the temporal test machine
  7. Copy back to the disk the virtual disk
  8. Attach the cloned disk

But allways have in mind, snapshots can be like a full tree, one node can have more than one child, each child can have more than one child, etc.

To work with trees of snoapshots, allways think on DELETE as deleting a node without affeting the rest of nodes (only loose that state, but not there rest, no parent and no child will be affeted, data will be merged on all the first sub level childs, so slow process) and on RESTORE as destroying all of its childs on all sub levels (loosing all states after that one you restore, it only deletes the files, so really fast process, just seconds).

That is!

P.D.: How horrible names VBOX gave to that two operations (delete just one node = DELETE; delete all child nodes on all sub levels = RESTORE)

1
  • Restore does not delete any snapshots, just the current (unsaved) state.
    – Melebius
    Apr 25, 2017 at 10:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .