Thursday, October 2, 2008

V2P (Virtual-to-Physical) for VirtualBox

So you might have had a great Virtual Machine which has your development environment or may be a specific build environment. You think the time has come now to free this VM and give its own dedicated hardware. Or even none of the above is true, you want to do it because you can :)

You will have to go do what is called as v2p (Virtual to Physical) migration. So lets just think about what exactly we are trying to do. We have Virtual Machine running inside a VirtualBox which has its own virtual hard disk. The converting a virtual machine to a physical machine is mainly about changing this virtual machine operating system boot from a physical real hard disk than virtual hard disk on which it was running when inside VirtualBox.

VirtualBox comes with one hidden command under its hood, convettoraw! This can be used in following manner,

VBoxMange internalcommands converttoraw your.vdi your.raw

So now you have a raw image of your VM (pleaes note that if you have a VM of say, 16GB dynamically expandable virtual hard disk, when you create a raw image it will actually create a file which will occupy 16GB on your disk! so make sure you have that much of space on your disk before procedeeing). Now this raw image can be deployed to another disk very easily.

Connect the disk on which you want to deploy the raw image that you just created to your existing system. Now depending upon on the Operating system that you are running the actual command may very. I will pick Linux as my host operating system on which I will assume the VirtaulBox is running. So this second physical disk appears as /dev/sdb on my Linux box, so I execute,

dd if=/location-of-your-raw of=/dev/sdb

Once its done, connect this disk as primary master to the system that you are planning run. At first boot, make sure the system is started with -r option to re-configure the devices.