Sunday 13 April 2014

Convert Virtualbox VM to KVM



To Convert a Virtualbox VM to KVM there is a simple process to follow. It makes use of the Virtualbox tool 'VBoxManage'. If the VM image size is large the conversion can take some time (depending on your machine) e.g. 30 minutes for  a 40GB file. If you also have a low powered machine you may not be able to run other tasks while the conversion is occurring.

Convert Virtual Disk Image to RAW image format

  • Convert the Virtualbox vdi (Virtual Disk Image) file to a raw image
  • Format
$ sudo VBoxManage clonehd --format RAW /<Path to Virtualbox VM>/<Virtualbox VM>.vdi /<Path to KVM VM>/<KVM VM>.img 
  • Example
$ sudo VBoxManage clonehd --format RAW ~/VirtualBox\ VMs/Vista/Vista.vdi ~/KVMImages/Vista.img 
  • I also find it useful in a second terminal to have 'watch running on ls to see the file size increasing
$ sudo watch ls -lh

Convert RAW image format to QCOW2

  • RAW images are simple to work with but can take up a lot of space
  • QCOW2 (QEMU Copy on Write) advantages over RAW file format
    • Files with this format can grow as data is added i.e. smaller images
    • Allows changes made to a read-only base image to be stored on a separate qcow file by using copy on write
    • Snapshot support
    • Optional zlib compression
    • Optional AES encryption
  •  Format
$ sudo qemu-img convert -f raw  /<Path to KVM VM>/<KVM VM>.img -O qcow2  /<Path to KVM VM>/<KVM VM>.qcow 
  • Example
$ sudo qemu-img convert -f raw Vista.img -O qcow2 Vista.qcow


Using Virtual Machine Manager to import image

  •  Open 'Virtual Machine Manager'
  •  Right Click on 'localhost (QEMU) and select 'New' 

  • Select 'Import existing file disk image' as highlighted above
  • Select image at location file was converted
  • Define remaining options as required and start the VM from KVM
  • When the VM is OK you can delete the RAW format file 

No comments:

Post a Comment