Thursday 30 January 2014

Importing a VirtualBox VM into RHEV

After several trials and errors I finally found a "working" method of importing VirtualBox (and probably VMWare and other Virtualizations solutions) VM into a RHEV system.

What you need:

1 - Lots of disk space! At least twice the size of your VM's disks.
2 - A VirtualBox installation and the qemu-img program (available in your distro or from www.qemu.org).
3 - A libvirtxml template file (you can get the one I use from here).
4 - The virt-v2v program installed in one the RHEV machines (or the RHEV manager machine).

So how do you do it?

Convert VirtualBox disks to QCOW format (if someone knows how to easily convert them directly to raw please let know!).
You could be tempted to convert the disks directly from VMDK format to RAW with qemu-img, unfortunately I found this is not possible since qemu gives an "unsupported format error".

Anyway, just follow these steps:


Go to the VirtualBox File Menu and select: "Virtual Media Manager".


Then select the first disk and right-click it and select "Copy...", or press the Copy Button:



Check if the right file was selected and press Next:


Select the QCOW (QEMU Copy-On-Write) format and press Next:


Select the output filename and path, finally press Copy:


Wait for it to finish... 


Once it is done you still need to convert them to the RAW format. This is where qemu-img comes in. Issue the following command to convert a disk to the RAW format:

qemu-img convert disk1.qcow -O raw disk1.img

Repeat for every disk you need converted.


Now, for the real fun part! 

Open the libvirtxml file you got from above and edit the following fields:

<name>VMNAME</name>
<uuid>b8d7388a-bbf2-db3a-e962-12346789abcd</uuid>
<memory>2097152</memory>
 <type arch='x86' machine='pc'>hvm</type>

The vmname should be changed to whatever you want, this will be the name that appears on the imported VM.
The uuid is not important at this point since it will be changed once the import is completed.
You can also change the memory size (in KB).
The arch property should be set to x86 or x86_64 if it has a 32bit or a 64bit guest OS.


In the disk section you need to change a few things.
<disk type='file' device='disk'>
    <driver name='qemu' type='raw' cache='none' io='threads'/>
    <source file='disk1.img'/>
    <source dev='/dev/sda'/>
    <target dev='sda' bus='scsi'/>

<shareable/>      
</disk>



Change the source file  and target dev properties to what you need.  In this example the disk1.img is the first disk (sda). 
The example XML file I provide has two disks, you can remove the section for the second one or you can add more disk sections if you need to.


Once you have the file properly set up it's time to import it into RHEV.

Use the following command:

virt-v2v -i libvirtxml -o rhev -osd IP:/DIR --network rhevm VM_libvirt.xml

The IP and DIR should be the IP, or hostname, of the export domain and DIR the NFS dir path (I'm using an NFS export domain, you can change this to reflect you export domain).
Check the documentation if you have any doubts.


After a couple of minutes or hours, depending on the size of the disks and your network speed, you should have the machine in your export domain. From there you can import it to RHEV.

I have used this method on both windows and Linux machines and it seems to work fine!

3 comments:

  1. getting error "No root device found in this operating system image"

    ReplyDelete
  2. In which command are you getting that error message?

    ReplyDelete
    Replies
    1. Thank brother. it was vey useful for me when my RHEV server goes down and migration time. I had try all utility and all way but i did not get solution. then i was export disk by dd command and import as per your above documention. thanks a lot..

      Delete