Using the Chocolatey Test Environment under QEMU by Converting From VirtualBox VHD to QEMU QCOW2 Disk Format

Using the Chocolatey Test Environment under QEMU by Converting From VirtualBox VHD to QEMU QCOW2 Disk Format
Image courtesy of Michael Mook. License.

In February, a new version of the Chocolatey Test Environment was released. And, like last time when I wanted to use it under VMware Workstation, it got me thinking how I would be able to use it under KVM this time?

In a previous post, I talked about converting the Chocolatey Test Environment Vagrant box from the VirtualBox format to VMware Workstation. For the last 18 months I have been using Linux as my daily driver, and after the increasing number of problems with VMware Workstation, I switched to using KVM with Virtual Machine Manager. To use the Chocolatey Test Environment under KVM, I need to have a disk in the QCOW2 format that QEMU supports.

The Chocolatey Test Environment comes in two Vagrant box flavours: VirtualBox and Hyper-V. To get it working under KVM, I have two options:

  1. Use Vagrant and amend the Vagrantfile in the box to work with libvirt.
  2. Convert the Vagrant VirtualBox virtual machine disk to QCOW2 and create a virtual machine from it.

On the website, Vagrant’s stated goal is (emphasis mine):

Vagrant is the command line utility for managing the lifecycle of virtual machines. Isolate dependencies and their configuration within a single disposable and consistent environment.

Using Vagrant for many years under VirtualBox, VMware Workstation, Hyper-V and finally libvirt, leads me to the conclusion that Vagrant does not work in a repeatable and consistent way. Vagrant is not a tool I can rely on, and as a result, I no longer use it. So, I have no alternative but to use option 2 which, fortunately, is also the easiest one.

Here Be Dragons!

Before we go any further there are a couple of things I need to clear up.

This guide can be used as a template for converting any Vagrant VirtualBox disk or Vagrant box to a QCOW2 disk that can be used with QEMU. As it is based on a very specific box, version 3.3.1 of the chocolatey/test-environment, it uses specific names and filenames. If you convert another Vagrant box, you will need to change those. I would hope that would be obvious, but just because it is to me doesn’t mean it is to anyone else.

This is a quick and dirty way to convert a VirtualBox VMDK disk to a QCOW2 format disk. It works. But that doesn’t mean it’s ideal or good practice. In fact, it’s not good practice. It’s bad practice. Don’t do it. The end disk image will likely be considerably larger than the original.

Before You Start

Ensure you have qemu-img installed. You can do that by:

  1. Linux: Installing it using your package manager. Under Fedora this is dnf install qemu-img.
  2. Windows: Install it using Chocolatey CLI using choco install qemu.
  3. All: Going to the website.

Download VirtualBox Box

Download the latest version of the Chocolatey Test Environment in VirtualBox format by clicking Download on the Vagrant Cloud website. Version 3.3.1, which is the current version at the time of this writing, is 8.43GB in size.

Extract the VirtualBox Disk

Once the Vagrant file has been downloaded, open it in your favourite archive viewer (for example, 7zip, Peazip, Ark). Inside that archive you may, depending on your archive viewer, find another archive inside. This happened when I was using both Ark and Peazip. If you do, extract this too. We are looking for chocolatey-test-environment-disk001.vmdk and once you find that extract it. This is the file we will convert.

Convert the VirtualBox Disk file to QCOW2 Format

Now we have our extracted disk file, we need to convert it from WMDK to QCOW2 format. Use this command:

qemu-img convert -cpf vmdk -O qcow2 chocolatey-test-environment-disk001.vmdk chocolatey_test_environment-3.31.qcow2

Create the Chocolatey Test Environment Virtual Machine

Now you have a QCOW2 format disk, you can create a virtual machine. These are the hardware details specified for this Vagrant box:

  • 2 vCPU’s.
  • 2GB RAM.

As creating this virtual machine is specific to whatever you are using as the virtual machine manager, I am unable to go into specifics. But as you are looking at converting virtual machine disk formats, it’s highly likely you already know what you are doing here.

Summary

As we are not going to use this new disk with Vagrant, the only thing left for us to do is to configure it for the best Windows guest experience.

But if you want to use this with Vagrant under libvirt, follow the steps in the previous blog post to create a new Vagrant box.

Do you know of a better way to convert between disk formats? Let me know in the comments on how you do these types of conversions.