Thursday, April 7, 2016

VBoxmanage | import vs clonevm


Why I am writing this?

I have been using VBoxmanage for some time now and only recently ran into a situation that made me realize I didn't do all my homework.
So I wanted to make sure that no one else makes the same mistake I did with managing virtual machines via the command line.

What is Cloning (clonevm)?


    "This command creates a full or linked copy of an existing virtual machine.[1]"

So what does that mean? well, it means it creates a *.vmdk file within the folder for the new virtual machine.

$ vboxmanage clonevm [existing-vm] --register --name [new-vmname]

The above command will create a new vm in the ~/VirtualBox\ VMs/ folder with the *.vmdk file residing within.

What are the advantages to using clonevm:

  • Speed of creation is faster compared to import
  • Fewer options to get yourself tripped up on

Possible disadvantages:

  • There really are fewer options
  • You must already have a base system imported and registered
    • This is just more space being taken up by a machine that may not even be running

What is Importing (import)?

Importing is what needs to be done before you can even clone a system.

    "This command imports a virtual appliance in OVF format by copying the virtual disk images and creating virtual machines in VirtualBox.[1]"

So what does that mean? well, it means that if you simply run the following command:

$ vboxmanage import [filename.ova] --vsys 0 --vmname [new-vmname]

you will get a vm that is based off of the base system found within the *.ova.
But, where is the *.vmdk file located?

~/VirtualBox\ VMs/[filename]/[filename]-disk1_[#].vmdk

When importing an image you can actually import multiple VMs based off one *.ova file, and the disk1_[#] number will just continue to increment.

So, what if you want the *.vmdk file in the same directory that your new VM log file will be?
In order to make that happen you will need to include several other options:

$ vboxmanage import [filename.ova] --vsys 0 --unit 10 --disk VirtualBox\ VMs/[new-vmname]/[new-vmname].vmdk --vmname [new-vmname]

When looking up the '--unit' option, I noticed that some people had 11, but you can get this number at the bottom of the following command:

$ vboxmanage import [filename.ova] -n
...
(change target path with "--vsys 0 --unit 10 --disk path";
...

What are the advantages to using import:

  • You can import the image from anywhere, it does not have to be an installed and registered machine
  • More options so you can setup the machine how you want it and where you want it
  • Other than the *ova file you will not need to have another machine running

Possible disadvantages:

  • If you neglect to include an option, you will not have the environment you were hoping for
  • It does take a little bit longer to import a machine rather than cloning it

I bet you are wondering what it was that I did that caused me to really write this, well, I deleted a folder that contained over 10 VMs because I didn't realize that by importing it would place all of the *.vmdk files into the same folder.
Again, I didn't do all of my homework.

Well, there you have it, clonevm vs import.

----
References:
[1] Chapter 8. VBoxManage; https://www.virtualbox.org/manual/ch08.html