Convert Virtualbox vdi to KVM qcow
I have been asked several times how to convert an existing VirtualBox machine / image to KVM. The process is quite easy and involves simply converting your virtual hard drive (VirtualBox uses “vdi”) to a format compatible with KVM (qcow). You then use the qcow image with KVM, either from the command line of with virt-manager.
Although the process is quite easy, it does require sufficient hard drive space as the VirtualBox .vdi is first converted to a raw disk image.
Side track – Both vdi and qcow images are compressed, so a a 10 Gb .vid or .qcow will take less space on your hard drive. Conversion, however, requires you to first convert the .vdi to a raw image, which will require the full 10 Gb, so plan accordingly.
Assume your VirtualBox image is called “ubuntu.vdi”
Step 1. Convert the VB disk vdi image to a raw image format.
VBoxManage clonehd --format RAW ubuntu.vdi ubuntu.img
Note: The ubunut.img is a raw disk image, it will be quite large (as many GB as your virtual drive is, see above).
Step 2 : convert the raw image to a qcow
qemu-img convert -f raw ubuntu.img -O qcow2 ubuntu.qcow
That is all there is to it, the ubuntu.qcow can be used with KVM.
Test your new image (ubuntu.qcow) with:
kvm -m 512 -usbdevice tablet -hda ubuntu.qcow
If it is working you may delete the raw image (ubuntu.img) and archive or delete the ubuntu.vdi .
Welcome to KVM :)
Posted in Linux
Thanks so much for this, I will be moving to KVM this week!
Comment by jimcooncat — April 27, 2009 @ 1:10 pm
Hi.
KVM sounds interesting and certainly seems like the future in virtualization on nix.
The one feature virtualbox offers me that I could not live without is the headless mode with interaction with the VM over the remote desktop protocol. Can kvm/qemu do anything like that? I can never seem to find any “features” page.
Comment by m — April 27, 2009 @ 1:23 pm
KVM has a built in VNC server and you may run guests “headless”. From there you can VNC into the guest with any VNC client.
The built in VNC server does not have a ton of features, so you may wish to install a more full featured VNC server.
In terms of “Seamless Integration” , this is actually a feature of Windows and the so called rdp (remote desktop protocol). You will have to manually configure it, but it should work (it is not difficult).
This Ubuntu Wiki page will show you how to do it, follow the instructions for “qemu”.
Comment by bodhi.zazen — April 27, 2009 @ 1:57 pm
[...] Bodhi.Zazen: Convert Virtualbox vdi to KVM qcow VA:F [1.1.7_509]please wait…Rating: 0.0/5 (0 votes cast) This article was found on Planet Ubuntu. Click here to visit the full article on the original website. [...]
Pingback by linkfeedr » Blog Archive » Bodhi.Zazen: Convert Virtualbox vdi to KVM qcow - RSS Indexer (beta) — April 27, 2009 @ 2:43 pm
Alright, and where can we get vditool? :/
Comment by Yann — April 28, 2009 @ 4:59 am
vidtool is included in vitrualbox. If needed you may install either the OSE from the Ubuntu repositories or the PUEL edition from the Sun site.
Comment by bodhi.zazen — April 28, 2009 @ 9:16 am
Hello bodhi, could you please double check this, or specify which package contains it, and where it gets installed? I don’t think it is true :/
Comment by Yann — April 28, 2009 @ 9:44 am
hmm … It appears they changed the syntax and I can no longer find vditool for download :(
use VBoxManage clonehd
I updated my tutorial , lol
Comment by bodhi.zazen — April 28, 2009 @ 2:39 pm
Does it work? If I create a vdi disk with the following command line:
VBoxManage createhd -filename ubuntu.vdi -size 200M
And then try to convert it:
VBoxManage clonehd -format RAW ubuntu.vdi ubuntu.img
I get the following error:
Error: failed to clone hard disk. Error message: Could not create the clone hard disk ‘/home/yann/.VirtualBox/HardDisks/ubuntu.img’ (VERR_INVALID_PARAMETER)
(placing myself in /home/yann/.Virtualbox/HardDisks)
Any idea?
Comment by Yann — April 29, 2009 @ 4:20 am
I am able to convert using the PUEL version. In fact, I downloaded to test this for you yesterday (I made a disk, converted it using the commands I updated, and used the disk with KVM).
(Host Ubuntu 9.04 x86_64 ; Virtualbox PUEL 2.2.2)
A google search shows that this error you now have is common with VirtualBox, but it was “fixed in SVN”.
http://www.virtualbox.org/ticket/3012
I suggest you update your version of VirtualBox and if the problem persists filing a bug report with VirtualBox.
#VBoxManage clonehd –format RAW ubuntu.vdi ubuntu.img
VirtualBox Command Line Management Interface Version 2.2.2
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.
0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
Clone hard disk created in format ‘RAW’. UUID: 6d73f00d-5165-4717-ae32-55b1992d7f7e
#ls
ubuntu.img ubuntu.vdi
#qemu-img convert -f raw ubuntu.img -O qcow2 ubuntu.qcow
#ls
ubuntu.img ubuntu.qcow ubuntu.vdi
Comment by bodhi.zazen — April 29, 2009 @ 12:36 pm
And , just for completeness …
I installed Virtualbox ( PUEL 2.2.2 – x86_64 ) on Fedora 10 ->
I then installed Ubuntu 9.04 (guest) with an encrypted / (root)
I then used the commands in this blog to convert the ubuntu.vdi -> ubuntu.img (raw) -> ubuntu.qcow
The resulting ubuntu.qcow booted in KVM with no problems, encryption was preserved.
HTH :twisted:
Comment by bodhi.zazen — April 30, 2009 @ 5:30 pm
Depending on your version of VirtualBox you may have to put the “-format RAW” AFTER the filenames.
VBoxManage clonehd |
[--format VDI|VMDK|VHD|RAW|]
[--variant Standard,Fixed,Split2G,Stream,ESX]
[--type normal|writethrough|immutable]
[--remember]
VBoxManage clonehd “ubuntu.vdi” “ubuntu.img” -format RAW
Hope this help!
Ryan
Comment by Ryan Grieve — June 12, 2009 @ 3:56 am
[...] 基本上是照着这篇文章来做的,只是我按照它的方法,在第一步出了状况,修改了一下,下面是详细步骤: [...]
Pingback by 将virtualbox的vdi镜像文件转换成kvm的qcow静像文件 | Linux|系统管理|WEB开发 — July 9, 2009 @ 6:27 am
How would it be the same process but backwards? Would it work just like that or it would require extra steps?
Comment by Guest — December 9, 2009 @ 9:29 am
In theory, it should work the same in reverse.
In Practice, sometimes my conversions fail, and when they do sometime I can debug and sometimes not.
Comment by bodhi.zazen — December 9, 2009 @ 4:00 pm
Hi I have tested the procedure and it works like a charm!
but… I have a little problem after the conversion…
In this case I converted a Windows XP vbox machine into KVM qcow and then I’m not able to startup the machine because of the common bsod caused by the HAL problem…
anyone knows how to overcome this issue without having to repair the windows installation???
thanks in advance!
Comment by Pablo Alonso — December 13, 2009 @ 5:48 pm
Pablo Alonso: Aye, the “problem” is that when you convert form VMWare to KVM, as far as Windows is concerned, the “hardware” changed.
I do not know of an easy fix :(
Comment by bodhi.zazen — December 15, 2009 @ 5:06 pm
VBoxManage clonehd -format RAW ubuntu.vdi ubuntu.img
I get the following error:
Error: failed to clone hard disk. Error message: Could not create the clone hard disk ‘/home/yann/.VirtualBox/HardDisks/ubuntu.img’ (VERR_INVALID_PARAMETER)
Try:
VBoxManage clonehd –format RAW ubuntu.vdi ubuntu.img
Comment by Anonymous — May 3, 2010 @ 1:50 pm
@Anonymous:
Try two – -
Wordpress renders two – - as a long –
I updated the syntax of the post , hope that helps.
Comment by bodhi.zazen — May 3, 2010 @ 3:32 pm
[...] trick was found at this guy’s blog (thanks!). It took an age and made my laptop cry while it was working, but in the end Sleuthkit saw [...]
Pingback by Converting VirtualBox VDI files to raw disk images | Needs More Pop — June 24, 2010 @ 11:26 am
As far as I’ve read, KVM can read VMDK files (Vmware). Virtualbox exports VMDK either via vboxmanage or via “Export appliance” in the file menu. Export works fine, but I did not try using the VMDK in KVM, yet.
Comment by Conceit — July 20, 2010 @ 4:57 am
I was able to make this conversion in one step with this command:
qemu-img convert -f vdi oldImage.vdi -O qcow2 newImage.qcow
Comment by Jim — August 16, 2010 @ 12:06 pm