Easy Cloning
Easy Cloning
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
So far this is the only deficiency I've run across (aside from the occasional bug, but frankly it is a show-stopper).
Ron
Re: Easy Cloning
Can you explain that cmd line process or link to a tutorial?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
I would also like to clone a VM.
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)
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)
vdi file on different disk or partition
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!
Re: Easy Cloning
Why don't you make a batch file and then just fill in the blanks each time?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
Quick temp fix.
-
- Posts: 5
- Joined: 9. Jul 2008, 23:20
Maybe this shell script can help:
http://samyantoun.50webs.com/virtualbox/clonevm/
http://samyantoun.50webs.com/virtualbox/clonevm/
The clonevm.sh script is handy and seems to work well.
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 ---------------------------------------------------
------------------------------------------- cut here ---------------------------------------------------
Modbreak: Use code blocks next time, it improves readability and keeps the layout.
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 ***"
Modbreak: Use code blocks next time, it improves readability and keeps the layout.
Operating from ignorance is a good way to obtain knowledge.
-
- 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
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
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 ***
-
- Posts: 5
- Joined: 9. Jul 2008, 23:20
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?
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?
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
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
Brazil - Blumenau
-
- 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:
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.
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.
-
- Site Moderator
- Posts: 39156
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
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.sej7278 wrote: surely if the vm is turned off (or virtualbox closed altogether) there should be no lock on the files ... ?
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.