Introduction to Virtualization - 102 Clone a Virtual Machine with Sun Virtual Box
How do you clone a virtual machine with Sun Virtual Box?
The short answer is:
use VBoxManage to "clone" the disk. this changes the uuid of the virtual disk.
use the GUI or the command VboxManage to make a new virtual machine
then attach the cloned virtual disk to the new virtual machine.
How to is included below:
1. You cannot just copy the disk. You cannot export and import the virtual machine with the GUI.
There is an export and import command however
VirtualBox complains about the uuid of the disk already being in the system.
2. There is no GUI command to clone the disk
but there is a handy VboxManage command
3. There is no GUI command to clone the vm
but you can just make another one with the gui or VboxManage
4. In the Virtual Machine new machine- after you build it.
a. It might not boot if the /boot/grub/menu.1st file finds its disks via uuid.
so change to use devices or use labels.
b. It might not find its Ethernet Card. The uuid and mac changes.
so change the system to use the device and mac (sometimes busid)
Had to use "busid" on OpenSUSE. I think RHEL Linux just worked.
c. Surprising this is usually a Linux problem. Windows XP worked fine.
more details below.
So to do all this for OpenSUSE 11.1
My environment is an older Dual Opteron Machine with 8Gb of RAM and 1T of
SATA 3.0 disk.
Running OpenSUSE 11.1 64 bit as the host OS.
Running OpenSUSE 11.1 32 bit as the guest (Plus some others)
The script below was able to make a clone in about 5 minutes
The longest part of the cloning process is copying the disk.The rest
of the commands were only a few seconds
I changed the menu.1st before I cloned the disk.
I changed the network card afterward but one can do it before one clones the disk.
Use in the GUI "bridged" networking to make a full fledged networked OS.
Note, in the script below,
My host machine uses eth1. Yours might use eth0.
Adjust your RAM and Video RAM as necessary.
------------------------------
Some Control Commands using VBoxManage
Note these are using BASH on LINUX.
Any Linux should do:
cat info.sh
VBoxManage showvminfo $1
cat on.sh
VBoxManage startvm $1
cat off.sh
VBoxManage controlvm $1 poweroff
cat pause.sh
VBoxManage controlvm $1 pause
cat resume.sh
VBoxManage controlvm $1 resume
cat savestate.sh
VBoxManage controlvm $1 savestate
------------------------------
To Clone a harddrive:
cat clonevm.sh
#put VBoxManage on the path: /usr/lib/virtualbox
#easiest to run in the harddrive directory
cd ~/.VirtualBox/HardDisks
#clone the disk
echo example:
echo "./clone3.sh somedisk.vmdk newvm"
newvmname=$2
date
echo create a clone of the disk
VBoxManage clonehd $1 $newvmname.vmdk
date
echo create the vm
VBoxManage createvm --name $newvmname --register
#take output and hack on the xml file or just use register
#name and uuid important. hack on ~/.VirtualBox/VirtualBox.xml to add to gui
#Virtual machine 'testlink-test' is created.
#UUID: a3622e48-1edd-48df-ac62-d9891d1a1982
#Settings file:
'/home2/vmrunner/.VirtualBox/Machines/testlink-test/testlink-test.xml'
#modify the machine
#comment on my machine the base machine was eth1 ..
VBoxManage modifyvm $newvmname --ostype openSUSE --memory 512 --vram
64 --nic1 bridged --bridgeadapter1 eth1 --nictype1 82545EM
--cableconnected1 on --audiocontroller ac97 --usb on
#somehow the network was not quite right
#but going into the gui and hitting save did it
#attach storage
VBoxManage storagectl $newvmname --add ide --name $newvmname-hd0
--controller PIIX4
VBoxManage storageattach $newvmname --storagectl $newvmname-hd0 --port
0 --device 0 --type hdd --medium $newvmname.vmdk
date
- stephen's blog
- Login or register to post comments
- Printer-friendly version
- Send to friend
