Sunday, December 16, 2012

Migrate physical PC to Oracle Virtualbox


Some day ago we had to return back a old desktop computer. In this computer we had software and configuration we rarely use. We decide to don’t clone the PC in another physical computer because didn’t use this desktop very often. We decide to create a virtual machine to start when needed. We could creare a new VM with a fresh Windows XP installation, but install and configure all the software we had was too long. So we decide to clone the physical machine.

There are two easy way to clone a physical machine in a virtual machine for free. Those two method create a copy of your hard-drive to use with you favorite VM software: Microsoft Virtual PC, VMware, Oracle Virtualbox (with some edit with KVM, XEN too)

The first one is Disk2vhd from Microsoft. This sofware works only on Microsoft OS, and need a running Microsoft OS to work. You can use the computer you want to clone to run the program an save the images on another hard-drive (network, usb). I think you can connect the hard drive you want to clone to another pc and clone it, but I never tried.
I tried to use this method, but the program wasn't able to start on the Desktop. It worked fine with my laptop.

The second one is WmWare Converter
I don’t know much about this software. I know it’s free but I had to give them my email and accept something to use it so I quit before start.

I decided to use a third way. It (should) works with all kind of OS.

What we need:
Second computer
Big hard-drive.
usb-key or cd-rom with a live version of Linux

Step 1 Clone the hard drive

We need to clone the hard drive, to do that I used Linux command DD. It’s a very powerful and  dangerous command. It can clone hard drive, cd-rom or just file byte to byte.
Can be dangerous because if you set wrong the source and the target you might overwrite the data you want to clone.

the command is: dd if=(source) of=(target)

DD will clone every single byte of your hard drive, even the free space, so it will create a image as big as your hard drive. So be sure you are going to have a usb or network hardrive big enough to contain this image.

I started a live distro on the pc i wanted to clone.
Opened a terminal
and used DD.

dd if=/dev/sda of=/<path>/clone_sda.img

I didn’t had a usb hardrive so I decided to copy over SSH:

Source: karlherrick.com

dd if=/dev/sda | ssh username@backupserver "dd of=/<path>/clone_sda.img"

Step 2 Create VDI virtual hard drive

This and next step need Virtualbox.

Pretty straightforward:

VBoxManage convertfromraw clone_sda.img clone_sda.vdi --format VDI

* Step 1 and 2 can be pipelined, bu you need some extrasteps check phaq.phunsites.net.


Step 3 Compress VDI virtual hard drive

To compress the VDI image you have to “wipe” all free space.
When you delete a file in your harddrive you don’t overwrite the data of your file with ZEROES but you just “forgot” you you put the data. 
The compression just trows away all the zeroes we have in our hardrive. So we must wipe the free space before launch the program.

I used CCLEANER 




After the wipe the harddrive: 

VBoxManage modifyvdi <hd_path> compact

Source: kakku.wordpress.com

Done!

Tuesday, March 13, 2012

Migrate from Virtualbox to KVM

Some days ago I decided to migrate some of my Oracle Virtualbox test VM on a KVM server.

Why? easy, KVM\QEMU is better Oracle Virtualbox for a lot of reason. Probably this link will be enough to convince you.


Have a computer with virtualbox make everything easier but I wanted to do everything without virtuabox. (Link with virtuabox)

So we have to converto VDI images into somethink KVM can read. I used a simple ".RAW" images. This step is easy, and you can find tons of post online:
http://blog.bodhizazen.net/linux/convert-virtualbox-vdi-to-kvm-qcow/
http://xpapad.wordpress.com/2010/02/21/migrating-from-virtualbox-to-vmware-in-linux/
http://www.dedoimedo.com/computers/virtualbox-convert.html
http://kevin.deldycke.com/2007/04/how-to-grow-any-qemu-system-image/

Edit 16/12/12: Anyway this will make a .RAW as big as the dimension assigned to your virtual hard drive.

I started with my VirtualBox VM Debian6 test server, where I usually try new stuff before put it on a real PC or anyway in the main VM.
Convert the hard drive from VDI to RAW, I used the RAW image inside a KVM VM and everything worked fine.

Windows XP:
After conver the VDI image and put the RAW inside a KVM VM i had this issue:

 0x0000007B
BLUE SCREEN OF DEATH (BSOD)
 
This blue screen arrived at the first second third and ALL boot after the conversion....
I searched and I found something.
Talking on IRC I realized the problem was the hard drive controller.
What we have to do? touch a bit WinXp registry... how to do it easily?
I found 2 solutions:
  1. With virtualbox: This "patch". Run it before your turn off the last time your virtualbox machine before the migration. I will say to XP to accept all HD chipset (or something similar)
  2. Without virtualbox: HIREN's boot cd or as a lot of SysAdmin know it... Ass saver! Simply boot micro XP goes on the tools and find "Fix Hard disk controller" under Registry. And DONE!


I found another problem, something I really though I wasn't to solve it fast, read a lot of stuff, like reinstall windows over the existing one or make a brand new VM.
I didn't want! so I pass more time searching than the time I needed to reinstall windows! But I Found it

Fist the problem (link):

So what happened? I haven't only moved my VM from Virtualbox to KVM on the same machine but I moved it from an AMD Athlon x2 to two different PC (to test) an AMD phenon x6 and Intel SB i5. On the AMD I haven't had this problem, but on the Intel I had! So I had problem because the processor type isn't the same.

Thanks to this AWESOME GUY we have a solution for this problem too....
http://blogs.msdn.com/b/virtual_pc_guy/archive/2005/10/24/484461.aspx

I just start my VM XP in safe mode and edit the register like he wrote

And here we are! true you won't have reconized the CPU on hardware manager on Windows, but who care it's Windows! :D

Hope this post will help somebody.
Have a nice day!