Easy Cloning

Here you can provide suggestions on how to improve the product, website, etc.
eialbur
Posts: 1
Joined: 29. May 2008, 23:42

Easy Cloning

Post by eialbur »

I like VirtualBox better than VMWare ... EXCEPT you make it waaaayyy tooooo difficult to clone a VM. I want to have several 'base' VMs that I can copy and modify at will. With VMWare I can (depending on which version I've got) either hit the Clone button or just copy the files to a new location and import the existing machine. It appears that there are ways of doing it from the command line with virtualbox, but come on - why would I want to have to drop out to command line and run a whole series of commands when I can just click a button.

So far this is the only deficiency I've run across (aside from the occasional bug, but frankly it is a show-stopper).

Ron
Kite
Posts: 14
Joined: 25. May 2008, 04:25

Re: Easy Cloning

Post by Kite »

eialbur wrote:I like VirtualBox better than VMWare ... EXCEPT you make it waaaayyy tooooo difficult to clone a VM. I want to have several 'base' VMs that I can copy and modify at will. With VMWare I can (depending on which version I've got) either hit the Clone button or just copy the files to a new location and import the existing machine. It appears that there are ways of doing it from the command line with virtualbox, but come on - why would I want to have to drop out to command line and run a whole series of commands when I can just click a button.

So far this is the only deficiency I've run across (aside from the occasional bug, but frankly it is a show-stopper).

Ron
Can you explain that cmd line process or link to a tutorial?
I would also like to clone a VM.
JohnG
Volunteer
Posts: 77
Joined: 23. Feb 2008, 00:51
Location: Canada

Post by JohnG »

A VirtualBox "VM" consists of 2 files: the machine config file (machine_name.xml) and the virtual drive file (*.vdi). Using VBoxManage, you can clone a vdi file, but not the machine config file.

See chapter 8 in the Manual for more info on VBoxManage. Also, there's a set of steps - for clonevdi - posted in this thread (last post):
http://forums.virtualbox.org/viewtopic.php?t=6679
(this is for a Windows host)
jgkt
Posts: 1
Joined: 5. Jun 2008, 22:43

vdi file on different disk or partition

Post by jgkt »

Not being an expert, I spent a few evenings trying to clone a vdi file. Until I figured out you have to specify the path to the dvi file if it's on a different partition or hardisk!
Kite
Posts: 14
Joined: 25. May 2008, 04:25

Re: Easy Cloning

Post by Kite »

eialbur wrote:I like VirtualBox better than VMWare ... EXCEPT you make it waaaayyy tooooo difficult to clone a VM. I want to have several 'base' VMs that I can copy and modify at will. With VMWare I can (depending on which version I've got) either hit the Clone button or just copy the files to a new location and import the existing machine. It appears that there are ways of doing it from the command line with virtualbox, but come on - why would I want to have to drop out to command line and run a whole series of commands when I can just click a button.

So far this is the only deficiency I've run across (aside from the occasional bug, but frankly it is a show-stopper).

Ron
Why don't you make a batch file and then just fill in the blanks each time?
Quick temp fix.
rebus
Posts: 35
Joined: 2. Jul 2008, 17:43

Post by rebus »

I agreee ...
cloning a complete VB + disk
is a very usefull feature
and shoud be more friendly and immediate
samyantoun
Posts: 5
Joined: 9. Jul 2008, 23:20

Post by samyantoun »

Maybe this shell script can help:
http://samyantoun.50webs.com/virtualbox/clonevm/
NEKGuy
Posts: 4
Joined: 10. Jul 2008, 01:24
Location: Northern Vermont USA

The clonevm.sh script is handy and seems to work well.

Post by NEKGuy »

I downloaded the script an tried it out but it did have some problems. The fixes were quite easy and once made, things worked just fine.

Usage:
./clonevm.sh "Source Machine" "Clone Machine"

The updated clonevm.sh script is below....
------------------------------------------- cut here ---------------------------------------------------

Code: Select all

#!/bin/bash

############## Clone VirtualBox Machine ##############
# Written By: Samy Antoun                            #
# Usage:                                             #
# ./clonevm.sh "Source Machine" "Clone Machine"      #
# Limitation:                                        #
# Clone only VM that has ONE Hard Drive (hda)        #
######################################################

############## Functions

function ChkUtility {
    res=`which $1 | grep "no $1"`
    if [ "$res" != "" ]; then
        echo "\"$1\" is missing";
        exit 2;
    fi
}

function GetValue {
    Line=`VBoxManage -nologo showvminfo "$1" -machinereadable | grep "^$2="`;
    Raw=`echo $Line | cut -d= -f2`;
    Fixed=`echo $Raw | sed 's/"//g'`;
    echo $Fixed;
}

function CheckUUID {
    CheckID=`echo "$1" | sed -e "s/\w\{8\}-\w\{4\}-\w\{4\}-\w\{4\}-\w\{12\}/ok/"`;
    if [ "$CheckID" != "ok" ]; then
        echo "Source Disk \"$1\" UUID Not Valid";
        exit 2;
    fi
}

############## Sanity Check
# Make Sure that we have the required software
ChkUtility "grep";
ChkUtility "cut";
ChkUtility "sed";
ChkUtility "uuidgen";
ChkUtility "VBoxManage";

# Command line Parameters must be 2
if [ $# != 2 ]; then
    echo "Source VM Name Or Clone VM Name is Missing";
    exit 2;
fi

# Get Command line Parameters
SrcVM=$1;
CloneVM=$2;

# Set Clone Machine Directory
MachinesDirLine=`VBoxManage -nologo list systemproperties | grep "Default machine folder:"`;
MachinesDirRaw=`echo $MachinesDirLine | cut -d: -f2`;
MachinesDir=`echo $MachinesDirRaw | sed -e "s/^ *//g"`;
CloneMachineDir=$MachinesDir/$CloneVM;

# Make Sure that the Source VM is Registered
res=`VBoxManage -nologo showvminfo "$SrcVM" | grep "[!]"`
if [ "$res" != "" ]; then
    echo "Source VM \"$SrcVM\" Not Registered";
    exit 2;
fi

# Make Sure that the Clone VM NOT Registered
res=`VBoxManage -nologo showvminfo "$CloneVM" | grep "[!]"`
if [ "$res" = "" ]; then
    echo "Clone VM \"$CloneVM\" Already Registered";
    exit 2;
fi

# Make Sure that the Clone VM Directory Doesn't Exsits
if [ -d "$CloneMachineDir" ]; then
	echo "The Directory \"$CloneMachineDir\" Already Exists";
	exit 2;
fi

# Make Sure that the Source Disk UUID is Valid
SrcDiskID=`GetValue "$SrcVM" "HdaImageUUID"`;
CheckDiskID=`CheckUUID "$SrcDiskID"`;

# Make Sure that the Source Machine UUID is Valid
SrcVMid=`GetValue "$SrcVM" "UUID"`;
CheckDiskID=`CheckUUID "$SrcVMid"`;

# Make Sure that the Source Machine Config File Exists
SrcVMcfg=`GetValue "$SrcVM" "CfgFile"`;
if [ ! -f "$SrcVMcfg" ]; then
    echo "Source Config File \"$SrcVMcfg\" Doesn't Exist";
    exit 2;
fi

############## Make Clone Machine Directory and Copy Machine Config File
mkdir "$CloneMachineDir";
echo "Created Clone Machine Directory \"$CloneMachineDir\""
cp -f "$SrcVMcfg" "$CloneMachineDir/$CloneVM.xml";
echo "Copied Source Machine Config File \"$SrcVMcfg\" to \"$CloneMachineDir/$CloneVM.xml\""

############## Clone Disk
echo "Cloning Disk ..."
VBoxManage -nologo clonevdi "$SrcDiskID" "$CloneVM.vdi";
echo "Source Disk has been Cloned to \"$CloneVM.vdi\""

############## Create a new Machine UUID and replace the original
sed -i "s/<Machine uuid=\"{$SrcVMid}\" name=\"$SrcVM\"/<Machine uuid=\"{`uuidgen`}\" name=\"$CloneVM\"/" "$CloneMachineDir/$CloneVM.xml";
echo "Clone Machine UUID has been Updated"

############## Remove Hard Disk Description
sed -i 's/<HardDiskAttachment .*\/>//' "$CloneMachineDir/$CloneVM.xml";
echo "Hard Disk Description has been Removed"

############## Register the New Machine
VBoxManage -nologo registervm "$CloneMachineDir/$CloneVM.xml";
echo "Clone Machine has been Registered"

############## Register the New Disk
VBoxManage -nologo modifyvm "$CloneVM" -hda "$CloneVM.vdi";
echo "Clone Machine Hard Disk has been Registered"

############## Done
echo -e "*** DONE ***\n*** The Clone Machine \"$CloneVM\" Created Succesfully ***"
------------------------------------------- cut here ---------------------------------------------------

Modbreak: Use code blocks next time, it improves readability and keeps the layout.
Operating from ignorance is a good way to obtain knowledge.
dmcgraw
Volunteer
Posts: 808
Joined: 24. Jun 2008, 17:16
Primary OS: Ubuntu 8.10
VBox Version: PUEL
Guest OSses: XP, Ubuntu 9.10
Location: St. Louis, MO, USA

Post by dmcgraw »

When I run this script, it fails to clone the .vdi. The output is shown below.

Is this just because it is not possible to clone a VM which has snapshots?

Thanks,
Dave

Code: Select all

Created Clone Machine Directory "/home/dave/.VirtualBox/Machines/WindowsXP2"
Copied Source Machine Config File "/home/dave/.VirtualBox/Machines/WindowsXP/WindowsXP.xml" to "/home/dave/.VirtualBox/Machines/WindowsXP2/WindowsXP2.xml"
Cloning Disk ...
[!] FAILED calling hardDisk->CloneToImage(Bstr(argv[1]), vdiOut.asOutParam(), progress.asOutParam()) at line 3313!
[!] Primary RC  = NS_ERROR_FAILURE (0x80004005) - Operation failed
[!] Full error info present: true , basic error info present: true 
[!] Result Code = NS_ERROR_FAILURE (0x80004005) - Operation failed
[!] Text        = Cloning differencing VDI images is not yet supported ('/home/dave/.VirtualBox/Machines/WindowsXP/Snapshots/{4022f098-ed5b-486c-75a2-b145b9f18ee3}.vdi')
[!] Component   = HardDisk, Interface: IHardDisk, {fd443ec1-000f-4f5b-9282-d72760a66916}
[!] Callee      = IHardDisk, {fd443ec1-000f-4f5b-9282-d72760a66916}
Source Disk has been Cloned to "WindowsXP2.vdi"
Clone Machine UUID has been Updated
Hard Disk Description has been Removed
Clone Machine has been Registered
[!] FAILED calling virtualBox->OpenHardDisk(Bstr(hdds[0]), hardDisk.asOutParam()) at line 4537!
[!] Primary RC  = NS_ERROR_FAILURE (0x80004005) - Operation failed
[!] Full error info present: true , basic error info present: true 
[!] Result Code = NS_ERROR_FAILURE (0x80004005) - Operation failed
[!] Text        = Could not access hard disk image '/home/dave/.VirtualBox/VDI/WindowsXP2.vdi' (VERR_FILE_NOT_FOUND)
[!] Component   = HardDisk, Interface: IHardDisk, {fd443ec1-000f-4f5b-9282-d72760a66916}
[!] Callee      = IVirtualBox, {2d3b9ea7-25f5-4f07-a8e1-7dd7e0dcf667}
Clone Machine Hard Disk has been Registered
*** DONE ***
*** The Clone Machine "WindowsXP2" Created Succesfully ***
samyantoun
Posts: 5
Joined: 9. Jul 2008, 23:20

Post by samyantoun »

NEKGuy,
Thank you very much for the bug fixes (And for correcting some typo)

dmcgraw,
Sorry that the script didn't work for you, Please be advised that it is a "Work in progress" and shouldn't be used in a production environment.
rebus
Posts: 35
Joined: 2. Jul 2008, 17:43

Post by rebus »

I hope that some one find the time to translate the script in VBS (or some other MS script ... ) for the "Bill Gates's boys" :?

Modbreak: No abusive use of hard returns, makes it hard to read.
jcato77
Posts: 3
Joined: 18. Jul 2008, 19:30

Post by jcato77 »

I know that SUN is probably not the greatest fan of Microsoft but making some of these tools work under windows would be much appericated. I know that once I figured out how to use vboxmanage and clonevdi I'm able to do what I want but not everyone wants to run in the command line. If you want more windows hosts to use this software get out of the command line and have some of these options work within windows.

Quick note I added the vbox path to my host machine so I could run vboxmanage from any folder. This way I didn't have to fully qualify the .exe name once that was done clonevdi "source" "dest" worked much better. Anyone want to write a small java app that would do this in windows for the rest of us?
Micheus
Posts: 6
Joined: 8. Sep 2008, 02:10

Post by Micheus »

Last month I found this topic and it was very usefull to me. Thanks.

I had resolve to create a simple GUI to clone vdi disks. Now that I finished it, I wish share it with some others users.

I have observed that VBoxManage use VBoxSVC (it was started when VirtualBox was not running). So I think that is not a good idea to stop the process after it was started and I decided not enable that the window could be closed or not to add some option to cancel the cloning process because I think that it will be more secure if VirtualBox is running - to stop process the VBoxSVC must be stopped (or killed).

Link to download: vBoxManageGUI (for Windows)

Comments and suggestions are welcome.

Bye
Last edited by Micheus on 8. Sep 2008, 23:30, edited 1 time in total.
"It always has, at least, two ways to make one same thing. Exactly that they are certain and wrong"(Micheus)

Brazil - Blumenau
sej7278
Volunteer
Posts: 1003
Joined: 5. Sep 2008, 14:40
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Solaris, Linux, Windows, OS/2, MacOSX, FreeBSD
Contact:

Post by sej7278 »

why do you need an application to clone the vdi files though anyway - are they doing some nasty hardware-level disk inode tricks or something?

surely if the vm is turned off (or virtualbox closed altogether) there should be no lock on the files and they should be copy'n'paste-able (keeping access permissions etc.)?

one of the benefits of using a vm are that to back them up you just copy some files, no need to ghost disk images etc.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Post by mpack »

sej7278 wrote: surely if the vm is turned off (or virtualbox closed altogether) there should be no lock on the files ... ?
Virtualbox writes a unique identifying number (called a UUID) into the header of each VDI file. If you simply copy the VDI file using the host OS then it means that two VDI files now have the same UUID. When you try to create a new VM using the new VDI, Virtualbox will complain that you have already previously registered a virtual drive with the same UUID.

I find this intensely irritating. The UUIDs are there so that snapshots can be associated with the correct "parent" VDI - and even though I don't use snapshots I still suffer from the bureacracy which it entails. I wish the developers could find a way to implement snapshots (for those that want them) in a way that doesn't inconvenience everyone else.

This isn't just a problem when cloning. If you attempt to move VMs from one PC to another (eg. if you keep your VM on a USB stick), then you are likely, eventually, to run into problems with VBox complaining about conflicting UUIDs.
Post Reply