How to Clone & Reuse VirtualBox Disk-Images under Linux

When working with Oracle VirtualBox you might have come accross situations, where you wanted to copy the state of a given Disk-Image and build a new Virtual Machine upon that. We tell you, hot to do that.

a) Preparations

Before starting to make manipulations make sure, you have a recent backup of your VM with all its files.

Then create a new Machine of the desired OS – which is the one you have an exisitng Disk-Image for. You can create new Machines using the UI application ‘Oracle VM VirtualBox Manager’:

Create Virtual Machine_002

How to Create a new Virtual Machine

By now, a new folder would have been created in your VirtualBox VMs directory, which is something like: ‘/home/phabi/VirtualBox VMs’. Now you can switch to the folder of your desired source VM, i.e. ‘/home/phabi/VirtualBox VMs/myoldVM/’ where you would find the source Disk-Image to be copied, named something like ‘old_disk_image.vdi’. [Attention: Copying this image only takes the Base Disk-Image, which this VM is based on. If you’re having Snapshots, this information will not be contained in the Disk-Image unless you merge them back to the root node.]

b) Copy your existing Disk-Image

Now take that *.vdi Disk-Image and copy it to the newly created location, say you name it ‘new_disk_image.vdi’, in our case ‘/home/phabi/VirtualBox VMs/mynewVM’.

If you’d continue now with ‘Oracle VM VirtualBox Manager’ the application would complain, that the same Disk-Image is already in use. Oracle VirtualBox Manager doesn’t allow you to run VMs using Disk-Images providing the same Identifier (UUID). That’s why you have to assign it a new UUID using Oracle’s VBoxManage-Utility, located somewhere like ‘/usr/lib/virtualbox’.

c) Assign a new UUID to your Disk-Image

To change the UUID of the newly copied Disk-Image open a Terminal-Window and enter the following command, provided the VBoxManage-Utility location is contained in your $PATH variable, otherwise cd to its location and adapt the arguments accordingly:

phabi # ./VBoxManage internalcommands sethduuid "/home/phabi/VirtualBox VMs/mynewVM/new_disk_image.vdi"
UUID changed to: 214d8f33-3ba9-4123-b646-0d7eabef38a1
phabi #

If the VirtualBox is not located in your homedirectory you might need to run the command under root privileges.

d) Finish the VM-Creation Process

Then switch back to the ‘Oracle VM VirtualBox Manager’. In the following Screen select the RAM to be assigned to the new VM, click [Next]  and in the Screen titled ‘Hard drive’ select the option (x) Use an existing virtual hard drive file  and select the disk you have just copied, then click [Create].

That’s it. Now you should have your new VM ready based on that new Disk-Image.

Share on FacebookShare on LinkedInShare on Google+Tweet about this on TwitterEmail this to someone
PDF herunterladen
Posted in Build Process, Infrastructure, Software Engineering, Uncategorized