DEV Community

Cover image for From OVA to Qcow2: A Step-by-Step Guide to Unlocking Qemu's Power
Zoo Codes
Zoo Codes

Posted on

From OVA to Qcow2: A Step-by-Step Guide to Unlocking Qemu's Power

Background

I was recently studying for and completed the CISCO CyberOps Associate certification. One of the labs required me to use a security VM in OVA format. I wanted to convert the OVA file to Qcow2 format to use it with Qemu, a popular open-source emulator and virtualizer. This wasn't necessary, I could have just used VirtualBox or VMware, but I wanted to explore the process of converting the file format and learn more about Qcow2.

cisco-badge

Introduction

Virtual machines (VMs) have become an essential part of modern computing, allowing users to run multiple operating systems on a single physical machine. When working with VMs, it's not uncommon to encounter different file formats, each with its own set of features and compatibility issues. In this article, we'll explore the process of converting a VM in OVA format to Qcow2, a format compatible with Qemu.

What is OVA?

OVA (Open Virtualization Archive) is an open standard for packaging and distributing virtual machines. It's a single file that contains the VM's configuration, disk images, and other metadata. OVA files are widely supported by various virtualization platforms, including VMware, VirtualBox, and KVM.

What is Qcow2?

Qcow2 is a disk image format used by Qemu, a popular open-source emulator and virtualizer. Qcow2 is a more efficient and flexible format compared to traditional raw disk images, offering features like compression, encryption, and snapshotting.

Why Convert OVA to Qcow2?

There are several reasons why you might want to convert an OVA file to Qcow2:

  1. Qemu compatibility: If you're using Qemu as your virtualization platform, you'll need to convert the OVA file to Qcow2 to ensure compatibility.
  2. Performance optimization: Qcow2 offers better performance and compression compared to OVA, making it a more efficient choice for resource-intensive workloads.
  3. Security: Qcow2 supports encryption and other security features, making it a more secure choice for sensitive workloads.

Converting OVA to Qcow2

Converting an OVA file to Qcow2 is a relatively straightforward process. You'll need to have the following tools installed:

  • OVA file: The VM in OVA format that you want to convert.
  • Qemu: The Qemu emulator and virtualizer.
  • qemu-img: A command-line tool for manipulating disk images.

Here are the steps to convert an OVA file to Qcow2:

  1. Extract the OVA file: Use a tool like tar or 7zip to extract the contents of the OVA file. This will typically include a vmx file (VM configuration), a vmdk file (disk image), and other metadata. In my case I used 7zip to extract the OVA file in a relevant folder. The syntax is as follows:
7z x cyberops_workstation.ova -ocyberops_workstation
Enter fullscreen mode Exit fullscreen mode

screenshot

2.Identify the disk image: Locate the disk image file (usually a vmdk file).

3.Convert the VMDK file to Qcow2: Use the qemu-img command to convert the vmdk file to Qcow2. The syntax is as follows:

qemu-img convert -f vmdk -O qcow2 input.vmdk output.qcow2
Enter fullscreen mode Exit fullscreen mode

NB: Note this may take some time depending on the size of the disk image. Also the siize of the image may increase or decrease depending on the conversion process. In my case the image size increased from 3.8GB to 8.3GB.

after-conversion

4.Create a new Qemu VM: Create a new Qemu VM using the qemu-system-x86_64 command (or similar, depending on your architecture). Specify the Qcow2 file as the disk image:

qemu-system-x86_64 -m 2048 -vnc :1 -hda output.qcow2
Enter fullscreen mode Exit fullscreen mode

This will start the Qemu VM with 2048MB of RAM, VNC enabled on port 5900, and the Qcow2 file as the disk image. Replace 2048 with the desired amount of RAM, and :0 with the desired VNC port.

When you run this command, QEMU will:

  1. Allocate 2 GB of memory to the virtual machine.
  2. Start a VNC server listening on port 5901.
  3. Use the output.qcow2 image file as the primary hard disk.
  4. You can then connect to the virtual machine's graphical console using a VNC client, such as vinagre or tightvnc, by connecting to localhost:5901 or 127.0.0.1:5901.

Optionally, use Virt-Manager to create a new VM and use the Qcow2 file as the disk image.

virt-manager

virt-2

Conclusion

Converting a VM from OVA to Qcow2 is a relatively simple process that can be accomplished using the qemu-img command. By following these steps, you can take advantage of Qemu's features and performance optimizations, while ensuring compatibility with your virtualization platform. Remember to always exercise caution when working with virtual machines, especially when dealing with sensitive workloads.

I hope you have enjoyed this article. If you have any questions, please feel free to reach out to me on Twitter. or LinkedIn. You can also check out my other articles on Dev.to. Thanks for reading!

Support me by buying me a coffee

next-time

Top comments (1)

Collapse
 
hartley94 profile image
Martin Thuo

Great article, had to try out QEMU.
Cheers ! 💪✌