Page 1 of 3

Cloning a VM with multiple snapshots?

Posted: 8. Jul 2007, 13:00
by RSeso
I have a VM (Windows 2003 Server) which has three snapshots and would like to create a new VM by cloning the most current state (== the state of the latest snapshot). However, "VBoxManage clonevdi" only allows me to clone the base vdi, I cannot clone the snapshots.

Is there any way to do this without having to first discard/merge all the existing snapshots? I'd really like to keep the original VM as-is (with snapshots) and create a new VM using the current state.

Thanks, Robert

Posted: 13. Jul 2007, 12:07
by loan
I have the same question. It is not confortable to merge all snapshots, which in most cases are different stages of a VM. I do the following as a workaround.
1) Copy the vdi files (base disk AND snapshots) to a tempdir
2) Copy the Virtulabox.xml file from your UserProfile to a tempdir (very important!!)
3) Merge all Snapshots to one base vdi
4) Clone that vdi with VBOXMANAGE to generate a new vdi with a new UUID.
5) Delete the original merged vdi
6) Copy the previous copied files (all) back to their orignal(!) location
7) Create a new VM in the VB-Gui and attach the merged and cloned vdi as the primary disk.

Lot of work, but i didn't find annother way and i know that the snapshots for the new VM are lost but in most cases they are not important for a copy of a VM. Maybe innotek will enhance the clonevdi to support snapshoted vdi's in the future.

regards
Andre

Posted: 16. Jul 2007, 19:43
by RSeso
Hi Andre,

thanks for your comment, that's basically what I did at the end as well. That said, I also hope this feature makes it into one of the next upgrades, since all cloning does is changing a few UUIDs along the way, so I don't see why that should be limited to a single VDI.

best regards, Robert

Posted: 17. Aug 2007, 17:08
by skibum
Yes, this topic is very much on point. I want to roll my snapshots up into my current one, not roll them back to the original.

I'm running Ubuntu on a Sony Vaio notebook hardware, with XP in a VBox. I've tweaked the XP to where I need it to be, using a snapshot before every tweak.

So now XP is where I want it to be, but unfortunately I have no more room left on my hard drive to accomplish this workaround.

This is because the bloody snapshot footprints are every bit as big as the original install. There's no way I can copy my whole snapshot tree (7 deep, over 10gig) to a temporary directory in order to roll the snapshots up into a single smaller clone.

Now I have to go find my external HD.

I look forward to the "clone the latest snapshot" button.

skibum

Cloning the latest snapshot

Posted: 17. Aug 2007, 22:31
by skibum
To the problem of "clone your latest snapshot" I found the solution using just the GUI, with no file problems, copying, messing with vmi / xml / UUIDs etc.

It was hinted at in Michael of Innotek's May 10 2007 post at
http://forums.virtualbox.org/viewtopic.php?t=659

My setup is Ubuntu running on Sony Vaio notebook hardware, with XP in a VirtualBox.

I had nursed my XP forward through a series of software installs, to get it to where I needed it to be. Prior to every install I would take a snapshot, knowing that installing different types of software on XP often creates multiple problems.

I finished with my installs, and found myself nested 7 deep in my snapshot sequence. In VMWare, I would now clone this snapshot in order to consolidate the changes and finalize it as my XP utility OS.

So how to clone the latest snapshot? The instructions weren't clear, and neither were all the threads on cloning.

1. The clonevdi command line utility appears from other threads to only work on the base installation. This would wipe out all my tweaks. Not an option.

2. Others suggested copying vdi's, xml, etc. While backup copying never hurts, I didn't want to face a mess of out-of-whack files, a problem noted in other threads.

3. There was no straight answer. However, the post noted above states that discarding a snapshot, and NOT THE EXISTING STATE, would preserve the current state of the Box. This is not clear from the GUI, and discarding a snapshot with a lot of work that's gone into it is a scary thought.

I had no more hard drive space to try the copying technique noted in this thread. This was largely due to the fat snapshot footprints (I was shocked when I saw them all, they were in the .VirtualBox hidden directory). So I changed the desktop background, exited XP, went up 2 rungs in my snapshot tree to an earlier shot, crossed my fingers / toes / all other appendages, and clicked on "Discard the Snapshot". The program proceeded in copying changes between snapshots.

After it finished (I noticed that one of my fat snapshots disappeared from .VirtualBox) I went back to the lowest, most latest rung on the tree, started XP, et voila, my tweaked XP was 100% there, available, and functioning, including the incremental change in desktop backgrounds.

I proceeded to prune my snapshot tree of all branches in between my original XP install, and my fully tweaked production utility install, occasionally starting XP to check and make sure I wasn't losing anything. Everything discarded like it was supposed to, and it was gratifying to see the fat snapshot files disappearing one by one. I can now roll back to a spanking fresh XP install if I have to, or go to my production XP, and I've recovered 30% of my HD space from snapshots I no longer need.

Innotek this is a great product, but I expect that I'm not the only one wanting to clone the latest, not the earliest. Using the term "Discard" in your Snapshot manager context menu is not enough information to make a decision on. I would add an alert box on making this choice that says "Discarding your snapshot will not disturb your existing state", or something to that effect. It is a more accurate description of what happens, and users won't need to parse the forums to figure it out that this is how you "clone" your latest state.

So I can breathe again. Now I need to find a slope.

Skibum

Re: Cloning a VM with multiple snapshots?

Posted: 5. May 2009, 22:43
by dpursehouse
Hi. New to VirtualBox Forums, but been using VBOX for a good couple of years.

Totally agree with last couple of comments re cloning snapshot machines. I feel that the GUI is at least partly at fault here - a tree view where you delete the "higher" branches suggests initially that ones below it will also be deleted. If the GUI wre presented differently, it would help:

current state
----Snapshot (2)
----Snapshot (1)

You could then highlight snapshot2 for example and revert to this (hence discarding the current state) or you could remove snapshot (1) so that it leaves only current state and previous snapshot. Comment about a warning would also help - if user attempts to discard snapshot (2) for arguments sake, then a prompt saying "current state will be preserved, and snapshot (1) will also be preserved; it will no longer be possible to revert to snapshot (2) if you continue with this action" likewise, if Snapshot (1) is deleted, it will only be possible to revert from current state to snapshot(2)

Keep up the work Innotek (Sun?), I was a seasoned VMware worsktation user, but I have moved over to VirtualBox in preference of the licensing terms. A worthy competitor to the bigwigs out there... Thank You! Just please give us an option to "clone latest snapshot" (or an option to clone machine including all snapshots) I use snapshots all the time, and do not want to lose them.

Re: Cloning a VM with multiple snapshots?

Posted: 2. Sep 2009, 06:17
by lead09jae
Hi,

I've been having the same issues and i did the same thing as you guys did as well. Hopefully, things will be more advanced in the future.

Regards,
Jun
Regroupement credits

Re: Cloning a VM with multiple snapshots?

Posted: 15. Oct 2009, 08:02
by MarkCranness
As of 3.0.8 (or before) the VBoxManage clonehd command can clone any snapshot of a hard disk or clone the Current State of a hard disk.

The resulting VDI file is flattened (it does not have any other snapshots attached).
(It may be experimental or not stable, I can't tell. It worked for me cloning the Current State of one of my disks.)

You need to find the UUID of the Current State image file, or of the Snapshot image file (NOT the UUID of the snapshot!)
 Edit: I have a better way, described in the post below: See Below
To clonehd the Current State of a disk:
  • Use the VirtualBox Details tab to find which Hard Disk controller/slot your disk is attached to (if you have more than one slot).
    (In the example below, my disk is attached to controller IDE Primary master.)
  • Use command as below (replace "<Machine Name>" with the case-sensitive machine name):

    Code: Select all

    C:> VBoxManage showvminfo <Machine Name>
    ...
    Name:            <Machine Name>
    Guest OS:        ...
    IDE Controller:  PIIX4
    Primary master:  <path>.vdi (UUID: 73880a2b-ba46-459e-b71b-816ceadecb5a)
    
  • Note the UUID that corresponds to the controller/slot found above
  • Run clonehd to clone it!

    Code: Select all

    C:> VBoxManage clonehd 73880a2b-ba46-459e-b71b-816ceadecb5a CloneDisk.vdi
    
    
To clonehd a snapshot of a disk:
  • Use the steps above to find the UUID of the Current State image of the disk.
  • Open file <Machine Name>.xml, preferably in a tool (Internet Explorer works) that allows easy navigation of the XML file.
  • At the VERY BOTTOM, in the Storage Controllers section, find the UUID of the Current State and note the StorageController name=, type= and the AttachedDevice type=, port= and device= settings.
  • In the middle, find the snapshot you want.
  • In the Storage Controller section of the snapshot, find the AttachedDevice with the values (name/type/type/port/device) that matches the values retrieved above.
  • That image UUID identifies the Snapshot image for the hard disk. Remove the {} brackets, and:
  • Code: Select all

    C:> VBoxManage clonehd <UUID> CloneDisk.vdi
    
    

Re: Cloning a VM with multiple snapshots?

Posted: 29. Oct 2009, 20:34
by hankyknot
Mark, you are my new hero. Its a shame the manual doesn't give a sample of the Syntax for the clonehd command.

Two questions I do have though;

Firstly does the Virtual Machine have to be stopped in order to clone the drive? Im assuming it would but we know what that does.

Secondly, is there any reason why the output path for the clone couldn't be a networked drive?

Re: Cloning a VM with multiple snapshots?

Posted: 29. Oct 2009, 23:52
by MarkCranness
hankyknot wrote:Two questions I do have though
:roll: Well try it and see!
The answers are: Yes the VM must be stopped, and Yes a network share is OK.

Re: Cloning a VM with multiple snapshots?

Posted: 30. Oct 2009, 02:19
by hankyknot
Didn't want to do that in case is screwed everything up, so cross everything and lets give it a try

Re: Cloning a VM with multiple snapshots?

Posted: 31. Oct 2009, 12:55
by MarkCranness
As of 3.0.8 (or before) the VBoxManage clonehd command can clone any snapshot of a hard disk or clone the Current State of a hard disk.

The resulting VDI file is flattened (it does not have any other snapshots attached).
(It may be experimental or not stable, I can't tell. It worked for me cloning the Current State of one of my disks.)

You need to find the UUID of the Current State image file, or of the Snapshot image file (NOT the UUID of the snapshot!)

To clonehd the Current State of a disk:
  • Open the Virtual Media Manager (Menu: File>Virtual Media Manager).
  • Navigate to the hard disk you want to clone and fully expand the tree (use * key on numeric keypad).
  • Find the {hexUUID}.vdi file that is attached to the VM you want to clone the Current State of.
    It will be (one of) the leaf files at the end of a branch.
    When you select it, the 'Attached to:' text at the bottom of the window will say:
    'Attached to: <VMName>', without any (snaphot name) in brackets after it.
  • Click the filename to the right of the 'Location:' displayed at the bottom of the window.
  • Ctrl+C / Copy to copy the text to the clipboard, which will be something like:
    (path){b6441469-5ccb-418c-8fdd-73c5e1a17314}.vdi
  • Ctrl+V / Paste and extract the hexUUID value (removing the {} brackets) and run clonehd to clone it!

    Code: Select all

    C:> VBoxManage clonehd b6441469-5ccb-418c-8fdd-73c5e1a17314 CloneDisk.vdi
    
To clonehd a snapshot of a disk:
  • Open the Virtual Media Manager (Menu: File>Virtual Media Manager).
  • Navigate to the hard disk you want to clone and fully expand the tree (use * key on numeric keypad).
  • Find the {hexUUID}.vdi file that is attached to the VM (and Snapshot) you want to clone.
    It will be one of the files along a branch.
    When you select it, the 'Attached to:' text at the bottom of the window will say:
    'Attached to: <VMName> (<SnapshotName>)', with (snaphot name) in brackets after it.
  • Click the filename to the right of the 'Location:' displayed at the bottom of the window.
  • Ctrl+C / Copy to copy the text to the clipboard, which will be something like:
    (path){75bd6ab1-ce25-4b56-aa39-7826c9ebcc93}.vdi
  • Ctrl+V / Paste and extract the hexUUID value (removing the {} brackets) and run clonehd to clone it!

    Code: Select all

    C:> VBoxManage clonehd 75bd6ab1-ce25-4b56-aa39-7826c9ebcc93 CloneDisk.vdi
    

Re: Cloning a VM with multiple snapshots?

Posted: 17. Mar 2010, 16:24
by Vadi
Thanks, that worked great.

Re: Cloning a VM with multiple snapshots?

Posted: 28. Jun 2010, 04:50
by Corey Murtagh
I recently flattened a VM to clone it, and this went well thanks to posts in this forum.

What I wanted to do however was retain the snapshots of the pre-clone VM, so I made a copy of the VM's folder and restored this after the clone was up and running... and yes, this restored backup failed to load as none of my snapshot VDIs were registered with Virtual Box.

Since I really wanted those snapshots I dug around and found out how snapshots are stored in the VirtualBox.xml, then dug into the VDI files to find out where and how the UUIDs are stored. Took a couple of hours to rebuild the list, using some VBA code in an excel spreadsheet (no, I don't have any decent devel tools on that machine) to extract the UUID data from the snapshots.

I've attached the Excel file for those that might find it interesting. It is an XLSM file, so please be careful how you open it... always do a virus scan before using these things!!!

To use: open the file in Excel 2007 (or higher), press Alt-F11 to go to the Code editor, press Ctrl-G to go to the Immediate window and type the following:

Code: Select all

MakeHDList "(path to your Snapshot directory)"
The function will scan all VDI files in the specified directory, build a dependency tree and the print the XML HardDrive tags to the Immediates window. Copy this to your VirtualBox.xml file in the appropriate place and fix the disk entries with ??? in the location (filenames not available from the snapshot VDIs) and you should be good to go.

I only spent a couple of hours on it, so this isn't a fantastically robust or elegant solution. Might be useful for anyone who needs to restore a backed-up VM where the original VirtualBox.xml file is not available.

Please note:this isn't going to let you clone machines with snapshots. I'm sure someone can build a utility to do just that, with the right amount of effort. Personally I think Sun need to handle that side of things by adding functionality to VirtualBox.

Re: Cloning a VM with multiple snapshots?

Posted: 28. Jun 2010, 14:04
by mpack
Corey Murtagh wrote:I recently flattened a VM to clone it, and this went well thanks to posts in this forum.

What I wanted to do however was retain the snapshots of the pre-clone VM
Urm... why?

I don't necessarily want you to answer, just consider the question carefully. Is it just the comfort you get from knowing that you can restore the VM to any (saved) point in time? If so, then you can get the same result by simply backing up the VDIs from those same points in time. Yes, this takes a minute or two longer to do, but the result is far more secure and useful - and can take less disk space too (depending on where you put the backup copy).