Saltar al contenido

VirtualBox

Clone and move virtual machines in VirtualBox

It describes cloning and moving virtual machines in VirtualBox.

I’m a big fan of VirtualBox. The tool enables me to extend a machine beyond its normal capabilities, test operating systems without getting invasive with my host, and kick the tires on various software titles without installing them on my production machine. But sometimes I get a virtual machine up and running and want to copy it (to move it to another machine or to have a second instance to test); when that time comes, I don’t want to completely re-install the operating system and get it to the state I need. In this situation, I clone the virtual machine.When you clone a drive, you make an exact copy of the virtual machine that can be used on either the same host or moved to another VirtualBox host. The process of cloning and moving a virtual machine is now easy in VirtualBox. In fact, there are no more commands for cloning, as the process is built into the GUI. I’ll walk through this process and then move the resulting clone to another machine for use.

What you need

  • VirtualBox installed (the host platform doesn’t matter)
  • A running virtual machine
  • The ability to move the clone from one machine to another (shared drive, external drive, disk, etc.)

Cloning a virtual machine

Step 1: Close the virtual machine

You cannot pause the machine that is going to be cloned and then clone it — the machine must be turned off.

Step 2: Start the cloning process

Select the virtual machine you want to clone in the left pane of the VirtualBox main window. Click the Snapshots tab (Figure A) and then click the small sheep icon.

Figure A

A Ubuntu 12.04 virtual machine with no snapshots taken.

The wizard that opens is a simple two-step process. The first step requires you to give the clone a name; you must give this clone a different name than the source virtual machine. By default, VirtualBox will append “clone” at the end of the name of the source virtual machine. You can keep this, and it should work fine. The second phase of the wizard asks the type of clone you want to create (Figure B). You will want to create a full clone, since our goal is to move this virtual machine to a new host.

Figure B

Read carefully the difference between full and linked clones.

Step 3: Locate and move the clone

You will be looking for a .vdi file. The location of this file will depend upon the host platform. On my Linux host, the file will be found in ~/VirtualBox VMs. Within that directory, you will find sub-directories of all your virtual machines. Within the virtual machine directory in question, you will find the .vdi file of the cloned virtual machines — that is, the file that must be moved to the new host. Copy that file to an external or shared drive and then copy it onto the new host (the location doesn’t matter).

Step 4: Create a new virtual machine

The process of creating the new virtual machine will be the same as if you were creating a standard virtual machine until you get to the Virtual Hard Disk creation screen (Figure C). You will select Use Existing Hard Disk, click the folder icon, navigate to the newly copied .vdi file, select the file in question, and then click Next.

Figure C

I’m almost finished adding my clone to a new host.

Once the new virtual machine is created, that virtual machine should fire up as expected and regardless of platform (I have tested this going from Linux to Linux, Linux to Windows, and Windows to Linux hosts).

Summary

The ability to clone and move virtual machines in VirtualBox as easily as shown above makes this a great tool for anyone who needs to expand their world with virtual machines. Give this a try and see how far you extend the reach of your hosts and guests with VirtualBox.

VirtualBox – Red visible máquina virtual (Servidor único interface)

  • admin 

Al trabajar con Máquinas Virtuales será necesario añadir interfaces de red de varios tipos, según nuestras necesidades:

– Bridged : Comparte el rango de red de la máquina anfitrión (la máquina en la que está instalado virtualbox).

– Host-only (Sólo anfitrión) : Crea una red para compartir solamente con el anfitrión.

– Red Interna :Para comunicarse con otras máquinas virtuales que estén ejecutándose a la vez en la misma máquina y poseer una interfaz de red interna que nos facilitará la conexión con las máquinas virtuales cliente (situadas tambien en la red interna).

 NAT : Crea una interfaz en el rango 10.0.0.0 que crea una conexión NAT (traduce entre una dirección IP y la otra) con la red del anfitrión.


Cuando creas una máquina virtual con VirtualBox, con las opciones de red por defecto, esta  con conexión a cualquier recurso en la red al que tenga acceso la máquina anfitriona (conexión a Internet incluida) y puede compartir archivos con ella si configuramos la opción de “Directorios Compartidos”, pero entre máquina anfitriona y máquina virtual no existe ninguna otra posible conexión. La máquina virtual tampoco es accesible de ninguna forma desde otra máquina de nuestra red local y si abrimos dos máquinas virtuales en la misma máquina anfitriona tampoco pueden verse entre si. Esto puede cambiarse fácilmente para que cualquier máquina virtual que creemos sea totalmente visible, tanto por la máquina anfitriona, como por cualquier otra máquina  (o virtual, en esta u otra máquina anfitriona configurada por este mismo método) como si se tratase verdaderamente de una máquina real conectada de forma  a nuestra red. Nos ponemos a ello.

Partimos de una máquina anfitriona con Debian o una distribución derivada (Ubuntu, Kubuntu, etc.), que ya tiene Virtualbox instalado y cuenta con una única interfaz de red (eth0). Lo primero que tenemos que hacer es instalar el paquete bridge-utils.

pablo@pablo-U-100:~$ sudo apt-get install bridge-utils

Luego editamos la configuración de nuestro interface ethernet (/etc/network/interfaces) y lo dejamos de esta forma:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto br0
iface br0 inet dhcp
bridge_ports eth0 vbox0 vbox1

Las líneas en negritas son las que hemos añadido. En ellas estamos definiendo dos interfaces virtuales (vbox0 y vbox1) que están ligados a nuestro interfaz físico real (eth0) y que tomaran una IP de forma dinámica a través de un servicio DHCP que debemos de tener disponible en nuestra red. Esto no quiere decir que no podamos ponerles direcciones fijas a nuestras máquinas virtuales: Estas tendrán disponible este servicio, si existe, desde su arranque pero luego nosotros podremos configurarlas perfectamente mediante IP’s estáticas sin ningún problema, ya dentro del sistema operativo que hayamos elegido para ellas. Por cierto: hemos creado dos interfaces por que es lo que necesitamos (yo, en concreto, quiero hacer prácticas para los chicos con un windows 2003 server y un windows xp que deben de verse para que el segundo se conecte al dominio definido por el primero) pero, lógicamente, podríamos definir una sóla. O diez 🙂 .

Ahora editamos el archivo de configuración de interfaces de virtualbox (/etc/vbox/interfaces) y añadimos las siguientes líneas:

vbox0 pablo br0
vbox1 pablo br0

En ellas redefinimos los dos nuevos interfaces virtuales que hemos creado (vbox0 y vbox1) y declaramos el usuario de la máquina anfitriona que tiene permiso para usarlos.

Ya casi estamos. Ahora reiniciamos, por este orden, la interfaz de red física de nuesta máquina anfitriona y luego virtualbox:

pablo@pablo-U-100:~$ sudo /etc/init.d/networking restart
* Reconfiguring network interfaces…
(…)
bound to 192.168.1.10 — renewal in 39314 seconds.
[ OK ]

pablo@pablo-U-100:~$ sudo /etc/init.d/virtualbox-ose restart
* Shutting down VirtualBox host networking
* done.
* Starting VirtualBox host networking
* done.

Luego iniciamos Virtualbox y configuramos la red de las máquinas que queremos hacer accesibles de esta forma:

Y con esto ya si que hemos acabado. En el siguiente pantallazo (ampliable si hacéis click en él) podéis ver como mis dos máquinas virtuales se ven perfectamente (la XP tomando su IP mediante DHCP, el 2003 server con IP estática configurada manualmente), la autenticación de dominio entre ellos se ha hecho perfectamente y ambas son visibles también desde la máquina anfitriona.