Move and clone VirtualBox machines with filesystem commands

Posted on

Move and clone VirtualBox machines with filesystem commands – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.

But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, virtualization, command-line-interface, virtualbox, cloning.

I know of 2 ways to clone a VirtualBox machine on a linux host, one is by using the VirtualBox gui and exporting and re-importing as appliance (in the file menu of VirtualBox).

The other is by cloning only the virtual disk container files:

VBoxManage clonevdi /mnt/md1/original/root-fs.vdi /mnt/md1/cloned/root-fs.vdi

(Taken from )

Edit: this does not seem to work for VDI files that are already part of ~/VirtualBox/VirtualBox.xml, I get an error message:

ERROR: Cannot register the hard disk ‘/mnt/md1/original/root-fs.vdi’ with UUID {96a1462b-c30a-4911-a954-d9093122f083} because a hard disk ‘/mnt/md1/original/root-fs.vdi’ with UUID {96a1462b-c30a-4911-a954-d9093122f083} already exists in the media registry (‘/home/mit/.VirtualBox/VirtualBox.xml’)

I would have to create a new VM afterwards and use the cloned virtual disk containers.

Is it also possible to clone a VM by copying the virtual disk contianer files and the config files using filesystem commands and do the rest by hand?

I’d have to manually edit the ~/VirtualBox/VirtualBox.xml and insert a new disk and a new machine:

Can I just make up UUIDs or how would this work?

I would very much prefer this hardcore method of doing things as it allows me to freely and rapdily backup, restore, move or clone machines. Or ist there a better way to do this?

Solution :

You can change the UUID of a vdi using the command

VBoxManage internalcommands setvdiuuid disk.vdi

or if you are using VBox V4.x at least to 4.0.10

 VBoxManage internalcommands sethduuid disk.vdi

then use the GUI import the new ‘unique’ disk.

If you want to clone a particular VirtualBox machine then you are probably better off making an appliance of it and then using it. To make an appliance use the GUI Export Appliance feature or the vboxmanage export command. The resultant appliance can then be imported using the GUI Import Appliance feature or the vboxmanage import command.

Or you can edit the “Virtualbox.xml” setupfile with the right uuids for the machineid. Worked great for me moving a virtual machine from one host to another (both hosts being 64-bits linux, no idea if it had worked moving to e.g. windows or mac) see for details.

This works even if the vboxmanager on the original host for some reason can not be run.

Leave a Reply

Your email address will not be published.