You can reduce the time it takes to create virtual machines (VMs) in
VM Runtime on GDC by manually converting existing virtual disk
images to the [`qcow2`](https://wikipedia.org/wiki/Qcow) format. After you
convert an image, you can create and run VMs directly from it.

VM Runtime on GDC automatically converts non-`qcow2` disk images
during deployment. However, if you create multiple VMs from the same
non-`qcow2` image, VM Runtime on GDC converts the image every time,
which increases the time it takes to create and start each VM. Converting the
image first, as shown in this document, avoids this repeated conversion.

## Before you begin

To create a VM after you convert your existing virtual disk image, you need
access to the following resources:

- Access to Google Distributed Cloud version 1.12.0 (`anthosBareMetalVersion: 1.12.0`) or higher cluster. You can use any cluster type capable of running workloads. If needed, [try Google Distributed Cloud on Compute Engine](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/try/gce-vms.md.txt) or see the [cluster creation overview](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/installing/creating-clusters/create-clusters-overview.md.txt).
- The `virtctl` client tool installed as a plugin for `kubectl`. If needed, [install the virtctl client tool](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/quickstart.md.txt#install_the_virtctl_client_tool).

## Convert a virtual disk image

In this document, you use the
[QEMU disk image utility](https://www.qemu.org/docs/master/tools/qemu-img.html)
to convert existing virtual disk images to the `qcow2` format. The `qemu-img`
tool can convert virtual disk images from multiple formats, such as `vmdk` or
`vhdx`, to the `qcow2` format for use with VM Runtime on GDC.

To convert virtual disk images to the `qcow2` format, complete the following
steps:

1. Install the `qemu-utils` package using your Linux distro's package manager.

   ### Ubuntu

   ```bash
   apt-get install qemu-utils
   ```

   ### RHEL

   ```bash
   yum install qemu-utils
   ```
2. Use `qemu-img` to convert the existing virtual disk image:

   ```bash
   qemu-img convert -f EXISTING_DISK_IMAGE_FORMAT -O qcow2 \
     EXISTING_DISK_IMAGE_NAME \
     CONVERTED_DISK_IMAGE_NAME.qcow2
   ```

   Replace the following values:
   - `EXISTING_DISK_IMAGE_FORMAT`: the format of your existing virtual disk image, such as `vmdk`.
   - `EXISTING_DISK_IMAGE_NAME`: the path and name of your existing virtual disk image.
   - `CONVERTED_DISK_IMAGE_NAME`: the path and name for your converted `qcow2` virtual disk image.

   For more information on the `qemu-img` tool, such as the different image format
   options, see the
   [QEMU disk image utility documentation](https://www.qemu.org/docs/master/tools/qemu-img.html).

## Create a VM with your converted image

If you want to see your converted virtual disk image in action, create a VM and
use the local `qcow2`-formatted image created in the previous section. For
production use, you should upload your converted virtual disk image to a central
repository and then
[create a VM boot disk from HTTP source](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/create-manage-disks.md.txt#from_image)
or
[from Cloud Storage using a Secret](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/create-storage-credentials.md.txt#use_a_secret_to_import_an_image).

To use your local converted virtual disk image, complete the following steps:

1. Create a VM in your cluster:

   ```bash
   kubectl virt create vm VM_NAME \
     --os-type OS_TYPE \
     --image CONVERTED_DISK_IMAGE_NAME.qcow2
   ```

   This command creates a VM with the defaults of 2 CPU, 4 Gi memory.

   Replace the following values:
   - `VM_NAME`: name for your VM
   - `OS_TYPE`: the OS type of your converted virtual disk image. Can be `linux` or `windows`.
   - `CONVERTED_DISK_IMAGE_NAME`: the path and name of your converted `qcow2` virtual disk image from the previous section.
2. It can take 10-20 minutes to create the VM from your locally converted
   virtual disk image, depending on the size of your image. Check the status of
   the VM with the `kubectl` command:

   ```bash
   kubectl get gvm VM_NAME
   ```

   Replace `VM_NAME` with the name of your VM.

   The following example output shows the VM in a `Running` state when the
   process is complete:

   ```bash
   NAME    STATUS    AGE   IP
   MY_VM   Running   64s   192.168.2.124
   ```

## What's next

You can upload your converted virtual disk image in `qcow2` format to an HTTP
source or Cloud Storage. The following documents show you how to then create a
VM from those sources:

- [Create a VM boot disk from HTTP source](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/create-manage-disks.md.txt#from_image)
- [Create a VM boot disk from Cloud Storage using a Secret](https://docs.cloud.google.com/kubernetes-engine/distributed-cloud/bare-metal/docs/vm-runtime/create-storage-credentials.md.txt#use_a_secret_to_import_an_image)